當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Definition::getInjectionMethodParameters方法代碼示例

本文整理匯總了PHP中Definition::getInjectionMethodParameters方法的典型用法代碼示例。如果您正苦於以下問題:PHP Definition::getInjectionMethodParameters方法的具體用法?PHP Definition::getInjectionMethodParameters怎麽用?PHP Definition::getInjectionMethodParameters使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Definition的用法示例。


在下文中一共展示了Definition::getInjectionMethodParameters方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: resolveMethodParameters

    /**
     * Resolve parameters referencing other services
     *
     * @param string $class
     * @param string $method
     * @param array $callTimeUserParams
     * @param bool $isInstantiator
     * @param string $alias
     * @return array
     */
    protected function resolveMethodParameters($class, $method, array $callTimeUserParams, $isInstantiator, $alias)
    {
        /* @var $isSubclassFunc Closure */
        static $isSubclassFunc = null;
        static $isSubclassFuncCache = null; // null as unset, array when set

        $isSubclassFunc = function($class, $type) use (&$isSubclassFuncCache) {
            /* @see https://bugs.php.net/bug.php?id=53727 */
            if ($isSubclassFuncCache === null) {
                $isSubclassFuncCache = array();
            }
            if (!array_key_exists($class, $isSubclassFuncCache)) {
                $isSubclassFuncCache[$class] = class_parents($class, true) + class_implements($class, true);
            }
            return (isset($isSubclassFuncCache[$class][$type]));
        };
        
        // parameters for this method, in proper order, to be returned
        $resolvedParams = array();
        
        // parameter requirements from the definition
        $injectionMethodParameters = $this->definition->getInjectionMethodParameters($class, $method);
        
        // computed parameters array
        $computedParams = array(
            'value'    => array(),
            'lookup'   => array(),
            'optional' => array()
        );
        
        // retrieve instance configurations for all contexts
        $iConfig = array();
        $aliases = $this->instanceManager->getAliases();
        
        // for the alias in the dependency tree
        if ($alias && $this->instanceManager->hasConfiguration($alias)) {
            $iConfig['thisAlias'] = $this->instanceManager->getConfiguration($alias);
        }
        
        // for the current class in the dependency tree
        if ($this->instanceManager->hasConfiguration($class)) {
            $iConfig['thisClass'] = $this->instanceManager->getConfiguration($class);
        }
        
        // for the parent class, provided we are deeper than one node
        list($requestedClass, $requestedAlias) = ($this->instanceContext[0][0] == 'NEW')
            ? array($this->instanceContext[0][1], $this->instanceContext[0][2])
            : array($this->instanceContext[1][1], $this->instanceContext[1][2]);

        if ($requestedClass != $class && $this->instanceManager->hasConfiguration($requestedClass)) {
            $iConfig['requestedClass'] = $this->instanceManager->getConfiguration($requestedClass);
            if ($requestedAlias) {
                $iConfig['requestedAlias'] = $this->instanceManager->getConfiguration($requestedAlias);
            }
        }

        // This is a 2 pass system for resolving parameters
        // first pass will find the sources, the second pass will order them and resolve lookups if they exist
        // MOST methods will only have a single parameters to resolve, so this should be fast
        
        foreach ($injectionMethodParameters as $name => $info) {
            list($type, $isOptional, $isTypeInstantiable) = $info;

            // PRIORITY 1 - consult user provided parameters
            if (isset($callTimeUserParams[$name])) {
                if (is_string($callTimeUserParams[$name])) {
                    if ($this->instanceManager->hasAlias($callTimeUserParams[$name])) {
                        // was an alias provided?
                        $computedParams['lookup'][$name] = array(
                            $callTimeUserParams[$name],
                            $this->instanceManager->getClassFromAlias($callTimeUserParams[$name])
                        );    
                    } elseif ($this->definition->hasClass($callTimeUserParams[$name])) {
                        // was a known class provided?
                        $computedParams['lookup'][$name] = array(
                            $callTimeUserParams[$name],
                            $callTimeUserParams[$name]
                        );
                    } else {
                        // must be a value
                        $computedParams['value'][$name] = $callTimeUserParams[$name]; 
                    }
                } else {
                    // int, float, null, object, etc
                    $computedParams['value'][$name] = $callTimeUserParams[$name];
                }
                continue;
            }
            
            // PRIORITY 2 -specific instance configuration (thisAlias) - this alias
//.........這裏部分代碼省略.........
開發者ID:noose,項目名稱:zf2,代碼行數:101,代碼來源:DependencyInjector.php


注:本文中的Definition::getInjectionMethodParameters方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。