Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
API Reference
The full public surface of every type shipped by initphp/auth.
Behavioural deep-dives are linked into the Core Types
and Adapters sections.
Signatures below show the PHP 8 form for readability. The library is type-safe under PHPStan level 8.
namespaceInitPHP\Auth;
interface AdapterInterface
{
publicfunctionget(string$key, mixed$default = null): mixed;
publicfunctionset(string$key, mixed$value): self;
publicfunctioncollective(array$data): self;
publicfunctionhas(string$key): bool;
publicfunctionremove(string ...$keys): self;
publicfunctiondestroy(): bool;
}Depend on this interface in your service signatures. See Adapter Interface for per-method semantics.
namespaceInitPHP\Auth;
abstractclass AbstractAdapter implements AdapterInterface
{
publicfunctioncollective(array$data): AdapterInterface;
}The default collective() iterates set(). Override for atomic
backing stores. See Adapter Interface →
AbstractAdapter.
The facade that wraps a single adapter and forwards the
AdapterInterface contract methods.
namespaceInitPHP\Auth;
class Segment implements AdapterInterface
{
publicconstADAPTER_SESSION = 0;
publicconstADAPTER_COOKIE = 1;
publicfunction__construct(string$name, int|string$adapter = self::ADAPTER_SESSION, array$options = []);
// Factoriespublicstaticfunctioncreate(string$name, int|string$adapter = self::ADAPTER_SESSION, array$options = []): self;
publicstaticfunctionsession(string$name, array$options = []): self;
publicstaticfunctioncookie(string$name, array$options = []): self;
publicstaticfunctioncustom(string$name, string$adapterClass, array$options = []): self;
// Escape hatchpublicfunctionadapter(): AdapterInterface;
// AdapterInterface proxiespublicfunctionget(string$key, mixed$default = null): mixed;
publicfunctionset(string$key, mixed$value): AdapterInterface;
publicfunctioncollective(array$data): AdapterInterface;
publicfunctionhas(string$key): bool;
publicfunctionremove(string ...$keys): AdapterInterface;
publicfunctiondestroy(): bool;
// Magic delegation for non-interface adapter methodspublicfunction__call(string$name, array$arguments): mixed;
}See Segment for the factory comparison, BC notes, and adapter resolution rules.
namespaceInitPHP\Auth;
class SessionAdapter extends AbstractAdapter
{
publicfunction__construct(string$name, array$options = []);
}Throws \RuntimeException if session_status() !== PHP_SESSION_ACTIVE
at construction time, or on any read/write after destroy().
See Session Adapter for the full lifecycle and the
options forwarded to the internal ParameterBag.
namespaceInitPHP\Auth;
class CookieAdapter extends AbstractAdapter
{
publicconstMIN_SALT_LENGTH = 32;
publicfunction__construct(
string$name,
array$options = [],
?\InitPHP\Auth\Cookie\CookieWriterInterface$writer = null,
);
}Overrides collective() so a bulk write emits one Set-Cookie header
instead of N.
Throws \InvalidArgumentException for:
- missing / non-string / short
salt; samesite='None' + secure=false.
Throws \RuntimeException on any read/write after destroy(), and on
JSON encoding failure inside set() / collective().
See Cookie Adapter for the wire format and the options matrix.
namespaceInitPHP\Auth;
finalclass NullAdapter extends AbstractAdapter
{
publicfunction__construct(string$name = '', array$options = []);
}Every operation is a no-op (or returns the default value / false /
true as appropriate). See Null Adapter.
namespaceInitPHP\Auth\Cookie;
interface CookieWriterInterface
{
publicfunctionsend(string$name, string$value, array$options): bool;
}
finalclass NativeCookieWriter implements CookieWriterInterface
{
publicfunctionsend(string$name, string$value, array$options): bool;
}
finalclass InMemoryCookieWriter implements CookieWriterInterface
{
publicfunctionsend(string$name, string$value, array$options): bool;
publicfunctioncalls(): array;
publicfunctionlastCall(): ?array;
publicfunctionreset(): void;
publicfunctionreturnValue(bool$value): void;
}See Cookie Writer for the full discussion.
namespaceInitPHP\Auth;
class Permission
{
publicfunction__construct(array$permissions = []);
publicfunctionis(string ...$names): bool;
publicfunctionpush(string ...$names): int;
publicfunctionremove(string ...$names): int;
publicfunctiongetPermissions(): array;
publicfunctiongetPermission(): array; // @deprecated since 2.0// Magicpublicfunction__call(string$name, array$arguments): bool;
publicfunction__isset(string$name): bool;
publicfunction__unset(string$name): void;
publicfunction__sleep(): array;
}__call() raises \BadMethodCallException for names that do not start
with is_. See Permissions for the magic accessor
table and the normalization rules.
| Exception class | Raised by |
|---|---|
\InvalidArgumentException | Segment::__construct/create/custom, CookieAdapter::__construct |
\RuntimeException | SessionAdapter::__construct (inactive session), any adapter read/write after destroy(), CookieAdapter::set/collective on JSON encoding failure |
\BadMethodCallException | Permission::__call for non-is_* names |
\Error | Segment::__call when the underlying adapter does not expose the method |
See Exceptions for the per-failure-mode table.
initphp/auth · MIT License · part of the InitPHP family
Source · Issues · Discussions · Packagist · Contributing · Security Policy
Getting Started
Core Types
Adapters
Reference
Recipes
Migration & Help