当前位置: 首页>>代码示例>>PHP>>正文


PHP Definition::isShared方法代码示例

本文整理汇总了PHP中Symfony\Component\DependencyInjection\Definition::isShared方法的典型用法代码示例。如果您正苦于以下问题:PHP Definition::isShared方法的具体用法?PHP Definition::isShared怎么用?PHP Definition::isShared使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\DependencyInjection\Definition的用法示例。


在下文中一共展示了Definition::isShared方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getProxyFactoryCode

    /**
     * {@inheritdoc}
     */
    public function getProxyFactoryCode(Definition $definition, $id)
    {
        $instantiation = 'return';
        if ($definition->isShared() && ContainerInterface::SCOPE_CONTAINER === $definition->getScope(false)) {
            $instantiation .= " \$this->services['{$id}'] =";
        } elseif ($definition->isShared() && ContainerInterface::SCOPE_PROTOTYPE !== ($scope = $definition->getScope(false))) {
            $instantiation .= " \$this->services['{$id}'] = \$this->scopedServices['{$scope}']['{$id}'] =";
        }
        $methodName = 'get' . Container::camelize($id) . 'Service';
        $proxyClass = $this->getProxyClassName($definition);
        return <<<EOF
        if (\$lazyLoad) {

            {$instantiation} new {$proxyClass}(
                function (&\$wrappedInstance, \\ProxyManager\\Proxy\\LazyLoadingInterface \$proxy) {
                    \$wrappedInstance = \$this->{$methodName}(false);

                    \$proxy->setProxyInitializer(null);

                    return true;
                }
            );
        }


EOF;
    }
开发者ID:nuwe1,项目名称:symfony,代码行数:30,代码来源:ProxyDumper.php

示例2: getProxyFactoryCode

    /**
     * {@inheritdoc}
     */
    public function getProxyFactoryCode(Definition $definition, $id)
    {
        $instantiation = 'return';
        if ($definition->isShared()) {
            $instantiation .= " \$this->services['{$id}'] =";
        }
        if (func_num_args() >= 3) {
            $methodName = func_get_arg(2);
        } else {
            @trigger_error(sprintf('You must use the third argument of %s to define the method to call to construct your service since version 3.1, not using it won\'t be supported in 4.0.', __METHOD__), E_USER_DEPRECATED);
            $methodName = 'get' . Container::camelize($id) . 'Service';
        }
        $proxyClass = $this->getProxyClassName($definition);
        $generatedClass = $this->generateProxyClass($definition);
        $constructorCall = $generatedClass->hasMethod('staticProxyConstructor') ? $proxyClass . '::staticProxyConstructor' : 'new ' . $proxyClass;
        return <<<EOF
        if (\$lazyLoad) {

            {$instantiation} {$constructorCall}(
                function (&\$wrappedInstance, \\ProxyManager\\Proxy\\LazyLoadingInterface \$proxy) {
                    \$wrappedInstance = \$this->{$methodName}(false);

                    \$proxy->setProxyInitializer(null);

                    return true;
                }
            );
        }


EOF;
    }
开发者ID:Ener-Getick,项目名称:symfony,代码行数:35,代码来源:ProxyDumper.php

示例3: getProxyFactoryCode

    /**
     * {@inheritdoc}
     */
    public function getProxyFactoryCode(Definition $definition, $id)
    {
        $instantiation = 'return';
        if ($definition->isShared()) {
            $instantiation .= " \$this->services['{$id}'] =";
            if (defined('Symfony\\Component\\DependencyInjection\\ContainerInterface::SCOPE_CONTAINER') && ContainerInterface::SCOPE_CONTAINER !== ($scope = $definition->getScope(false))) {
                $instantiation .= " \$this->scopedServices['{$scope}']['{$id}'] =";
            }
        }
        $methodName = 'get' . Container::camelize($id) . 'Service';
        $proxyClass = $this->getProxyClassName($definition);
        $generatedClass = $this->generateProxyClass($definition);
        $constructorCall = $generatedClass->hasMethod('staticProxyConstructor') ? $proxyClass . '::staticProxyConstructor' : 'new ' . $proxyClass;
        return <<<EOF
        if (\$lazyLoad) {
            \$container = \$this;

            {$instantiation} {$constructorCall}(
                function (&\$wrappedInstance, \\ProxyManager\\Proxy\\LazyLoadingInterface \$proxy) use (\$container) {
                    \$wrappedInstance = \$container->{$methodName}(false);

                    \$proxy->setProxyInitializer(null);

                    return true;
                }
            );
        }


EOF;
    }
开发者ID:robhaverkort,项目名称:belasting,代码行数:34,代码来源:ProxyDumper.php

示例4: isInlinableDefinition

 protected function isInlinableDefinition(ContainerBuilder $container, $id, Definition $definition)
 {
     if (!$definition->isShared()) {
         return true;
     }
     if ($definition->isPublic()) {
         return false;
     }
     $references = count(array_keys($container->getAliases(), $id, true));
     foreach ($container->getDefinitions() as $cDefinition) {
         if ($references > 1) {
             break;
         }
         if ($this->isReferencedByArgument($id, $cDefinition->getArguments())) {
             $references += 1;
             continue;
         }
         foreach ($cDefinition->getMethodCalls() as $call) {
             if ($this->isReferencedByArgument($id, $call[1])) {
                 $references += 1;
                 continue 2;
             }
         }
     }
     return $references <= 1;
 }
开发者ID:jackbravo,项目名称:symfony-sandbox,代码行数:26,代码来源:InlineServiceDefinitionsPass.php

示例5: getProxyFactoryCode

    /**
     * {@inheritdoc}
     */
    public function getProxyFactoryCode(Definition $definition, $id)
    {
        $instantiation = 'return';
        if ($definition->isShared()) {
            $instantiation .= " \$this->services['{$id}'] =";
        }
        $methodName = 'get' . Container::camelize($id) . 'Service';
        $proxyClass = $this->getProxyClassName($definition);
        $generatedClass = $this->generateProxyClass($definition);
        $constructorCall = $generatedClass->hasMethod('staticProxyConstructor') ? $proxyClass . '::staticProxyConstructor' : 'new ' . $proxyClass;
        return <<<EOF
        if (\$lazyLoad) {

            {$instantiation} {$constructorCall}(
                function (&\$wrappedInstance, \\ProxyManager\\Proxy\\LazyLoadingInterface \$proxy) {
                    \$wrappedInstance = \$this->{$methodName}(false);

                    \$proxy->setProxyInitializer(null);

                    return true;
                }
            );
        }


EOF;
    }
开发者ID:tifabien,项目名称:symfony,代码行数:30,代码来源:ProxyDumper.php

示例6: shareService

 /**
  * Direct copy of the parent function.
  */
 protected function shareService(Definition $definition, $service, $id)
 {
     if ($definition->isShared() && self::SCOPE_PROTOTYPE !== ($scope = $definition->getScope(false))) {
         if (self::SCOPE_CONTAINER !== $scope && !isset($this->scopedServices[$scope])) {
             throw new InactiveScopeException($id, $scope);
         }
         $this->services[$lowerId = strtolower($id)] = $service;
         if (self::SCOPE_CONTAINER !== $scope) {
             $this->scopedServices[$scope][$lowerId] = $service;
         }
     }
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:15,代码来源:ContainerBuilder.php

示例7: isInlinableDefinition

 protected function isInlinableDefinition(ContainerBuilder $container, $id, Definition $definition)
 {
     if (!$definition->isShared()) {
         return true;
     }
     if ($definition->isPublic()) {
         return false;
     }
     if (!$this->graph->hasNode($id)) {
         return true;
     }
     $ids = array();
     foreach ($this->graph->getNode($id)->getInEdges() as $edge) {
         $ids[] = $edge->getSourceNode()->getId();
     }
     return count(array_unique($ids)) <= 1;
 }
开发者ID:notbrain,项目名称:symfony,代码行数:17,代码来源:InlineServiceDefinitionsPass.php

示例8: shareService

 /**
  * Shares a given service in the container.
  *
  * @param Definition $definition
  * @param mixed      $service
  * @param string     $id
  */
 private function shareService(Definition $definition, $service, $id)
 {
     if ($definition->isShared()) {
         $this->services[$lowerId = strtolower($id)] = $service;
     }
 }
开发者ID:hollodk,项目名称:symfony,代码行数:13,代码来源:ContainerBuilder.php

示例9: addService

    /**
     * Adds a service.
     *
     * @param string     $id
     * @param Definition $definition
     *
     * @return string
     */
    private function addService($id, $definition)
    {
        $this->definitionVariables = new \SplObjectStorage();
        $this->referenceVariables = array();
        $this->variableCount = 0;

        $return = array();

        if ($definition->isSynthetic()) {
            $return[] = '@throws RuntimeException always since this service is expected to be injected dynamically';
        } elseif ($class = $definition->getClass()) {
            $return[] = sprintf('@return %s A %s instance.', 0 === strpos($class, '%') ? 'object' : '\\'.ltrim($class, '\\'), ltrim($class, '\\'));
        } elseif ($definition->getFactory()) {
            $factory = $definition->getFactory();
            if (is_string($factory)) {
                $return[] = sprintf('@return object An instance returned by %s().', $factory);
            } elseif (is_array($factory) && (is_string($factory[0]) || $factory[0] instanceof Definition || $factory[0] instanceof Reference)) {
                if (is_string($factory[0]) || $factory[0] instanceof Reference) {
                    $return[] = sprintf('@return object An instance returned by %s::%s().', (string) $factory[0], $factory[1]);
                } elseif ($factory[0] instanceof Definition) {
                    $return[] = sprintf('@return object An instance returned by %s::%s().', $factory[0]->getClass(), $factory[1]);
                }
            }
        }

        $return = implode("\n     * ", $return);

        $doc = '';
        if ($definition->isShared()) {
            $doc .= <<<EOF

     *
     * This service is shared.
     * This method always returns the same instance of the service.
EOF;
        }

        if (!$definition->isPublic()) {
            $doc .= <<<EOF

     *
     * This service is private.
     * If you want to be able to request this service from the container directly,
     * make it public, otherwise you might end up with broken code.
EOF;
        }

        if ($definition->isLazy()) {
            $lazyInitialization = '$lazyLoad = true';
            $lazyInitializationDoc = "\n     * @param bool    \$lazyLoad whether to try lazy-loading the service with a proxy\n     *";
        } else {
            $lazyInitialization = '';
            $lazyInitializationDoc = '';
        }

        // with proxies, for 5.3.3 compatibility, the getter must be public to be accessible to the initializer
        $isProxyCandidate = $this->getProxyDumper()->isProxyCandidate($definition);
        $visibility = $isProxyCandidate ? 'public' : 'protected';
        $code = <<<EOF

    /**
     * Gets the '$id' service.$doc
     *$lazyInitializationDoc
     * $return
     */
    {$visibility} function get{$this->camelize($id)}Service($lazyInitialization)
    {

EOF;

        $code .= $isProxyCandidate ? $this->getProxyDumper()->getProxyFactoryCode($definition, $id) : '';

        if ($definition->isSynthetic()) {
            $code .= sprintf("        throw new RuntimeException('You have requested a synthetic service (\"%s\"). The DIC does not know how to construct this service.');\n    }\n", $id);
        } else {
            $code .=
                $this->addServiceInclude($id, $definition).
                $this->addServiceLocalTempVariables($id, $definition).
                $this->addServiceInlinedDefinitions($id, $definition).
                $this->addServiceInstance($id, $definition).
                $this->addServiceInlinedDefinitionsSetup($id, $definition).
                $this->addServiceMethodCalls($id, $definition).
                $this->addServiceProperties($id, $definition).
                $this->addServiceConfigurator($id, $definition).
                $this->addServiceReturn($id, $definition)
            ;
        }

        $this->definitionVariables = null;
        $this->referenceVariables = null;

        return $code;
//.........这里部分代码省略.........
开发者ID:ninvfeng,项目名称:symfony,代码行数:101,代码来源:PhpDumper.php

示例10: testPrototypeScopedDefinitionAreNotShared

 /**
  * @group legacy
  */
 public function testPrototypeScopedDefinitionAreNotShared()
 {
     $def = new Definition('stdClass');
     $def->setScope(ContainerInterface::SCOPE_PROTOTYPE);
     $this->assertFalse($def->isShared());
     $this->assertEquals(ContainerInterface::SCOPE_PROTOTYPE, $def->getScope());
 }
开发者ID:nuwe1,项目名称:symfony,代码行数:10,代码来源:DefinitionTest.php

示例11: isInlineableDefinition

 /**
  * Checks if the definition is inlineable.
  *
  * @param ContainerBuilder $container
  * @param string           $id
  * @param Definition       $definition
  *
  * @return bool If the definition is inlineable
  */
 private function isInlineableDefinition(ContainerBuilder $container, $id, Definition $definition)
 {
     if (!$definition->isShared() || ContainerInterface::SCOPE_PROTOTYPE === $definition->getScope(false)) {
         return true;
     }
     if ($definition->isPublic() || $definition->isLazy()) {
         return false;
     }
     if (!$this->graph->hasNode($id)) {
         return true;
     }
     if ($this->currentId == $id) {
         return false;
     }
     $ids = array();
     foreach ($this->graph->getNode($id)->getInEdges() as $edge) {
         $ids[] = $edge->getSourceNode()->getId();
     }
     if (count(array_unique($ids)) > 1) {
         return false;
     }
     if (count($ids) > 1 && is_array($factory = $definition->getFactory()) && ($factory[0] instanceof Reference || $factory[0] instanceof Definition)) {
         return false;
     }
     return $container->getDefinition(reset($ids))->getScope(false) === $definition->getScope(false);
 }
开发者ID:nuwe1,项目名称:symfony,代码行数:35,代码来源:InlineServiceDefinitionsPass.php

示例12: createService

 /**
  * Creates a service for a service definition.
  *
  * @param  Definition $definition A service definition instance
  * @param  string     $id         The service identifier
  *
  * @return object              The service described by the service definition
  *
  * @throws \InvalidArgumentException When configure callable is not callable
  */
 protected function createService(Definition $definition, $id)
 {
     if (null !== $definition->getFile()) {
         require_once $this->getParameterBag()->resolveValue($definition->getFile());
     }
     $arguments = $this->resolveServices($this->getParameterBag()->resolveValue($definition->getArguments()));
     if (null !== $definition->getFactoryMethod()) {
         if (null !== $definition->getFactoryService()) {
             $factory = $this->get($this->getParameterBag()->resolveValue($definition->getFactoryService()));
         } else {
             $factory = $this->getParameterBag()->resolveValue($definition->getClass());
         }
         $service = call_user_func_array(array($factory, $definition->getFactoryMethod()), $arguments);
     } else {
         $r = new \ReflectionClass($this->getParameterBag()->resolveValue($definition->getClass()));
         $service = null === $r->getConstructor() ? $r->newInstance() : $r->newInstanceArgs($arguments);
     }
     if ($definition->isShared()) {
         $this->services[$id] = $service;
     }
     foreach ($definition->getMethodCalls() as $call) {
         $services = self::getServiceConditionals($call[1]);
         $ok = true;
         foreach ($services as $s) {
             if (!$this->has($s)) {
                 $ok = false;
                 break;
             }
         }
         if ($ok) {
             call_user_func_array(array($service, $call[0]), $this->resolveServices($this->getParameterBag()->resolveValue($call[1])));
         }
     }
     if ($callable = $definition->getConfigurator()) {
         if (is_array($callable) && is_object($callable[0]) && $callable[0] instanceof Reference) {
             $callable[0] = $this->get((string) $callable[0]);
         } elseif (is_array($callable)) {
             $callable[0] = $this->getParameterBag()->resolveValue($callable[0]);
         }
         if (!is_callable($callable)) {
             throw new \InvalidArgumentException(sprintf('The configure callable for class "%s" is not a callable.', get_class($service)));
         }
         call_user_func($callable, $service);
     }
     return $service;
 }
开发者ID:roydonstharayil,项目名称:sugarbox,代码行数:56,代码来源:ContainerBuilder.php

示例13: addService

    /**
     * Adds a service.
     *
     * @param string     $id
     * @param Definition $definition
     *
     * @return string
     */
    private function addService($id, $definition)
    {
        $this->definitionVariables = new \SplObjectStorage();
        $this->referenceVariables = array();
        $this->variableCount = 0;
        $return = array();
        if ($definition->isSynthetic()) {
            $return[] = '@throws RuntimeException always since this service is expected to be injected dynamically';
        } elseif ($class = $definition->getClass()) {
            $return[] = sprintf('@return %s A %s instance.', 0 === strpos($class, '%') ? 'object' : '\\' . ltrim($class, '\\'), ltrim($class, '\\'));
        } elseif ($definition->getFactory()) {
            $factory = $definition->getFactory();
            if (is_string($factory)) {
                $return[] = sprintf('@return object An instance returned by %s().', $factory);
            } elseif (is_array($factory) && (is_string($factory[0]) || $factory[0] instanceof Definition || $factory[0] instanceof Reference)) {
                if (is_string($factory[0]) || $factory[0] instanceof Reference) {
                    $return[] = sprintf('@return object An instance returned by %s::%s().', (string) $factory[0], $factory[1]);
                } elseif ($factory[0] instanceof Definition) {
                    $return[] = sprintf('@return object An instance returned by %s::%s().', $factory[0]->getClass(), $factory[1]);
                }
            }
        } elseif ($definition->getFactoryClass(false)) {
            $return[] = sprintf('@return object An instance returned by %s::%s().', $definition->getFactoryClass(false), $definition->getFactoryMethod(false));
        } elseif ($definition->getFactoryService(false)) {
            $return[] = sprintf('@return object An instance returned by %s::%s().', $definition->getFactoryService(false), $definition->getFactoryMethod(false));
        }
        $scope = $definition->getScope(false);
        if (!in_array($scope, array(ContainerInterface::SCOPE_CONTAINER, ContainerInterface::SCOPE_PROTOTYPE))) {
            if ($return && 0 === strpos($return[count($return) - 1], '@return')) {
                $return[] = '';
            }
            $return[] = sprintf("@throws InactiveScopeException when the '%s' service is requested while the '%s' scope is not active", $id, $scope);
        }
        if ($definition->isDeprecated()) {
            if ($return && 0 === strpos($return[count($return) - 1], '@return')) {
                $return[] = '';
            }
            $return[] = sprintf('@deprecated %s', $definition->getDeprecationMessage($id));
        }
        $return = str_replace("\n     * \n", "\n     *\n", implode("\n     * ", $return));
        $doc = '';
        if ($definition->isShared() && ContainerInterface::SCOPE_PROTOTYPE !== $scope) {
            $doc .= <<<'EOF'

     *
     * This service is shared.
     * This method always returns the same instance of the service.
EOF;
        }
        if (!$definition->isPublic()) {
            $doc .= <<<'EOF'

     *
     * This service is private.
     * If you want to be able to request this service from the container directly,
     * make it public, otherwise you might end up with broken code.
EOF;
        }
        if ($definition->isAutowired()) {
            $doc = <<<EOF

     *
     * This service is autowired.
EOF;
        }
        if ($definition->isLazy()) {
            $lazyInitialization = '$lazyLoad = true';
            $lazyInitializationDoc = "\n     * @param bool    \$lazyLoad whether to try lazy-loading the service with a proxy\n     *";
        } else {
            $lazyInitialization = '';
            $lazyInitializationDoc = '';
        }
        // with proxies, for 5.3.3 compatibility, the getter must be public to be accessible to the initializer
        $isProxyCandidate = $this->getProxyDumper()->isProxyCandidate($definition);
        $visibility = $isProxyCandidate ? 'public' : 'protected';
        $code = <<<EOF

    /*{$this->docStar}
     * Gets the '{$id}' service.{$doc}
     *{$lazyInitializationDoc}
     * {$return}
     */
    {$visibility} function get{$this->camelize($id)}Service({$lazyInitialization})
    {

EOF;
        $code .= $isProxyCandidate ? $this->getProxyDumper()->getProxyFactoryCode($definition, $id) : '';
        if (!in_array($scope, array(ContainerInterface::SCOPE_CONTAINER, ContainerInterface::SCOPE_PROTOTYPE))) {
            $code .= <<<EOF
        if (!isset(\$this->scopedServices['{$scope}'])) {
            throw new InactiveScopeException('{$id}', '{$scope}');
        }
//.........这里部分代码省略.........
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:101,代码来源:PhpDumper.php

示例14: getServiceDefinition

 /**
  * Gets a service definition as PHP array.
  *
  * @param \Symfony\Component\DependencyInjection\Definition $definition
  *   The definition to process.
  *
  * @return array
  *   The service definition as PHP array.
  *
  * @throws \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
  *   Thrown when the definition is marked as decorated, or with an explicit
  *   scope different from SCOPE_CONTAINER and SCOPE_PROTOTYPE.
  */
 protected function getServiceDefinition(Definition $definition)
 {
     $service = array();
     if ($definition->getClass()) {
         $service['class'] = $definition->getClass();
     }
     if (!$definition->isPublic()) {
         $service['public'] = FALSE;
     }
     if ($definition->getFile()) {
         $service['file'] = $definition->getFile();
     }
     if ($definition->isSynthetic()) {
         $service['synthetic'] = TRUE;
     }
     if ($definition->isLazy()) {
         $service['lazy'] = TRUE;
     }
     if ($definition->getArguments()) {
         $arguments = $definition->getArguments();
         $service['arguments'] = $this->dumpCollection($arguments);
         $service['arguments_count'] = count($arguments);
     } else {
         $service['arguments_count'] = 0;
     }
     if ($definition->getProperties()) {
         $service['properties'] = $this->dumpCollection($definition->getProperties());
     }
     if ($definition->getMethodCalls()) {
         $service['calls'] = $this->dumpMethodCalls($definition->getMethodCalls());
     }
     if (($scope = $definition->getScope()) !== ContainerInterface::SCOPE_CONTAINER) {
         if ($scope === ContainerInterface::SCOPE_PROTOTYPE) {
             // Scope prototype has been replaced with 'shared' => FALSE.
             // This is a Symfony 2.8 forward compatibility fix.
             // Reference: https://github.com/symfony/symfony/blob/2.8/UPGRADE-2.8.md#dependencyinjection
             $service['shared'] = FALSE;
         } else {
             throw new InvalidArgumentException("The 'scope' definition is deprecated in Symfony 3.0 and not supported by Drupal 8.");
         }
     }
     // By default services are shared, so just provide the flag, when needed.
     if ($definition->isShared() === FALSE) {
         $service['shared'] = $definition->isShared();
     }
     if (($decorated = $definition->getDecoratedService()) !== NULL) {
         throw new InvalidArgumentException("The 'decorated' definition is not supported by the Drupal 8 run-time container. The Container Builder should have resolved that during the DecoratorServicePass compiler pass.");
     }
     if ($callable = $definition->getFactory()) {
         $service['factory'] = $this->dumpCallable($callable);
     }
     if ($callable = $definition->getConfigurator()) {
         $service['configurator'] = $this->dumpCallable($callable);
     }
     return $service;
 }
开发者ID:sojo,项目名称:d8_friendsofsilence,代码行数:69,代码来源:OptimizedPhpArrayDumper.php

示例15: addService

    /**
     * Adds a service.
     *
     * @param string     $id
     * @param Definition $definition
     *
     * @return string
     */
    private function addService($id, $definition)
    {
        $code = "    $id:\n";
        if ($class = $definition->getClass()) {
            if ('\\' === substr($class, 0, 1)) {
                $class = substr($class, 1);
            }

            $code .= sprintf("        class: %s\n", $class);
        }

        if (!$definition->isPublic()) {
            $code .= "        public: false\n";
        }

        $tagsCode = '';
        foreach ($definition->getTags() as $name => $tags) {
            foreach ($tags as $attributes) {
                $att = array();
                foreach ($attributes as $key => $value) {
                    $att[] = sprintf('%s: %s', $this->dumper->dump($key), $this->dumper->dump($value));
                }
                $att = $att ? ', '.implode(', ', $att) : '';

                $tagsCode .= sprintf("            - { name: %s%s }\n", $this->dumper->dump($name), $att);
            }
        }
        if ($tagsCode) {
            $code .= "        tags:\n".$tagsCode;
        }

        if ($definition->getFile()) {
            $code .= sprintf("        file: %s\n", $definition->getFile());
        }

        if ($definition->isSynthetic()) {
            $code .= sprintf("        synthetic: true\n");
        }

        if ($definition->isLazy()) {
            $code .= sprintf("        lazy: true\n");
        }

        if ($definition->getArguments()) {
            $code .= sprintf("        arguments: %s\n", $this->dumper->dump($this->dumpValue($definition->getArguments()), 0));
        }

        if ($definition->getProperties()) {
            $code .= sprintf("        properties: %s\n", $this->dumper->dump($this->dumpValue($definition->getProperties()), 0));
        }

        if ($definition->getMethodCalls()) {
            $code .= sprintf("        calls:\n%s\n", $this->dumper->dump($this->dumpValue($definition->getMethodCalls()), 1, 12));
        }

        if (!$definition->isShared()) {
            $code .= "        shared: false\n";
        }

        if (null !== $decorated = $definition->getDecoratedService()) {
            list($decorated, $renamedId, $priority) = $decorated;
            $code .= sprintf("        decorates: %s\n", $decorated);
            if (null !== $renamedId) {
                $code .= sprintf("        decoration_inner_name: %s\n", $renamedId);
            }
            if (0 !== $priority) {
                $code .= sprintf("        decoration_priority: %s\n", $priority);
            }
        }

        if ($callable = $definition->getFactory()) {
            $code .= sprintf("        factory: %s\n", $this->dumper->dump($this->dumpCallable($callable), 0));
        }

        if ($callable = $definition->getConfigurator()) {
            $code .= sprintf("        configurator: %s\n", $this->dumper->dump($this->dumpCallable($callable), 0));
        }

        return $code;
    }
开发者ID:ninvfeng,项目名称:symfony,代码行数:88,代码来源:YamlDumper.php


注:本文中的Symfony\Component\DependencyInjection\Definition::isShared方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。