Go\Core\Container::share PHP Method

share() public method

Set a shared value in the container
public share ( string $id, callable $value, array $tags = [] )
$id string Identifier
$value callable Value to store
$tags array Additional tags
    public function share($id, $value, array $tags = [])
    {
        if (!is_callable($value)) {
            throw new \InvalidArgumentException("Only callable values can be shared in the container");
        }
        $value = function ($container) use($value) {
            static $sharedValue;
            if (null === $sharedValue) {
                $sharedValue = $value($container);
            }
            return $sharedValue;
        };
        $this->set($id, $value, $tags);
    }