src/factories/implementations/dependency-injection-factory.php
private function make( $class_name, $named_arguments ) {
		$reflector   = new \ReflectionClass( $class_name );
		$constructor = $reflector->getConstructor();

		if ( is_subclass_of( $class_name, Singleton::class ) ) {
			return $class_name::get_instance();
		}

		if ( $reflector->isAbstract() ) {
			return null;
		}

		if ( null === $constructor ) {
			return new $class_name();
		}

		$dependencies = $this->get_dependencies( $constructor, $named_arguments );
		$obj          = $reflector->newInstanceArgs( $dependencies );

		// Handle special case of registering requests
		if ( $obj instanceof Request ) {
			$this->validators[] = $obj;
		}

		return $obj;
	}
private function make( $class_name, $named_arguments ) {
		$reflector   = new \ReflectionClass( $class_name );
		$constructor = $reflector->getConstructor();

		if ( is_subclass_of( $class_name, Singleton::class ) ) {
			return $class_name::get_instance();
		}

		if ( $reflector->isAbstract() ) {
			return null;
		}

		if ( null === $constructor ) {
			return new $class_name();
		}

		$dependencies = $this->get_dependencies( $constructor, $named_arguments );
		$obj          = $reflector->newInstanceArgs( $dependencies );

		// Handle special case of registering requests
		if ( $obj instanceof Request ) {
			$this->validators[] = $obj;
		}

		return $obj;
	}
private function make ( $ class_name , $ named_arguments ) { $ reflector = new \ ReflectionClass ( $ class_name ) ; $ constructor = $ reflector -> getConstructor ( ) ; if ( is_subclass_of ( $ class_name , Singleton :: class ) ) { return $ class_name :: get_instance ( ) ; } if ( $ reflector -> isAbstract ( ) ) { return null ; } if ( null === $ constructor ) { return new $ class_name ( ) ; } $ dependencies = $ this -> get_dependencies ( $ constructor , $ named_arguments ) ; $ obj = $ reflector -> newInstanceArgs ( $ dependencies ) ; // Handle special case of registering requests if ( $ obj instanceof Request ) { $ this -> validators [ ] = $ obj ; } return $ obj ; }
Given a class and arguments to inject into that class, this
will create an instance of the given object.

This will handle special cases as well.

@param  string $class_name      The name of the class to make
@param  array  $named_arguments The arguments to inject into the class
@return mixed                   An instance of the class

@throws \ReflectionException
Given a class and arguments to inject into that class this will create an instance of the given object .