Creates a class instance.

@param  string|\Closure $class      Class name or closure
@param  array           $parameters Constructor parameters
@return object
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;
	}
709122
public static function initializeClass($class)
    {
        try
        {
            // Get a static method named 'initialize'. If not found,
            // ReflectionMethod() will throw a ReflectionException.
            $ref = new \ReflectionMethod($class, 'initialize');

            // The 'initialize' method is probably 'private'.
            // Make it accessible before calling 'invoke'.
            // Note that 'setAccessible' is not available
            // before PHP version 5.3.2.
            $ref->setAccessible(true);

            // Execute the 'initialize' method.
            $ref->invoke(null);
        }
        catch (Exception $e)
        {
        }
    }
147595
protected function instance($class)
    {
        $reflection = new \ReflectionClass($class);

        $arguments = array();

        $constructor = $reflection->getConstructor();

        if ($this->container->has($class))
        {
            return $this->container->get($class);
        }

        if ($constructor !== null)
        {
            $arguments = $this->arguments($constructor);
        }

        return $reflection->newInstanceArgs($arguments);
    }
924419
public function makeInstance($class, $data)
    {
        $class = new \ReflectionClass($class);
        $constructArguments = [];
        if (isset($data['__construct'])) {
            $constructArguments = $this->constructorArgs($data['__construct']);
        }

        return $class->newInstanceArgs($constructArguments);
    }
1084481
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 Exception($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;
            }

            $parameters = $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.
            $dependencies = $this->getDependencies($parameters);

            return $reflector->newInstanceArgs($dependencies);
        }
316643
protected function createClient($class)
    {
        try {
            $reflection = new \ReflectionClass($class);
        } catch (\ReflectionException $e) {
            throw new ModelException(sprintf(
                "Could not instantiate Model class '%s'. (Reason: '%s').",
                $class,
                $e->getMessage()
            ));
        }

        if (!$reflection->implementsInterface('\PommProject\Foundation\Client\ClientInterface')) {
            throw new ModelException(sprintf("'%s' class does not implement the ClientInterface interface.", $class));
        }

        if (!$reflection->isSubclassOf('\PommProject\ModelManager\Model\Model')) {
            throw new ModelException(sprintf("'%s' class does not extend \PommProject\ModelManager\Model.", $class));
        }

        return new $class();
    }
592662
final protected static function getInstance($class, ...$params) {
        if (isset(self::$instances[$class]))
            return self::$instances[$class];

        // set a marker to detect recursive method invocations
        static $currentCreations;
        if (isset($currentCreations[$class])) throw new RuntimeException('Detected recursive call of '.__METHOD__.'('.$class.')');
        $currentCreations[$class] = true;

        // check validity of the passed class (omitting this check can cause an uncatchable fatal error)
        if (!is_a($class, __CLASS__, $allowString=true)) {
            if (!is_class($class)) throw new ClassNotFoundException('Class not found: '.$class );
            throw new InvalidArgumentException('Not a '.__CLASS__.' subclass: '.$class);
        }

        // instantiate the class with the passed parameters
        self::$instances[$class] = new $class(...$params);

        // reset the marker for detecting recursive method invocations
        unset($currentCreations[$class]);

        return self::$instances[$class];
    }
942013
protected function _buildInstance($instance, array $parameters = [])
  {
    if(is_scalar($instance) && class_exists($instance))
    {
      return Objects::create($instance, $parameters);
    }
    return $instance;
  }
8137
public static function createObject($class, ...$args) : object
    {
        $work = self::wrapObject($class);
        $work->__gentryConstruct(...$args);
        return $work;
    }
856633
private static function forkCallMapClass(\ReflectionClass $class): \ReflectionClass
    {
        if ($class->isTrait()) {
            $class = self::forkTrait($class);
        }

        try {
            $compile = self::$compile;
            $compile(self::createCallmapProxyCode($class));
        } catch (\ParseError $pe) {
            throw new ProxyCreationFailure(
                    'Failure while creating CallMap instance of '
                    . $class->getName() . ': ' . $pe->getMessage(),
                    $pe
            );
        }

        return new \ReflectionClass($class->getName() . 'CallMapProxy');
    }
613321
public function build($class, ...$arguments)
    {
        if (is_object($class)) {
            return $class;
        }

        if (!class_exists($class)) {
            throw new InvalidArgumentException("Unable to build class: $class it does not exist");
        }

        $reflection = new ReflectionClass($class);
        $this->log(LogLevel::DEBUG, "Building class: {class}", ['class' => $class]);
        $object = $reflection->newInstanceArgs($arguments);

        if ($object instanceof BuilderAwareInterface) {
            $object->setBuilder($this);
        }

        if ($this->logger && ($object instanceof LoggerAwareInterface)) {
            $object->setLogger($this->logger);
        }

        return $object;
    }
407587
protected static function makeInstance(
        $class, array $options = null
    ): Implementation {

        $options || $options = ['provider' => self::app()];

        return IOC::make($class, [$options, true]);
    }
766419
public function bind($contract, $class, $args = [])
    {
        $closure = function($class, $args) {
            $reflect = new \ReflectionClass($class);
            return $reflect->newInstanceArgs($args);
        };

        $this->bindings[$contract] = [
            'type' => 'closure',
            'closure' => $closure,
            'class' => $class,
            'args' => $args
        ];

        if (!class_exists($contract, false)) {
            eval("class {$contract} extends \Hades\Container\Facade {} ");
        }
    }
540045
public function callArray($class, array $args = array())
    {
        //argument 1 must be a string
        Argument::i()->test(1, 'string');

        //get the true class
        $route = $this->get($class);
        
        //if route is already an abject
        if (is_object($route)) {
            //return it
            return $route;
        }
        
        //if the static method i exists
        if (method_exists($route, 'i')) {
            //instantiate it
            return forward_static_call_array(array($route, 'i'), $args);
        }
        
        //instantiate it
        $reflect = new \ReflectionClass($route);
        return $reflect->newInstanceArgs($args);
    }
728116
public function create(string $class, array $map = [], array $params = null)
    {
        try {
            return Builder::create($this, $class, $map, $params);
        } catch (\InvalidArgumentException $e) {
            throw new InvalidArgumentException($e->getMessage());
        }
    }
1169253
public static function newInstance($class, ...$args)
    {
        if(!isset(static::$classNameMap[$class]))
        {
            $ref = new \ReflectionClass($class);
            $className = static::getNewClassName($ref->getShortName());
            $tpl = static::getTpl($ref, $className);
            eval($tpl);
            static::$classNameMap[$class] = $className;
        }
        return new static::$classNameMap[$class](...$args);
    }
222551
public function generate(\ReflectionClass $originalClass, PhpClass $class)
    {
        $methods = ReflectionUtils::getOverrideableMethods($originalClass, true);

        // no public, non final methods
        if (empty($methods)) {
            return;
        }

        if (null !== $this->markerInterface) {
            $class->setImplementedInterfaces(array_merge(
                $class->getImplementedInterfaces(),
                array($this->markerInterface)
            ));
        }

        $initializer = new PhpProperty();
        $initializer->setName($this->prefix.'lazyInitializer');
        $initializer->setVisibility(PhpProperty::VISIBILITY_PRIVATE);
        $class->setProperty($initializer);

        $initialized = new PhpProperty();
        $initialized->setName($this->prefix.'initialized');
        $initialized->setDefaultValue(false);
        $initialized->setVisibility(PhpProperty::VISIBILITY_PRIVATE);
        $class->setProperty($initialized);

        $initializerSetter = new PhpMethod();
        $initializerSetter->setName($this->prefix.'setLazyInitializer');
        $initializerSetter->setBody('$this->'.$this->prefix.'lazyInitializer = $initializer;');

        $parameter = new PhpParameter();
        $parameter->setName('initializer');
        $parameter->setType('\CG\Proxy\LazyInitializerInterface');
        $initializerSetter->addParameter($parameter);
        $class->setMethod($initializerSetter);

        $this->addMethods($class, $methods);

        $initializingMethod = new PhpMethod();
        $initializingMethod->setName($this->prefix.'initialize');
        $initializingMethod->setVisibility(PhpMethod::VISIBILITY_PRIVATE);
        $initializingMethod->setBody(
            $this->writer
                ->reset()
                ->writeln('if (null === $this->'.$this->prefix.'lazyInitializer) {')
                    ->indent()
                    ->writeln('throw new \RuntimeException("'.$this->prefix.'setLazyInitializer() must be called prior to any other public method on this object.");')
                    ->outdent()
                ->write("}\n\n")
                ->writeln('$this->'.$this->prefix.'lazyInitializer->initializeObject($this);')
                ->writeln('$this->'.$this->prefix.'initialized = true;')
                ->getContent()
        );
        $class->setMethod($initializingMethod);
    }