自动绑定（Autowiring）自动解析（Automatic Resolution）

@param $className
@return object
@throws \Exception
197787
public function build($className)
        {

                if(is_string($className) and $this->offsetExists($className)) {
                        $className =  $this->offsetGet($className);
                        if(is_object($className)) {
                                return $className;
                        }
                }

                // 如果是匿名函数（Anonymous functions），也叫闭包函数（closures）
                if ($className instanceof \Closure) {
                        // 执行闭包函数，并将结果
                        return $this->getClosure($className, $this);
                }
                /** @var \ReflectionClass $reflector */
                $reflector = new \ReflectionClass($className);

                // 检查类是否可实例化, 排除抽象类abstract和对象接口interface
                if (!$reflector->isInstantiable()) {
                        throw new \Exception("Can't instantiate ".$className);
                }

                /** @var \ReflectionMethod $constructor 获取类的构造函数 */
                $constructor = $reflector->getConstructor();
                // 若无构造函数，直接实例化并返回
                if (is_null($constructor)) {
                        return new $className;
                }

                // 取构造函数参数,通过 ReflectionParameter 数组返回参数列表
                $parameters = $constructor->getParameters();
                // 递归解析构造函数的参数
                $dependencies = $this->getDependencies($parameters);
                // 创建一个类的新实例，给出的参数将传递到类的构造函数。
                $class =  $reflector->newInstanceArgs($dependencies);
                $this->aliases[$className] = $class;
                return $class;
        }
1288802
public function getJsonConverter($className)
    {
        switch ($className) {
            case 'Puli\Manager\Api\Config\ConfigFile':
                return $this->container->getConfigFileConverter();

            case 'Puli\Manager\Api\Module\ModuleFile':
                return $this->container->getLegacyModuleFileConverter();

            case 'Puli\Manager\Api\Module\RootModuleFile':
                return $this->container->getLegacyRootModuleFileConverter();

            default:
                throw new InvalidArgumentException(sprintf(
                    'Could not find converter for class "%s".',
                    $className
                ));
        }
    }
651629
public function newInstance($className)
    {

        // lock the method
        \Mutex::lock($this->mutex);

        // we're not dispatched
        $this->dispatched = false;

        // initialize the data
        $this->className = $className;

        // notify the thread
        $this->notify();

        // wait till we've dispatched the request
        while ($this->dispatched === false) {
            usleep(100);
        }

        // try to load the last created instance
        if (isset($this->instances[$last = sizeof($this->instances) - 1])) {
            $instance = $this->instances[$last];
        } else {
            throw new \Exception('Requested instance can\'t be created');
        }

        // unlock the method
        \Mutex::unlock($this->mutex);

        // return the created instance
        return $instance;
    }
491686
public function setUserClassName($className)
    {
        try {
            \Parable\DI\Container::create($className);
        } catch (\Exception $e) {
            throw new \Parable\Framework\Exception("Class '{$className}' could not be instantiated.");
        }

        $this->userClassName = $className;
        return $this;
    }
206897
public function removeInstance($className): self
	{
		// Determine the instance name
		$instanceName = strtolower($className);

		if (!isset($this->{$instanceName}))
		{
			throw new FactoryException("Could not remove instance of '".$instanceName."'. Instance was not found.", 1);
		}

		// Unset
		unset($this->{$instanceName});

		// Return itself
		return $this;
	}
349907
public function handlerIdByClassName($className)
    {
        foreach ($this->handlers() as $id => $class) {
            if ($class->className() === $className) {
                return $id;
            }
        }

        throw new Exception("Handler with classname {$className} not found.");
    }
1112088
public function setMainConfigClassName($className)
    {
        if (!class_exists($className)) {
            throw new \Parable\Framework\Exception("Main Config class '{$className}' does not exist.");
        }
        $this->mainConfigClass = $className;
        return $this;
    }
1320788
public static function instantiate($className)
    {
        $objectManager = self::get()->getObjectManager();
        $args = func_get_args();

        if (1 === count($args)) {
            return $objectManager->get($className);
        }

        return call_user_func_array([$objectManager, 'get'], $args);
    }
441476
public function getObjectManagerNameByClassName($className)
    {
        $realClass = ClassUtils::getRealClass($className);
        if (false === $this->hasObjectManagerNameByClassName($realClass)) {
            $errMsg = sprintf('Failed to get the manager\'s name for class %s', $realClass);
            throw new Exception\ErrorBuildObjectManagerNameException($errMsg);
        }

        return $this->classNameToObjectManagerName[$realClass];
    }
1119506
public function createController($classname)
    {
        return (new $classname())
            ->setTheme($this)
            ->setTimberBridge($this->getTimberBridge())
            ->setWpBridge($this->getWpBridge());
    }
301282
public static function get_handler($classname) {
        global $DB;

        if (strpos($classname, '\\') !== 0) {
            $classname = '\\' . $classname;
        }

        $record = $DB->get_record('messageinbound_handlers', array('classname' => $classname), '*', IGNORE_MISSING);
        if (!$record) {
            return false;
        }
        return self::handler_from_record($record);
    }
1272802
public function resolveClassname($classname)
    {
        $path = $this->parseClassname($classname);

        // Check if the resource was found
        if (class_exists($path)) {
            return $path;
        }

        // If we are on the latest version, stop searching
        if ($this->isLatest()) {
            throw new Exceptions\ResourceNotFoundException($classname, $path);
        }

        // Search on the latest version
        $path = $this->parseClassname($classname, true);

        // If still does not exists, fail
        if (!class_exists($path)) {
            throw new Exceptions\ResourceNotFoundException($classname, $path);
        }

        return $path;
    }
597331
public function build(string $className): interfaces\commands\Command
    {
        $params = is_subclass_of($className, interfaces\commands\ExecutableCommand::class) ? [$this->bus] : [];

        /** @var interfaces\commands\Command $command */
        $command = \Yii::createObject($className, $params);

        $this->prepareCommand($command);

        return $command;
    }
913391
protected function make($className) {
        $refl = new ReflectionClass($className);
        $deps = $this->getDependencies($refl);

        if (empty($deps)) {
            return $refl->newInstance();
        }

        $resolvedDeps = array_map([$this, 'resolveDependency'], $deps);

        return $refl->newInstanceArgs($resolvedDeps);
    }
714710
private function createClassInstance($className)
    {
        if (empty($className)) {
            return new stdClass();
        }

        try {
            $refClass = new ReflectionClass($className);
            return $refClass->newInstance();
        } catch (Exception $e) {
            throw new DeserializationException("Class [$className] could not be instantiated");
        }
    }
795682
public function parseClassName($className)
    {
        if (!preg_match('/^\\\\?(.*?)\\\\?([a-zA-Z0-9_]+)$/', $className, $matches)) {
            throw new \Exception('Invalid class name "' . $className . '" given');
        }

        return array(
            'namespace' => $matches[1],
            'classname' => $matches[2],
            'fqcn'      => $className
        );
    }
902304
public static function fromClass(string $className) : Mapping
    {
        /* @var ApiMapping $instance */
        $className = '\\'.ltrim($className, '\\');
        if (!class_exists($className, true)) {
            throw new MappingException(
                \sprintf('Provided class %s could not be loaded.', $className)
            );
        }
        $instance = new $className();

        if (!in_array(ApiMapping::class, \class_implements($instance, true))) {
            throw new MappingException(
                \sprintf('Class %s must implement %s.', \ltrim($className, '\\'), ApiMapping::class)
            );
        }

        $mappedClass = [
            static::CLASS_KEY => $instance->getClass(),
            static::ALIAS_KEY => $instance->getAlias(),
            static::ALIASED_PROPERTIES_KEY => $instance->getAliasedProperties(),
            static::HIDE_PROPERTIES_KEY => $instance->getHideProperties(),
            static::ID_PROPERTIES_KEY => $instance->getIdProperties(),
            static::URLS_KEY => $instance->getUrls(),
        ];

        if (\in_array(HalMapping::class, \class_implements($instance, true))) {
            $mappedClass[static::CURIES_KEY] = $instance->getCuries();
        }

        if (\in_array(JsonApiMapping::class, \class_implements($instance, true))) {
            $mappedClass[static::RELATIONSHIPS_KEY] = $instance->getRelationships();
        }

        return static::fromArray($mappedClass);
    }