Creates an anonymous object based on a reflection.

@param mixed $class A class, object or trait to wrap.
@param mixed ...$args Arguments for use during construction.
@return object An anonymous, wrapped object.
@see Wrapper::wrapObject
8137
public static function createObject($class, ...$args) : object
    {
        $work = self::wrapObject($class);
        $work->__gentryConstruct(...$args);
        return $work;
    }
970106
private static function getInstance($class)
    {
        //get the backtrace
        $trace = debug_backtrace();
        $args = array();
        
        //the 2nd line is the caller method
        if (isset($trace[1]['args']) && count($trace[1]['args']) > 1) {
            //get the args
            $args = $trace[1]['args'];
            //shift out the class name
            array_shift($args);
            //then maybe it's the 3rd line?
        } else if (isset($trace[2]['args']) && count($trace[2]['args']) > 0) {
            //get the args
            $args = $trace[2]['args'];
        }
        
        //if there's no args or there's no construct to accept the args
        if (count($args) === 0 || !method_exists($class, '__construct')) {
            //just return the instantiation
            return new $class;
        }
        
        //at this point, we need to vitually call the class
        $reflect = new \ReflectionClass($class);
        
        try { //to return the instantiation
            return $reflect->newInstanceArgs($args);
        } catch (\ReflectionException $e) {
            //trigger error
            Exception::i()
                ->setMessage(self::ERROR_REFLECTION)
                ->addVariable($class)
                ->addVariable('new')
                ->trigger();
        }
    }
355759
public static function instance($args = null)
    {
        $class = self::className();
        $instanceKey = self::instanceKey($args);

        if ( ! isset(self::$_instances[$instanceKey]))
        {
            self::$_instances[$instanceKey] = is_array($args) ? new $class($args) : new $class;
        }
        return self::$_instances[$instanceKey];
    }
180341
protected static function createFacade($class='', $args=[])
    {
        $class=$class ?: static::class;
        $facadeClass=static::getFacadeClass();
        if ($facadeClass) {
            $class=$facadeClass;
        } elseif (isset(self::$bind[$class])) {
            $class=self::$bind[$class];
        }
        return Container::getInstance()->make($class, $args);
    }
624737
public function newInstance(string $class, $args = [], string $selector = Injector::DEFAULT_SELECTOR)
    {
        if (!class_exists($class))
            throw new DIException("Class $class does not exist");

        if (isset($this->factories[$class]))
            return $this->factories[$class]->produce($class, $args, $selector, $this);

        return $this->default_factory->produce($class, $args, $selector, $this);
    }
1180499
public function whenCreating($class)
    {
        if (!isset($this->args[$class])) {
            $this->args[$class] = new ClassMeta($class, $this);
        }

        return $this->args[$class];
    }
659809
private function handle(string $class, array $args)
    {
        $latest = null;
        foreach ($this->catchers[$class] as $catcher) {
            $latest = $catcher(...$args);
        }
        return $latest;
    }
1329908
public function create($class) {
        $reflectionClass = new ReflectionClass($class);
        $reflectionMethod = $reflectionClass->getConstructor();
        if (!$reflectionMethod) {
            return new $class;
        }
        $params = &$this->fetchDepsFromSignature($reflectionMethod);
        return $reflectionClass->newInstanceArgs($params);
    }
135148
public function get($class, ...$args)
    {
        $poolName = trim($class, '\\');

        if (!$poolName) {
            return null;
        }

        $pool     = $this->map[$poolName] ?? null;
        if ($pool == null) {
            $pool = $this->applyNewPool($poolName);
        }

        if ($pool->count()) {
            $obj = $pool->shift();
            $obj->__isConstruct = false;
            return $obj;
        } else {
            $reflector         = new \ReflectionClass($poolName);
            $obj               = $reflector->newInstanceWithoutConstructor();
            $obj->__useCount   = 0;
            $obj->__genTime    = time();
            $obj->__isConstruct = false;
            $obj->__DSLevel    = Macro::DS_PUBLIC;
            unset($reflector);
            return $obj;
        }
    }
167948
private static function createObject($className, array $args = null)
    {
        try {
            if (!$args) {
                return new $className;
            } else {
                $c = new \ReflectionClass($className);
                return $c->newInstanceArgs($args);
            }
        } catch (\Exception $e) {
            throw new RuntimeException($e->getMessage(), $e->getCode(), $e);
        }
    }
898297
public static function invokePrivateMethod($object, $method, $args = [], $class = null)
    {
        if (is_null($class)) {
            $class = $object;
        }

        $method = new \ReflectionMethod($class, $method);
        $method->setAccessible(true);

        return $method->invokeArgs($object, $args);
    }
1052
public function call($class)
    {
        //argument 1 must be a string
        Argument::i()->test(1, 'string');

        $args = func_get_args();
        $class = array_shift($args);

        return $this->callArray($class, $args);
    }
870922
private function createObject($class)
    {
        if (!class_exists($class)) {
            throw new JsonRpc\Exception\Method();
        }

        try {
            return new $class();
        } catch (Exception $e) {
            throw new JsonRpc\Exception\Method();
        }
    }
896225
protected function makeAttributesObject($class, array $values, array $args, array $excludeArgs){
        $attributes = [];
        foreach ($args as $arg){
            if(in_array($arg, $excludeArgs)){
                $attributes[] = null;
            }else{
                $attributes[] = $values[$arg] ?? null;
            }
        }
        return new $class(...$attributes);
    }
565415
public static function newInstance($class) {
		$className = str_replace(':', '\\', $class);
		$reflectedClass = new ReflectionClass($className);

		if ($reflectedClass->isInstantiable()) {
			$constructor = $reflectedClass->getConstructor();

			if ($constructor) {
				$parameters = $constructor->getParameters();
				$constructorParameters = array();

				foreach ($parameters as $parameter) {
					if ($parameter->getClass()) {
						$constructorParameters[] = self::newInstance($parameter->getClass()->getName());
					} else {
						$constructorParameters[] = $parameter->getDefaultValue();
					}
				}

				return $reflectedClass->newInstanceArgs($constructorParameters);
			} else {
				return $reflectedClass->newInstance();
			}

		} else {
			throw new Exception($class." is not instantiable Class");
		}
	}
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');
    }
400505
public function newInstance($class = null, $options = [])
    {
        if ($class === null) {
            $class = get_class($this);
        } elseif ($class instanceof self) {
            $class = get_class($class);
        }

        if (is_string($class) && $class[0] != '\\') {
            $class = '\\'.$class;
        }

        if ($this->persistence) {
            return $this->persistence->add($class, $options);
        }

        return new $class($options);
    }