-
Notifications
You must be signed in to change notification settings - Fork 2
Manager class
Common parameters are described in Function parameters.
void __construct ( [ mixed $bootMode
], [bool $namespacing
] )
// Pimple implements ArrayAccess
// Statical will discover this and use offsetGet
$container = new Pimple(...);
$manager = new StaticalManager($container);
// Aura Di resolves through the get function
// Statical will discover and use this
$container = new Aura\Di\Container(...);
$manager = new StaticalManager($container);
// This container uses magic __get calls
// We need to tell Statical the method to use
$di = new CustomContainer(...);
$container = array($di, '__get');
$manager = new StaticalManager($container);
void addNamespace ( string $alias
, mixed $namespace
)
Adds a namespace to an alias.
-
$alias - either an alias param or an asterisk
*
which signifies any registered alias. - $namespace - namespace param
$manager = new StaticalManager();
...
$manager->addNamespace('Foo', 'App');
// Foo can be called in global and App namespace
$manager->addNamespace('Foo', 'App\\*');
// Foo can be called in global and App... namespace
$manager->addNamespace('Foo', '*');
// Foo can be called in any namespace
$manager->addNamespace('*', '*');
// Any registered alias can be called in any namespace
void addProxyInstance ( string $alias
, string $proxy
, object $target
, [ mixed $namespace
] )
Adds an instance or closure as a proxy target.
- $alias - an alias param
- $proxy - the fully-qualified class name of the static proxy.
- $target - either a class instance or a closure.
- $namespace - optional namespace param
void addProxySelf ([ mixed $namespace
] )
Registers ourself as a proxy using the alias Statical
.
- $namespace - optional namespace param
$manager = new StaticalManager();
$manager->addProxySelf();
// We can now use the manager via the alias Statical or \Statical
$manager->addProxySelf('*');
// We can now call Statical in any namespace
void addProxyService ( string $alias
, string $proxy
, mixed $container
, [ string $id
], [ mixed $namespace
] )
Adds a service as a proxy target.
- $alias - an alias param
- $proxy - the fully-qualified class name of the static proxy.
- $container - container param.
- $id - optional id or key-name used in the container. If missing will used lower-cased alias
- $namespace - optional namespace param
void disable ()
void enable ()
void makeSingleton ( )
Enforces a singleton pattern on the class. Any subsequent attempts to instantiate it will result in a RuntimeException
.
If another instance of Statical is created it will destroy the functionality of the first. This is not a consideration if you have total control of your code, but in the case of a framework, for example, you can lock things down with this method.
This section describes common function parameters. If they do not conform an InvalidArgumentException
will be thrown.
string The name of the class to call. It must not include a namespace (or any backslash characters)
mixed Either a class instance or a callable, ie an array containing an instance and method name.
mixed Either a string or an array of strings. Each string value must define one of three namespace groups:
- any - an alias can be used in any namespace, denoted by an asterisk
*
- name - an alias can be used in a specific namespace defined by the value, denoted
Name\\Space
- path - an alias can be used in any namespace starting with the value, denoted
Name\\Space\\*
Note that there must not be a backslash at either the beginning or end of the value. [contents]: #Contents