Creates the instance callback which is passed to the wrappers if they exist.

@param string $name
@param mixed $spec
@return \Closure
343516
protected function createInstanceCallback($name, $spec)
    {
        if (is_string($spec) && class_exists($spec)) {
            $spec = new $spec();
        }

        $callback = function () use ($name, $spec) {
            if ($spec instanceof \Closure) {
                return $spec($this);
            } elseif ($spec instanceof ServiceFactory) {
                return $spec->createService($this);
            } elseif (is_object($spec)) {
                return $spec;
            } elseif (is_array($spec)) {
                return $this->createFromArray($name, $spec);
            } elseif (is_null($spec)) {
                throw new Exception\NullServiceException($name);
            }

            throw new Exception\InvalidServiceException($name);
        };

        return $callback;
    }
423741
protected function buildBasic($name, Closure $callback = null): void
    {
        if ($name instanceof Closure) {
            $callback = $name;
            $name = null;
        }

        ! empty($name) && $this->legend($name);

        $callback($this);
    }
1015834
public function make(string $name, array $data = [], \Closure $callback = null)
    {
        $this->setWidgetName($name);
        $this->data = $data;
        /*
         | If second param given as closure then we will
         | return callback
         */
        if (!is_null($callback) && $callback instanceof \Closure) {
            return $callback($this);
        }

        /*
         | return object
         */
        return $this->render();
    }
1183576
protected function callMacro($name, $parameters)
    {
        $macro = static::$macros[$name];

        if ($macro instanceof Closure) {
            return call_user_func_array($macro->bindTo($this, static::class), $parameters);
        }

        return call_user_func_array($macro, $parameters);
    }
941552
public function alias($name, $spec)
    {
        if (is_callable($spec)) {
            $this->instances[$name] = $spec;
        } else {
            $this->aliases[$name] = $spec;

            // Ensure that the new alias will be used when called.
            unset($this->instances[$name]);
        }
    }
849658
public function make($name, array $params = array(), $force = false)
    {
        if (isset($this->_ioc[$name])) {

            // If a singleton instance exists, return it
            if ($this->_ioc[$name]['instance'] && !$force)
                return $this->_ioc[$name]['instance'];

            // Include an instance of this object as the final argument
            $params[] = $this;

            // Call the stored container
            $result = call_user_func_array($this->_ioc[$name]['closure'], $params);

            // If this is supposed to be a singleton, store it
            if ($this->_ioc[$name]['singleton'])
                $this->_ioc[$name]['instance'] = $result;

            return $result;
        }

        return null;
    }
952415
public function create($name, Closure $resolver)
    {
        $builder = new MenuBuilder($name, $this->config);

        $builder->setViewFactory($this->views);

        $this->menus[$name] = $builder;

        return $resolver($builder);
    }
568776
protected static function createFreshMockInstance($name)
	{
		static::$resolvedInstance[$name] = $mock = static::createMockByName($name);

		if (isset(static::$app))
		{
			static::$app->instance($name, $mock);
		}

		return $mock;
	}
621817
public function createDelayed($name, \Closure $startCallback)
    {
        $childJob = $this->jobProcessor->findOrCreateChildJob($name, $this->rootJob);

        $this->jobExtension->onPreCreateDelayed($childJob);

        $jobRunner = $this->getJobRunnerForChildJob($this->rootJob);
        $createResult = call_user_func($startCallback, $jobRunner, $childJob);

        $this->jobExtension->onPostCreateDelayed($childJob, $createResult);

        return $createResult;
    }
449170
protected function buildClass($name)
    {

        $stub = parent::buildClass($name);

        $this->replaceEndpoint($stub, $this->argument('endpoint'));

        if (! is_null($this->option('esi-version')))
            $this->replaceVersion($stub, $this->option('esi-version'));

        if (! is_null($this->option('scope')))
            $this->replaceScope($stub, $this->option('scope'));

        return $stub;
    }
1216230
protected function add($smOrCallback, $event, $callable = null, array $specs = array())
    {
        if ($smOrCallback instanceof Callback) {
            $this->dispatcher->addListener($event, $smOrCallback);

            return $this;
        }

        trigger_error(
            'Use of CallbackHandler::add without a Callback instance is deprecated and will be removed in 2.0',
            E_USER_DEPRECATED
        );

        $specs = $this->specResolver->resolve($specs);
        $callback = CallbackBuilder::create($smOrCallback, $specs['from'], $specs['to'], $specs['on'], $callable)->getCallback();

        $this->dispatcher->addListener($event, $callback);

        return $this;
    }
632225
protected static function createFreshMockInstance($name)
    {
        static::$instance[$name] = $mock = static::createMockByName($name);

        if (isset(static::$container)) {
            static::$container->instance($name, $mock);
        }

        return $mock;
    }
1289985
public function resolveCallableFromCache(string $name, callable $closure)
    {
        if($this->cache->has(self::CACHE_CALLABLE . $name)) {
            return $this->cache->get(self::CACHE_CALLABLE . $name);
        }

        $resolved = $this->resolveCallable($name, $closure);

        //cache closure
        $this->store(self::CACHE_CALLABLE . $name, $resolved);

        return $resolved;
    }
1179141
public static function define($name, $define)
    {
        $instance = self::getInstance();
        $parent = false;
        $base   = false;
        $trait  = false;
        if (is_array($name)) {
            $parent = array_key_exists('parent', $name)?$name['parent']:false;
            $base   = array_key_exists('class', $name)?$name['class']:false;
            if (array_key_exists('trait', $name)) {
                $name = $name['trait'];
                $parent = $base = false;
                $trait = true;
            } else {
                $name = $name[0];
            }
        }
        if (empty($name)) {
            throw new \InvalidArgumentException("name is empty");
        }
        if ($parent && !$instance->registry->is_registered($parent)) {
            throw new \InvalidArgumentException("parent `{$parent}` is not registered");
        }
        if ($base && in_array($instance->config->adaptor->getModel($base), [false, null])) {
            throw new \InvalidArgumentException("class `{$base}` is not found");
        }
        $definition = new FabricateDefinition($define);
        if ($trait) {
            $instance->traits[$name] = $definition;
            return;
        }
        if (!$parent && !$base) {
            $base = $name;
        }
        $definition->parent = $parent?FabricateFactory::create($instance->registry->find($parent)):false;
        $definition->parent = $base?FabricateFactory::create($instance->config->adaptor->getModel($base)):$definition->parent;
        $definition->parent->setConfig(self::getInstance()->config);

        $instance->registry->register($name, $definition);
    }
538554
protected function prepareService(string $name, $service, ReflectionClass $class, array $config)
    {
        $this->storeService($name, $config, $service);

        foreach ($config['calls'] as $call) {
            if (!is_array($call)) {
                continue;
            }

            if (!isset($call['method'])) {
                throw new Exception\InvalidConfiguration('method is required for setter injection in service '.$name);
            }

            $arguments = [];

            try {
                $method = $class->getMethod($call['method']);
            } catch (\ReflectionException $e) {
                throw new Exception\InvalidConfiguration('method '.$call['method'].' is not callable in class '.$class->getName().' for service '.$name);
            }

            $arguments = $this->autoWireMethod($name, $method, $call);
            $result = call_user_func_array([&$service, $call['method']], $arguments);

            if (isset($call['select']) && true === $call['select']) {
                $service = $result;
            }
        }

        $this->storeService($name, $config, $service);

        return $service;
    }
311476
public function a_class( $name, $content, $extends = null, $implements = null )
	{
		return $this->add( $this->closure( "class ".$name.
			( $extends ? ' extends '.$extends : '' ).
			( $implements ? ' implements '.$implements : '' ), $content ) );
	}
1012558
public function create($name, $callback)
    {
        $this->_name = $name;
        $this->_class = $callback();

        $GLOBALS['providers'][$this->_name] = $this->_class;
    }