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


PHP Definition::getFactoryService方法代码示例

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


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

示例1: processDefinition

 /**
  * @param Definition $definition
  */
 protected function processDefinition(Definition $definition)
 {
     if ($definition->isSynthetic()) {
         return;
     }
     if ($definition->getFactoryService() || $definition->getFactoryClass()) {
         return;
     }
     if ($file = $definition->getFile()) {
         require_once $file;
     }
     if (!class_exists($definition->getClass())) {
         return;
     }
     $class = new \ReflectionClass($definition->getClass());
     if (!$class->implementsInterface(static::INTERFACE_CLASS)) {
         return;
     }
     $metadata = $this->getMetadataFactory()->getMetadataForClass($definition->getClass());
     if (!$metadata instanceof ClassMetadata) {
         return;
     }
     $namespace = $metadata->getNamespace() ?: static::ROOT_NAMESPACE;
     $serviceName = static::PROVIDER_PREFIX . substr(sha1($namespace), 0, 10);
     if (!$this->container->hasDefinition($serviceName)) {
         $cacher = new Definition('Werkint\\Bundle\\CacheBundle\\Service\\CacheProvider', [$this->container->getParameter('kernel.cache_dir') . '/werkint_cache']);
         $cacher->setPublic(true);
         $cacher->addMethodCall('setNamespace', [$namespace]);
         $this->container->setDefinition($serviceName, $cacher);
     }
     $definition->addMethodCall('setCacheProvider', [new Reference($serviceName)]);
 }
开发者ID:Werkint,项目名称:CacheBundle,代码行数:35,代码来源:CacheProviderPass.php

示例2: testSetGetFactoryService

 public function testSetGetFactoryService()
 {
     $def = new Definition('stdClass');
     $this->assertNull($def->getFactoryService());
     $this->assertSame($def, $def->setFactoryService('foo.bar'), '->setFactoryService() implements a fluent interface.');
     $this->assertEquals('foo.bar', $def->getFactoryService(), '->getFactoryService() returns current service to construct this service.');
 }
开发者ID:Herriniaina,项目名称:iVarotra,代码行数:7,代码来源:DefinitionTest.php

示例3: autowireFactory

 /**
  * @param Definition $definition
  * @param string[] $classes
  * @param string $id
  * @param ContainerBuilder $container
  */
 private function autowireFactory(Definition $definition, array $classes, $id, ContainerBuilder $container)
 {
     if ($definition->getFactoryClass()) {
         $factoryClass = $definition->getFactoryClass();
     } else {
         $factoryName = $definition->getFactoryService();
         $factoryClass = $container->getDefinition($factoryName)->getClass();
     }
     if ($factoryClass) {
         $parameterBag = $container->getParameterBag();
         $method = new ReflectionMethod($parameterBag->resolveValue($factoryClass), $definition->getFactoryMethod());
         $autowiredArgs = $this->autowireMethod($method, $definition->getArguments(), $classes, $id, $container);
         $definition->setArguments($autowiredArgs);
     }
 }
开发者ID:janmarek,项目名称:autowiring-bundle,代码行数:21,代码来源:AutowiringPass.php

示例4: validateFactoryService

 private function validateFactoryService(Definition $definition)
 {
     $factoryServiceId = $definition->getFactoryService();
     if (!$factoryServiceId) {
         return;
     }
     $factoryMethod = $definition->getFactoryMethod();
     if (!$factoryMethod) {
         throw new MissingFactoryMethodException();
     }
     if (!$this->containerBuilder->has($factoryServiceId)) {
         throw new ServiceNotFoundException($factoryServiceId);
     }
     $factoryServiceDefinition = $this->containerBuilder->findDefinition($factoryServiceId);
     $factoryClass = $factoryServiceDefinition->getClass();
     $this->validateFactoryClassAndMethod($factoryClass, $factoryMethod);
 }
开发者ID:seclu,项目名称:symfony-service-definition-validator,代码行数:17,代码来源:ServiceDefinitionValidator.php

示例5: describeContainerDefinition

 /**
  * {@inheritdoc}
  */
 protected function describeContainerDefinition(Definition $definition, array $options = array())
 {
     $description = isset($options['id']) ? array($this->formatSection('container', sprintf('Information for service <info>%s</info>', $options['id']))) : array();
     $description[] = sprintf('<comment>Service Id</comment>       %s', isset($options['id']) ? $options['id'] : '-');
     $description[] = sprintf('<comment>Class</comment>            %s', $definition->getClass() ?: "-");
     $tags = $definition->getTags();
     if (count($tags)) {
         $description[] = '<comment>Tags</comment>';
         foreach ($tags as $tagName => $tagData) {
             foreach ($tagData as $parameters) {
                 $description[] = sprintf('    - %-30s (%s)', $tagName, implode(', ', array_map(function ($key, $value) {
                     return sprintf('<info>%s</info>: %s', $key, $value);
                 }, array_keys($parameters), array_values($parameters))));
             }
         }
     } else {
         $description[] = '<comment>Tags</comment>             -';
     }
     $description[] = sprintf('<comment>Scope</comment>            %s', $definition->getScope());
     $description[] = sprintf('<comment>Public</comment>           %s', $definition->isPublic() ? 'yes' : 'no');
     $description[] = sprintf('<comment>Synthetic</comment>        %s', $definition->isSynthetic() ? 'yes' : 'no');
     $description[] = sprintf('<comment>Lazy</comment>             %s', $definition->isLazy() ? 'yes' : 'no');
     $description[] = sprintf('<comment>Synchronized</comment>     %s', $definition->isSynchronized() ? 'yes' : 'no');
     $description[] = sprintf('<comment>Abstract</comment>         %s', $definition->isAbstract() ? 'yes' : 'no');
     if ($definition->getFile()) {
         $description[] = sprintf('<comment>Required File</comment>    %s', $definition->getFile() ? $definition->getFile() : '-');
     }
     if ($definition->getFactoryClass()) {
         $description[] = sprintf('<comment>Factory Class</comment>    %s', $definition->getFactoryClass());
     }
     if ($definition->getFactoryService()) {
         $description[] = sprintf('<comment>Factory Service</comment>  %s', $definition->getFactoryService());
     }
     if ($definition->getFactoryMethod()) {
         $description[] = sprintf('<comment>Factory Method</comment>   %s', $definition->getFactoryMethod());
     }
     if ($factory = $definition->getFactory()) {
         if (is_array($factory)) {
             if ($factory[0] instanceof Reference) {
                 $description[] = sprintf('<comment>Factory Service</comment>  %s', $factory[0]);
             } elseif ($factory[0] instanceof Definition) {
                 throw new \InvalidArgumentException('Factory is not describable.');
             } else {
                 $description[] = sprintf('<comment>Factory Class</comment>    %s', $factory[0]);
             }
             $description[] = sprintf('<comment>Factory Method</comment>   %s', $factory[1]);
         } else {
             $description[] = sprintf('<comment>Factory Function</comment>    %s', $factory);
         }
     }
     $this->writeText(implode("\n", $description) . "\n", $options);
 }
开发者ID:Chaireeee,项目名称:chaireeee,代码行数:55,代码来源:TextDescriptor.php

示例6: addNewInstance

 private function addNewInstance($id, Definition $definition, $return, $instantiation)
 {
     $class = $this->dumpValue($definition->getClass());
     $arguments = array();
     foreach ($definition->getArguments() as $value) {
         $arguments[] = $this->dumpValue($value);
     }
     if (null !== $definition->getFactory()) {
         $callable = $definition->getFactory();
         if (is_array($callable)) {
             if (!preg_match('/^[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*$/', $callable[1])) {
                 throw new RuntimeException(sprintf('Cannot dump definition because of invalid factory method (%s)', $callable[1] ?: 'n/a'));
             }
             if ($callable[0] instanceof Reference || $callable[0] instanceof Definition && $this->definitionVariables->contains($callable[0])) {
                 return sprintf("        {$return}{$instantiation}%s->%s(%s);\n", $this->dumpValue($callable[0]), $callable[1], $arguments ? implode(', ', $arguments) : '');
             }
             $class = $this->dumpValue($callable[0]);
             // If the class is a string we can optimize call_user_func away
             if (strpos($class, "'") === 0) {
                 return sprintf("        {$return}{$instantiation}%s::%s(%s);\n", $this->dumpLiteralClass($class), $callable[1], $arguments ? implode(', ', $arguments) : '');
             }
             return sprintf("        {$return}{$instantiation}call_user_func(array(%s, '%s')%s);\n", $this->dumpValue($callable[0]), $callable[1], $arguments ? ', ' . implode(', ', $arguments) : '');
         }
         return sprintf("        {$return}{$instantiation}\\%s(%s);\n", $callable, $arguments ? implode(', ', $arguments) : '');
     } elseif (null !== $definition->getFactoryMethod(false)) {
         if (null !== $definition->getFactoryClass(false)) {
             $class = $this->dumpValue($definition->getFactoryClass(false));
             // If the class is a string we can optimize call_user_func away
             if (strpos($class, "'") === 0) {
                 return sprintf("        {$return}{$instantiation}%s::%s(%s);\n", $this->dumpLiteralClass($class), $definition->getFactoryMethod(false), $arguments ? implode(', ', $arguments) : '');
             }
             return sprintf("        {$return}{$instantiation}call_user_func(array(%s, '%s')%s);\n", $this->dumpValue($definition->getFactoryClass(false)), $definition->getFactoryMethod(false), $arguments ? ', ' . implode(', ', $arguments) : '');
         }
         if (null !== $definition->getFactoryService(false)) {
             return sprintf("        {$return}{$instantiation}%s->%s(%s);\n", $this->getServiceCall($definition->getFactoryService(false)), $definition->getFactoryMethod(false), implode(', ', $arguments));
         }
         throw new RuntimeException(sprintf('Factory method requires a factory service or factory class in service definition for %s', $id));
     }
     if (false !== strpos($class, '$')) {
         return sprintf("        \$class = %s;\n\n        {$return}{$instantiation}new \$class(%s);\n", $class, implode(', ', $arguments));
     }
     return sprintf("        {$return}{$instantiation}new %s(%s);\n", $this->dumpLiteralClass($class), implode(', ', $arguments));
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:43,代码来源:PhpDumper.php

示例7: 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

示例8: processDefinition

 /**
  * @param array<PointcutInterface> $pointcuts
  * @param array<string,string> $interceptors
  */
 private function processDefinition(Definition $definition, $pointcuts, &$interceptors)
 {
     if ($definition->isSynthetic()) {
         return;
     }
     if ($definition->getFactoryService() || $definition->getFactoryClass()) {
         return;
     }
     if ($originalFilename = $definition->getFile()) {
         require_once $originalFilename;
     }
     if (!class_exists($definition->getClass())) {
         return;
     }
     $class = new \ReflectionClass($definition->getClass());
     // check if class is matched
     $matchingPointcuts = array();
     foreach ($pointcuts as $interceptor => $pointcut) {
         if ($pointcut->matchesClass($class)) {
             $matchingPointcuts[$interceptor] = $pointcut;
         }
     }
     if (empty($matchingPointcuts)) {
         return;
     }
     $this->addResources($class, $this->container);
     if ($class->isFinal()) {
         return;
     }
     $classAdvices = array();
     foreach (ReflectionUtils::getOverrideableMethods($class) as $method) {
         if ('__construct' === $method->name) {
             continue;
         }
         $advices = array();
         foreach ($matchingPointcuts as $interceptor => $pointcut) {
             if ($pointcut->matchesMethod($method)) {
                 $advices[] = $interceptor;
             }
         }
         if (empty($advices)) {
             continue;
         }
         $classAdvices[$method->name] = $advices;
     }
     if (empty($classAdvices)) {
         return;
     }
     $interceptors[ClassUtils::getUserClass($class->name)] = $classAdvices;
     $proxyFilename = $this->cacheDir . '/' . str_replace('\\', '-', $class->name) . '.php';
     $generator = new InterceptionGenerator();
     $generator->setFilter(function (\ReflectionMethod $method) use($classAdvices) {
         return isset($classAdvices[$method->name]);
     });
     if ($originalFilename) {
         $relativeOriginalFilename = $this->relativizePath($proxyFilename, $originalFilename);
         if ($relativeOriginalFilename[0] === '.') {
             $generator->setRequiredFile(new RelativePath($relativeOriginalFilename));
         } else {
             $generator->setRequiredFile($relativeOriginalFilename);
         }
     }
     $enhancer = new Enhancer($class, array(), array($generator));
     $enhancer->setNamingStrategy(new DefaultNamingStrategy('EnhancedProxy' . substr(md5($this->container->getParameter('jms_aop.cache_dir')), 0, 8)));
     $enhancer->writeClass($proxyFilename);
     $definition->setFile($proxyFilename);
     $definition->setClass($enhancer->getClassName($class));
     $definition->addMethodCall('__CGInterception__setLoader', array(new Reference('jms_aop.interceptor_loader')));
 }
开发者ID:rostandnj,项目名称:ok,代码行数:73,代码来源:PointcutMatchingPass.php

示例9: describeContainerDefinition

 /**
  * {@inheritdoc}
  */
 protected function describeContainerDefinition(Definition $definition, array $options = array())
 {
     $output = '- Class: `' . $definition->getClass() . '`' . "\n" . '- Scope: `' . $definition->getScope() . '`' . "\n" . '- Public: ' . ($definition->isPublic() ? 'yes' : 'no') . "\n" . '- Synthetic: ' . ($definition->isSynthetic() ? 'yes' : 'no') . "\n" . '- Lazy: ' . ($definition->isLazy() ? 'yes' : 'no') . "\n" . '- Synchronized: ' . ($definition->isSynchronized() ? 'yes' : 'no') . "\n" . '- Abstract: ' . ($definition->isAbstract() ? 'yes' : 'no');
     if ($definition->getFile()) {
         $output .= "\n" . '- File: `' . $definition->getFile() . '`';
     }
     if ($definition->getFactoryClass()) {
         $output .= "\n" . '- Factory Class: `' . $definition->getFactoryClass() . '`';
     }
     if ($definition->getFactoryService()) {
         $output .= "\n" . '- Factory Service: `' . $definition->getFactoryService() . '`';
     }
     if ($definition->getFactoryMethod()) {
         $output .= "\n" . '- Factory Method: `' . $definition->getFactoryMethod() . '`';
     }
     if ($factory = $definition->getFactory()) {
         if (is_array($factory)) {
             if ($factory[0] instanceof Reference) {
                 $output .= "\n" . '- Factory Service: `' . $factory[0] . '`';
             } elseif ($factory[0] instanceof Definition) {
                 throw new \InvalidArgumentException('Factory is not describable.');
             } else {
                 $output .= "\n" . '- Factory Class: `' . $factory[0] . '`';
             }
             $output .= "\n" . '- Factory Method: `' . $factory[1] . '`';
         } else {
             $output .= "\n" . '- Factory Function: `' . $factory . '`';
         }
     }
     if (!(isset($options['omit_tags']) && $options['omit_tags'])) {
         foreach ($definition->getTags() as $tagName => $tagData) {
             foreach ($tagData as $parameters) {
                 $output .= "\n" . '- Tag: `' . $tagName . '`';
                 foreach ($parameters as $name => $value) {
                     $output .= "\n" . '    - ' . ucfirst($name) . ': ' . $value;
                 }
             }
         }
     }
     $this->write(isset($options['id']) ? sprintf("%s\n%s\n\n%s\n", $options['id'], str_repeat('~', strlen($options['id'])), $output) : $output);
 }
开发者ID:tonydub,项目名称:jarvis,代码行数:44,代码来源:MarkdownDescriptor.php

示例10: addService

 /**
  * Adds a service
  *
  * @param string     $id
  * @param Definition $definition
  *
  * @return string
  */
 private function addService($id, $definition)
 {
     $code = "    {$id}:\n";
     if ($definition->getClass()) {
         $code .= sprintf("        class: %s\n", $definition->getClass());
     }
     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->isSynchronized()) {
         $code .= sprintf("        synchronized: true\n");
     }
     if ($definition->getFactoryClass()) {
         $code .= sprintf("        factory_class: %s\n", $definition->getFactoryClass());
     }
     if ($definition->isLazy()) {
         $code .= sprintf("        lazy: true\n");
     }
     if ($definition->getFactoryMethod()) {
         $code .= sprintf("        factory_method: %s\n", $definition->getFactoryMethod());
     }
     if ($definition->getFactoryService()) {
         $code .= sprintf("        factory_service: %s\n", $definition->getFactoryService());
     }
     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 (ContainerInterface::SCOPE_CONTAINER !== ($scope = $definition->getScope())) {
         $code .= sprintf("        scope: %s\n", $scope);
     }
     if ($callable = $definition->getConfigurator()) {
         if (is_array($callable)) {
             if ($callable[0] instanceof Reference) {
                 $callable = array($this->getServiceCall((string) $callable[0], $callable[0]), $callable[1]);
             } else {
                 $callable = array($callable[0], $callable[1]);
             }
         }
         $code .= sprintf("        configurator: %s\n", $this->dumper->dump($callable, 0));
     }
     return $code;
 }
开发者ID:TuxCoffeeCorner,项目名称:tcc,代码行数:76,代码来源:YamlDumper.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 (ContainerInterface::SCOPE_PROTOTYPE === $definition->getScope()) {
         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 && $definition->getFactoryService()) {
         return false;
     }
     return $container->getDefinition(reset($ids))->getScope() === $definition->getScope();
 }
开发者ID:brennantom,项目名称:hackazon,代码行数:35,代码来源:InlineServiceDefinitionsPass.php

示例12: getContainerDefinitionDocument

 /**
  * @param Definition  $definition
  * @param string|null $id
  * @param bool        $omitTags
  *
  * @return \DOMDocument
  */
 private function getContainerDefinitionDocument(Definition $definition, $id = null, $omitTags = false)
 {
     $dom = new \DOMDocument('1.0', 'UTF-8');
     $dom->appendChild($serviceXML = $dom->createElement('definition'));
     if ($id) {
         $serviceXML->setAttribute('id', $id);
     }
     $serviceXML->setAttribute('class', $definition->getClass());
     if ($definition->getFactoryClass()) {
         $serviceXML->setAttribute('factory-class', $definition->getFactoryClass());
     }
     if ($definition->getFactoryService()) {
         $serviceXML->setAttribute('factory-service', $definition->getFactoryService());
     }
     if ($definition->getFactoryMethod()) {
         $serviceXML->setAttribute('factory-method', $definition->getFactoryMethod());
     }
     $serviceXML->setAttribute('scope', $definition->getScope());
     $serviceXML->setAttribute('public', $definition->isPublic() ? 'true' : 'false');
     $serviceXML->setAttribute('synthetic', $definition->isSynthetic() ? 'true' : 'false');
     $serviceXML->setAttribute('lazy', $definition->isLazy() ? 'true' : 'false');
     $serviceXML->setAttribute('synchronized', $definition->isSynchronized() ? 'true' : 'false');
     $serviceXML->setAttribute('abstract', $definition->isAbstract() ? 'true' : 'false');
     $serviceXML->setAttribute('file', $definition->getFile());
     if (!$omitTags) {
         $tags = $definition->getTags();
         if (count($tags) > 0) {
             $serviceXML->appendChild($tagsXML = $dom->createElement('tags'));
             foreach ($tags as $tagName => $tagData) {
                 foreach ($tagData as $parameters) {
                     $tagsXML->appendChild($tagXML = $dom->createElement('tag'));
                     $tagXML->setAttribute('name', $tagName);
                     foreach ($parameters as $name => $value) {
                         $tagXML->appendChild($parameterXML = $dom->createElement('parameter'));
                         $parameterXML->setAttribute('name', $name);
                         $parameterXML->appendChild(new \DOMText($this->formatParameter($value)));
                     }
                 }
             }
         }
     }
     return $dom;
 }
开发者ID:brennantom,项目名称:hackazon,代码行数:50,代码来源:XmlDescriptor.php

示例13: 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
  */
 private 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->getFactoryClass()) {
             $factory = $this->getParameterBag()->resolveValue($definition->getFactoryClass());
         } elseif (null !== $definition->getFactoryService()) {
             $factory = $this->get($this->getParameterBag()->resolveValue($definition->getFactoryService()));
         } else {
             throw new \RuntimeException('Cannot create service from factory method without a factory service or factory class.');
         }
         $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 (self::SCOPE_PROTOTYPE !== ($scope = $definition->getScope())) {
         if (self::SCOPE_CONTAINER !== $scope && !isset($this->scopedServices[$scope])) {
             throw new \RuntimeException('You tried to create a service of an inactive scope.');
         }
         $this->services[$lowerId = strtolower($id)] = $service;
         if (self::SCOPE_CONTAINER !== $scope) {
             $this->scopedServices[$scope][$lowerId] = $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])));
         }
     }
     $properties = $this->resolveServices($this->getParameterBag()->resolveValue($definition->getProperties()));
     foreach ($properties as $name => $value) {
         $service->{$name} = $value;
     }
     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:hykz,项目名称:Depot,代码行数:68,代码来源:ContainerBuilder.php

示例14: describeContainerDefinition

 /**
  * {@inheritdoc}
  */
 protected function describeContainerDefinition(Definition $definition, array $options = array())
 {
     $output = '- Class: `' . $definition->getClass() . '`' . "\n" . '- Scope: `' . $definition->getScope() . '`' . "\n" . '- Public: ' . ($definition->isPublic() ? 'yes' : 'no') . "\n" . '- Synthetic: ' . ($definition->isSynthetic() ? 'yes' : 'no') . "\n" . '- Lazy: ' . ($definition->isLazy() ? 'yes' : 'no') . "\n" . '- Synchronized: ' . ($definition->isSynchronized() ? 'yes' : 'no') . "\n" . '- Abstract: ' . ($definition->isAbstract() ? 'yes' : 'no');
     if ($definition->getFile()) {
         $output .= "\n" . '- File: `' . $definition->getFile() . '`';
     }
     if ($definition->getFactoryClass()) {
         $output .= "\n" . '- Factory Class: `' . $definition->getFactoryClass() . '`';
     }
     if ($definition->getFactoryService()) {
         $output .= "\n" . '- Factory Service: `' . $definition->getFactoryService() . '`';
     }
     if ($definition->getFactoryMethod()) {
         $output .= "\n" . '- Factory Method: `' . $definition->getFactoryMethod() . '`';
     }
     if (!(isset($options['omit_tags']) && $options['omit_tags'])) {
         foreach ($definition->getTags() as $tagName => $tagData) {
             foreach ($tagData as $parameters) {
                 $output .= "\n" . '- Tag: `' . $tagName . '`';
                 foreach ($parameters as $name => $value) {
                     $output .= "\n" . '    - ' . ucfirst($name) . ': ' . $value;
                 }
             }
         }
     }
     $this->write(isset($options['id']) ? sprintf("%s\n%s\n\n%s\n", $options['id'], str_repeat('~', strlen($options['id'])), $output) : $output);
 }
开发者ID:ygeneration666,项目名称:ma,代码行数:30,代码来源:MarkdownDescriptor.php

示例15: getContainerDefinitionData

 /**
  * @param Definition $definition
  * @param bool       $omitTags
  *
  * @return array
  */
 private function getContainerDefinitionData(Definition $definition, $omitTags = false)
 {
     $data = array('class' => (string) $definition->getClass(), 'scope' => $definition->getScope(), 'public' => $definition->isPublic(), 'synthetic' => $definition->isSynthetic(), 'lazy' => $definition->isLazy(), 'synchronized' => $definition->isSynchronized(), 'abstract' => $definition->isAbstract(), 'file' => $definition->getFile());
     if ($definition->getFactoryClass()) {
         $data['factory_class'] = $definition->getFactoryClass();
     }
     if ($definition->getFactoryService()) {
         $data['factory_service'] = $definition->getFactoryService();
     }
     if ($definition->getFactoryMethod()) {
         $data['factory_method'] = $definition->getFactoryMethod();
     }
     if ($factory = $definition->getFactory()) {
         if (is_array($factory)) {
             if ($factory[0] instanceof Reference) {
                 $data['factory_service'] = (string) $factory[0];
             } elseif ($factory[0] instanceof Definition) {
                 throw new \InvalidArgumentException('Factory is not describable.');
             } else {
                 $data['factory_class'] = $factory[0];
             }
             $data['factory_method'] = $factory[1];
         } else {
             $data['factory_function'] = $factory;
         }
     }
     if (!$omitTags) {
         $data['tags'] = array();
         if (count($definition->getTags())) {
             foreach ($definition->getTags() as $tagName => $tagData) {
                 foreach ($tagData as $parameters) {
                     $data['tags'][] = array('name' => $tagName, 'parameters' => $parameters);
                 }
             }
         }
     }
     return $data;
 }
开发者ID:tonydub,项目名称:jarvis,代码行数:44,代码来源:JsonDescriptor.php


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