Skip to content
johnstevenson edited this page Nov 14, 2014 · 13 revisions

Contents

Overview

Function reference

Common parameters are described in Function parameters.

__construct

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);

addNamespace

void addNamespace ( string $alias, mixed $namespace )

Adds a namespace to an alias.

$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

addProxyInstance

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

addProxySelf

void addProxySelf ([ mixed $namespace ] )

Registers ourself as a proxy using the alias Statical.

$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

addProxyService

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

disable

void disable ()

enable

void enable ()

makeSingleton

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.

Function parameters

This section describes common function parameters. If they do not conform an InvalidArgumentException will be thrown.

Alias param

string The name of the class to call. It must not include a namespace (or any backslash characters)

Container param

mixed Either a class instance or a callable, ie an array containing an instance and method name.

Namespace param

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