Create the object via the custom callable

@param string $abstract (optional) class or interface name
@param array  $parameters (optional)

@return object

@throws ReflectionException
540523
protected function createObject($abstract=null, array $parameters=[])
    {

        $abstract = $this->factoryAbstract($abstract);

        if (!$this->_customFactory) {
            return $this->createWithoutFactory($abstract, $parameters);
        }

        return Lambda::callFast($this->_customFactory, [$abstract, $parameters]);
    }
366883
public function generate(array $parameters = array(), array $options = array())
    {
        $parametersResolver = new OptionsResolver();
        $this->setDefaultParameters($parametersResolver);

        $parameters = $parametersResolver->resolve($parameters);

        $optionsResolver = new OptionsResolver();
        $this->setDefaultOptions($optionsResolver);

        $options = $optionsResolver->resolve($options);

        return $this->doGenerate($parameters, $options);
    }
798951
public function build($concrete, $parameters = array())
	{
		// If the concrete type is actually a Closure, we will just execute it and
		// hand back the results of the functions, which allows functions to be
		// used as resolvers for more fine-tuned resolution of these objects.
		if ($concrete instanceof Closure)
		{
			return $concrete($this, $parameters);
		}

		$reflector = new ReflectionClass($concrete);

		// If the type is not instantiable, the developer is attempting to resolve
		// an abstract type such as an Interface of Abstract Class and there is
		// no binding registered for the abstractions so we need to bail out.
		if ( ! $reflector->isInstantiable())
		{
			$message = "Target [$concrete] is not instantiable.";

			throw new BindingResolutionException($message);
		}

		$constructor = $reflector->getConstructor();

		// If there are no constructors, that means there are no dependencies then
		// we can just resolve the instances of the objects right away, without
		// resolving any other types or dependencies out of these containers.
		if (is_null($constructor))
		{
			return new $concrete;
		}

		$classes = $constructor->getParameters();

		// Once we have all the constructor's parameters we can create each of the
		// dependency instances and then use the reflection instances to make a
		// new instance of this class, injecting the created dependencies in.
		$deps = array_merge($parameters, $this->getDependencies(
			array_diff_key($classes, $parameters)
		));

		return $reflector->newInstanceArgs($deps);
	}
1054717
public function make($abstract, $parameters = [])
    {
        if ($alias = $this->getAlias($abstract)) {
            $abstract = $alias;
        }

        if (isset($this->instances[$abstract])) {
            return $this->instances[$abstract];
        }

        if (!isset($this->binds[$abstract])) {
            throw new \InvalidArgumentException(Lang::get('_CONTAINER_MAKE_PARAMS_ERROR_', $abstract));
        }

        if ($this->binds[$abstract]['concrete'] instanceof \Closure) {
            array_unshift($parameters, $this);
            $instance = call_user_func_array($this->binds[$abstract]['concrete'], (array)$parameters);
        } else {
            $concrete = $this->binds[$abstract]['concrete'];
            $instance = new $concrete($parameters);
        }
        $this->binds[$abstract]['singleton'] && $this->instances[$abstract] = $instance;

        return $instance;
    }
188909
protected function construct(string $abstract) : Closure
    {
        $inspector = new ReflectionClass($abstract);

        if (($constructor = $inspector->getConstructor()) && ($dependencies = $constructor->getParameters())) {

            // if, and only if, a class has a constructor with parameters, we try to solve then
            // creating a resolving callback that in every call will recalculate all dependencies
            // for the given class, and offcourse, using a cached resolving callback if exists.

            return function (string $abstract, array $parameters) use ($inspector, $dependencies) {
                return $inspector->newInstanceArgs(
                    $this->process($abstract, $parameters, $dependencies)
                );
            };
        }

        return function (string $abstract) {
            return new $abstract;
        };
    }
1325929
private function buildService($abstract, $version = '')
    {
        $resolved = null;

        if (is_string($abstract)) {
            // If it's a string, throw it at the IoC container
            $resolved = $this->app->make($abstract, array($version));
        } elseif (is_callable($abstract)) {
            // If it's a callable, lets call it with the application and $this
            $resolved = $abstract($version, $this->app, $this);
        }

        return $resolved;
    }
1239889
public function make($abstract, $parameters = array())
        {
            $abstract = $this->getAlias($abstract);

            // If an instance of the type is currently being managed as a singleton we'll
            // just return an existing instance instead of instantiating new instances
            // so the developer can keep using the same objects instance every time.
            if (Arrays::exists($abstract, $this->instances)) {
                return $this->instances[$abstract];
            }
            $concrete = $this->getConcrete($abstract);

            // We're ready to instantiate an instance of the concrete type registered for
            // the binding. This will instantiate the types, as well as resolve any of
            // its "nested" dependencies recursively until all have gotten resolved.
            if ($this->isBuildable($concrete, $abstract)) {
                $object = $this->build($concrete, $parameters);
            } else {
                $object = $this->make($concrete);
            }

            // If the requested type is registered as a singleton we'll want to cache off
            // the instances in "memory" so we can return it later without creating an
            // entirely new instance of an object on each subsequent request for it.
            if ($this->isShared($abstract)) {
                $this->instances[$abstract] = $object;
            }

            return $object;
        }
986509
public function findOrCreate($criteria, $parameters = null)
    {
        if ($criteria instanceof Bag) {
            $criteria = $criteria->toArray();
        }

        if ($parameters === null) {
            $parameters = $criteria;
        }

        $parameters = $this->castParameters($parameters);
        $entity = $this->getRepository()->findOneBy($criteria);

        if ($entity == null) {
            return $this->create($parameters);
        }

        $result = new Result();
        $result->getResources()->push($entity);

        return $result;
    }
1102634
public static function createInstanceToSave(array $parameters): ImportPropertyModel
    {
        try {
            $model = new ImportPropertyModel();

            $model
                ->setUserId($parameters[ImportPropertyRepository::FIELD_USER_ID])
                ->setAction($parameters[ImportPropertyRepository::FIELD_ACTION])
                ->setType($parameters[ImportPropertyRepository::FIELD_TYPE])
            ;

            if ('all' !== $model->getType()) {
                $model
                    ->setInStockDaysAgo($parameters[ImportPropertyRepository::FIELD_IN_STOCK_DAYS_AGO])
                    ->setFilters($parameters[ImportPropertyRepository::FIELD_FILTERS])
                ;
            }

            return $model;

        } catch (\Exception $e) {
            throw $e;
        }
    }
288921
public function createUrl(array $parameters = array())
    {
        $final_parameters = $this->getFinalParameters();
        $path = $this->getBaseURL();

        // Override default parameters
        $final_parameters = array_merge($final_parameters, $parameters);

        return $path . "?" . http_build_query($final_parameters, null, '&') . $this->buildFragment();
    }
1304657
public function parameters(array $parameters)
    {
        foreach ($parameters as $parameter => $value) {
            if (property_exists($this->parameters, $parameter)) {
                $this->parameters->{$parameter} = $value;
            }
        }

        return $this;
    }
750980
public function create(array $parameters = [])
    {
        if (isset($parameters['cache']) && $parameters['cache'] instanceof Cache) {
            $cache = $parameters['cache'];
        } else {
            $cache = new ApcCache();
        }

        $annotationReaderFactory = new AnnotationReaderFactory();
        $annotationReader = $annotationReaderFactory->create($parameters);

        return new ReflectionService($cache, $annotationReader);

    }
251819
protected function build($concrete, array $arguments = [])
    {
        if (is_callable($concrete)) {
            return $concrete($this, $arguments);
        }

        if (isset($this->reflectionClass[$concrete])) {
            $reflection = $this->reflectionClass[$concrete];
        } else {
            try {
                $reflection = $this->reflectionClass[$concrete] = new ReflectionClass($concrete);
            } catch (\ReflectionException $e) {
                throw new BindingException('ReflectionException: ' . $e->getMessage());
            }
        }

        if (!$reflection->isInstantiable()) {
            throw new BindingException("The '${concrete}' type is not instantiable");
        }

        if (isset($this->reflectionMethod[$concrete])) {
            $constructor = $this->reflectionMethod[$concrete];
        } else {
            $constructor = $this->reflectionMethod[$concrete] = $reflection->getConstructor();
        }

        if (is_null($constructor)) {
            return new $concrete();
        }

        // Resolve arguments
        $parameters = array_diff_key($constructor->getParameters(), $arguments);

        /**
         * @var int $key
         * @var  \ReflectionParameter $parameter
         */
        foreach ($parameters as $key => $parameter) {
            if (null === $class = $parameter->getClass()) {
                if ($parameter->isDefaultValueAvailable()) {
                    $arguments[$key] = $parameter->getDefaultValue();
                } else {
                    throw new BindingException("Could not resolve [$parameter]");
                }
                continue;
            }

            try {
                $class = $class->name;
                $arguments[$key] = isset($this->bindings[$class]) ? $this->make($class) : $this->build($class);
            } catch (BindingException $e) {
                if (!$parameter->isOptional()) {
                    throw $e;
                }
                $arguments[$key] = $parameter->getDefaultValue();
            }
        }

        ksort($arguments);

        return $reflection->newInstanceArgs($arguments);
    }
730373
public static function buildClass( $class, array $parameters = [] )
	{
		if ( !is_string( $class ) )
			throw new BindingException( "Class must be a string" );

		if ( static::building( $class ) )
			throw new BindingException( "The class [" . $class . "] is already being built." );

		static::$buildStack[] = $class;

		try
		{
			$reflector = new \ReflectionClass( $class );

			// If the type is not instantiable, the developer is attempting to resolve
			// an abstract type such as an Interface of Abstract Class and there is
			// no binding registered for the abstractions so we need to bail out.
			if ( !$reflector->isInstantiable() )
				throw new BindingException( "Target [$class] is not instantiable." );

			$constructor = $reflector->getConstructor();

			// If there are no constructors, that means there are no dependencies then
			// we can just resolve the instances of the objects right away.
			if ( is_null( $constructor ) )
				return new $class;

			$dependencies = $constructor->getParameters();

			// Once we have all the constructor's parameters we can create each of the
			// dependency instances and then use the reflection instances to make a
			// new instance of this class, injecting the created dependencies in.
			$parameters = static::keyParametersByArgument( $dependencies, $parameters );

			$instances = static::getDependencies( $dependencies, $parameters, $class );

			array_pop( static::$buildStack );

			/**/

			return $reflector->newInstanceArgs( $instances );
		}
		catch ( \ReflectionException $e )
		{
			array_pop( static::$buildStack );

			throw new BindingException( "Failed to build [$class]: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() );
		}
	}
942013
protected function _buildInstance($instance, array $parameters = [])
  {
    if(is_scalar($instance) && class_exists($instance))
    {
      return Objects::create($instance, $parameters);
    }
    return $instance;
  }
1115026
public function make($abstract, array $parameters = array())
    {
        $abstract = $this->getAlias($this->normalize($abstract));
        //反复make同一抽象时， 返回同一个对象
        if (isset($this->instances[$abstract]) && !is_null($this->instances[$abstract])) {
            return $this->instances[$abstract];
        }
        //获取抽象类对应的具体对象
        $concrete = $this->getConcrete($abstract);
        //当前具体类型是可以build时，
        if ($this->isBuildable($concrete, $abstract)) {
            $object = $this->build($concrete, $parameters);
        } else {
            $object = $this->make($concrete, $parameters);
        }
        //若容器中有该具体类的扩展回调
        foreach ($this->getExtenders($abstract) as $extender) {
            $object = $extender($object, $this);
        }
        if ($this->isShared($abstract)) {
            $this->instances[$abstract] = $object;
        }
        $this->resoleved[$abstract] = true;
        return $object;
    }
1097161
private function instantiate($class, array $parameters = [])
    {
        if (is_callable($class)) {
            return $class($this, $parameters);
        }
        $reflector = new \ReflectionClass($class);

        if (!$reflector->isInstantiable()) {
            //Try to give a descriptive exception message
            if ($reflector->isAbstract()) {
                throw new \InvalidArgumentException("Class {$class} is abstract and can not be instantiated.");
            }
            if ($reflector->isInterface()) {
                throw new \InvalidArgumentException("{$class} is an interface and can not be instantiated.");
            }
            throw new \InvalidArgumentException("Class {$class} can not be instantiated.");
        }

        $constructor = $reflector->getConstructor();

        if ($constructor === null || $constructor->getNumberOfParameters() === 0) {
            //Since the class has no constructor, it can not be instantiated with ReflectionClass

            //Also, if the class has no constructor arguments, it is cheaper to instantiate it directly
            //Although this has the downside of disallowing variable sized argument lists if
            //no arguments are required by the constructor signature.
            return new $class;
        }

        $constructorArgs = $constructor->getParameters();
        $arguments       = $this->resolveDependencies($constructorArgs, $parameters);

        if (!empty($parameters)) {
            //We need to sort the arguments because ReflectionClass passes them by order, not by index
            ksort($arguments);
        }

        return $reflector->newInstanceArgs($arguments);
    }