public function register($name, callable $factory)
    {
        $this->factories[$name] = $this->share($factory);
        unset($this->values[$name]);
    }
public function register($name, callable $factory)
    {
        $this->factories[$name] = $this->share($factory);
        unset($this->values[$name]);
    }
public function register ( $ name , callable $ factory ) { $ this -> factories [ $ name ] = $ this -> share ( $ factory ) ; unset ( $ this -> values [ $ name ] ) ; }
Register a resource factory.

Upon access the factory is called at most once to produce a value
which is then stored and returned each time the value is accessed.
The factory will receive the container's instance as its only
argument.

Example usage:

$container->register('alice', function ($container) {
return isset($container['bob']);
});
$alice = $container['alice']; // false
$container['bob'] = 'bob';
$alice = $container['alice']; // still false as the value is already calculated.

It is recommended that you divide your code into two stages:
initialization and utilization. On initialization stage you assign
values and register resource factories, allowing them to access
container from inside a function, but you never retrieve values from
the container. On utilization stage you assume all initialization is
over, and you access values and resources to perform your tasks.

@param  string      $name
@param  mixed(self) $factory
Register a resource factory .