Instantiate an instance of the given type.

@param  string $key
@param  array  $parameters

@throws \Exception
@return mixed
179649
protected function instanciate($key, $parameters = null)
    {

        if ($key instanceof \Closure) {
            return call_user_func_array($key, $parameters);
        }

        $reflection = new \ReflectionClass($key);
        return $reflection->newInstanceArgs($parameters);
    }
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);

    }
1157633
public function addJoin($key, array $parameters, $joinType = null)
    {
        if ( ! is_null($joinType)) {

            if ($joinType == 'join' || stripos($joinType, 'inner') !== false) {
                $this->joinTypes[$key] = 'join';
            } elseif (stripos($joinType, 'right') !== false) {
                $this->joinTypes[$key] = 'rightJoin';
            } else {
                unset( $this->joinTypes[$key] );
            }
        }

        $this->joins[$key] = $parameters;

        return $this;
    }
885527
public function execute($command, $parameters = array())
    {
        try {
            $cmdSet = $this->client->createCommand($command, $parameters);
            return $this->client->executeCommand($cmdSet);
        }catch(\Exception $e) {
            $this->exception = $e;
            return false;
        }
    }
487651
public function &call($type, $method, $parameters = array())
	{
		$class = $this->get_class($type);

		if (in_array($class, $this->legacy))
		{
			switch ($type)
			{
				case 'Cache':
					// For backwards compatibility with old non-static
					// Cache::create() methods
					if ($method === 'get_handler')
					{
						$result = @call_user_func_array(array($class, 'create'), $parameters);
						return $result;
					}
					break;
			}
		}

		$result = call_user_func_array(array($class, $method), $parameters);
		return $result;
	}
516100
public static function create($params = [])
    {
        if (\is_array($params)) {
            return new self($params);
        }

        if ($params instanceof self) {
            return $params;
        }

        throw new InvalidException('Invalid data type');
    }
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);
    }
1370147
public static function create($parameters)
    {
        if (is_string($parameters)) {
            return self::fromString($parameters);
        }

        if (is_array($parameters)) {
            return self::fromArray($parameters);
        }

        throw new InvalidArgumentException('Invalid parameters type');
    }
965376
public function factory($class, array $parameters = []): object
	{
		// Instantiate class

		if($class instanceof Closure)
		{
			$instance = $this->closureFactory($class, $parameters);
		}
		else
		{
			$instance = $this->reflectionFactory($class, $parameters);
		}

		// Inject container using setter if the class is container aware

		if($this->isContainerAware($instance))
		{
			$instance->setContainer($this);
		}

		// Return the instance

		return $instance;
	}
1071026
public function make($key)
    {
        switch ($key) {
            case 'config': return $this->config;
            case 'em': return $this->entityManager;
            case 'extension': return $this->extensionManager;
            case 'migration': return $this->migrationManager;
            case 'log': return $this->logger;
            case 'file': return $this->files;
            default: return $this;
        }
    }
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;
        }
    }
302473
static function &getInstance($key=null)
	{
		static $instances;

		if (!isset($instances))
		{
			$instances = array();
		}

		if (!isset($instances[$key]))
		{
			$instances[$key] = new static($key);
		}

		return $instances[$key];
	}
979744
public function withParameters(array $parameters): self
    {
        $query = $this;

        foreach ($parameters as $key => $parameter) {
            $query = $query->withParameter($key, $parameter);
        }

        return $query;
    }
575715
public function get($key, array $parameters = [])
    {
        // If service is a factory, we should always
        // return new instance of the service.
        if (isset($this->factories[$key])) {
            return $this->resolve($this->factories[$key], $parameters);
        }

        // Otherwise, look for service
        // in services collection.
        if (isset($this->services[$key])) {
            // Resolve service jf we don't have
            // a deposit for this service.
            if ( ! isset($this->deposit[$key])) {
                $this->deposit[$key] = $this->resolve($this->services[$key], $parameters);
            }

            return $this->deposit[$key];
        }

        throw new BindingResolutionException("Unresolvable resolution. The [{$key}] binding is not registered.");
    }
929840
public function build($builder, $parameters) {
		$instance = $this->builder->build($builder, $parameters);

		return $instance;
	}
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;
    }
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;
        }