src/mako/syringe/Container.php
protected function reflectionFactory(string $class, array $parameters): object
	{
		$class = new ReflectionClass($class);

		// Check that it's possible to instantiate the class

		if(!$class->isInstantiable())
		{
			throw new UnableToInstantiateException(vsprintf('Unable to create a [ %s ] instance.', [$class->getName()]));
		}

		// Get the class constructor

		$constructor = $class->getConstructor();

		// If we don't have a constructor then we'll just return a new instance

		if($constructor === null)
		{
			return $class->newInstance();
		}

		// The class had a constructor so we'll return a new instance using our resolved parameters

		return $class->newInstanceArgs($this->resolveParameters($constructor->getParameters(), $parameters, $class));
	}
protected function reflectionFactory(string $class, array $parameters): object
	{
		$class = new ReflectionClass($class);

		// Check that it's possible to instantiate the class

		if(!$class->isInstantiable())
		{
			throw new UnableToInstantiateException(vsprintf('Unable to create a [ %s ] instance.', [$class->getName()]));
		}

		// Get the class constructor

		$constructor = $class->getConstructor();

		// If we don't have a constructor then we'll just return a new instance

		if($constructor === null)
		{
			return $class->newInstance();
		}

		// The class had a constructor so we'll return a new instance using our resolved parameters

		return $class->newInstanceArgs($this->resolveParameters($constructor->getParameters(), $parameters, $class));
	}
protected function reflectionFactory ( string $ class , array $ parameters ) : object { $ class = new ReflectionClass ( $ class ) ; // Check that it's possible to instantiate the class if ( ! $ class -> isInstantiable ( ) ) { throw new UnableToInstantiateException ( vsprintf ( 'Unable to create a [ %s ] instance.' , [ $ class -> getName ( ) ] ) ) ; } // Get the class constructor $ constructor = $ class -> getConstructor ( ) ; // If we don't have a constructor then we'll just return a new instance if ( $ constructor === null ) { return $ class -> newInstance ( ) ; } // The class had a constructor so we'll return a new instance using our resolved parameters return $ class -> newInstanceArgs ( $ this -> resolveParameters ( $ constructor -> getParameters ( ) , $ parameters , $ class ) ) ; }
Creates a class instance using reflection.

@param  string                                                $class      Class name
@param  array                                                 $parameters Constructor parameters
@throws \mako\syringe\exceptions\UnableToInstantiateException
@return object
Creates a class instance using reflection .