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


PHP Definition::getClass方法代码示例

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


在下文中一共展示了Definition::getClass方法的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: 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());
     }
     $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->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:nfabre,项目名称:symfony,代码行数:67,代码来源:YamlDumper.php

示例3: 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->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 (ContainerInterface::SCOPE_CONTAINER !== ($scope = $definition->getScope())) {
         $code .= sprintf("        scope: %s\n", $scope);
     }
     if (null !== ($decorated = $definition->getDecoratedService())) {
         list($decorated, $renamedId) = $decorated;
         $code .= sprintf("        decorates: %s\n", $decorated);
         if (null !== $renamedId) {
             $code .= sprintf("        decoration_inner_name: %s\n", $renamedId);
         }
     }
     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:rgeraads,项目名称:symfony,代码行数:67,代码来源:YamlDumper.php

示例4: assertProvider

 private function assertProvider(ContainerBuilder $container, Definition $definition)
 {
     $class = $container->getParameterBag()->resolveValue($definition->getClass());
     $refClass = new \ReflectionClass($class);
     if (!$refClass->implementsInterface('Hateoas\\Configuration\\Provider\\Resolver\\RelationProviderResolverInterface')) {
         throw new InvalidArgumentException(sprintf('Relation provider "%s" does not implement the ReleationProviderResolver interface', $definition->getClass()));
     }
 }
开发者ID:ruudk,项目名称:BazingaHateoasBundle,代码行数:8,代码来源:RelationProviderPass.php

示例5: validate

 public function validate(Definition $definition) : bool
 {
     if (!$definition->isPublic() || $definition->isAbstract()) {
         return false;
     }
     if (null === $definition->getClass() || !class_exists($definition->getClass())) {
         return false;
     }
     return true;
 }
开发者ID:Symplify,项目名称:DefaultAutowire,代码行数:10,代码来源:DefinitionValidator.php

示例6: getProxyCode

 /**
  * {@inheritdoc}
  */
 public function getProxyCode(Definition $definition)
 {
     // Maybe the same class is used in different services, which are both marked
     // as lazy (just think about 2 database connections).
     // In those cases we should not generate proxy code the second time.
     if (!isset($this->buildClasses[$definition->getClass()])) {
         $this->buildClasses[$definition->getClass()] = TRUE;
         return $this->builder->build($definition->getClass());
     } else {
         return '';
     }
 }
开发者ID:EarthTeam,项目名称:earthteam.net,代码行数:15,代码来源:ProxyDumper.php

示例7: testConstructor

 /**
  * @covers Symfony\Component\DependencyInjection\Definition::__construct
  */
 public function testConstructor()
 {
     $def = new Definition('stdClass');
     $this->assertEquals('stdClass', $def->getClass(), '__construct() takes the class name as its first argument');
     $def = new Definition('stdClass', array('foo'));
     $this->assertEquals(array('foo'), $def->getArguments(), '__construct() takes an optional array of arguments as its second argument');
 }
开发者ID:nuwe1,项目名称:symfony,代码行数:10,代码来源:DefinitionTest.php

示例8: watchServiceClassForChanges

 private function watchServiceClassForChanges(Definition $definition, ContainerBuilder $containerBuilder)
 {
     $classReflection = new ReflectionClass($definition->getClass());
     do {
         $containerBuilder->addResource(new FileResource($classReflection->getFileName()));
     } while ($classReflection = $classReflection->getParentClass());
 }
开发者ID:jaimz22,项目名称:autowiring-bundle,代码行数:7,代码来源:AutowiringCompilerPass.php

示例9: assertDefinition

 /**
  * @param Definition $definition
  * @param string     $class
  * @param string     $repository
  */
 private function assertDefinition(Definition $definition, $class, $repository)
 {
     $this->assertSame($definition->getClass(), $repository);
     $factory = $definition->getFactory();
     $this->assertSame($factory[1], "getRepository");
     $this->assertSame($definition->getArgument(0), $class);
 }
开发者ID:itkg-canne,项目名称:open-orchestra-media-bundle,代码行数:12,代码来源:OpenOrchestraMediaModelExtensionTest.php

示例10: guardAgainstInvalidClass

 /**
  * @param Definition $emitterService
  * @param string     $expectedInterface
  *
  * @throws LogicException
  */
 private function guardAgainstInvalidClass(Definition $emitterService, $expectedInterface)
 {
     $definedClass = $emitterService->getClass();
     $reflection = new ReflectionClass($definedClass);
     if ($reflection->implementsInterface($expectedInterface) === false) {
         throw new LogicException(sprintf('Invalid class type registered, expected %s, got %s.', $expectedInterface, $definedClass));
     }
 }
开发者ID:frankdejonge,项目名称:league-event-bundle,代码行数:14,代码来源:RegisterEmittersPass.php

示例11: addDefinitionArguments

 /**
  * @param Definition $definition
  * @param stdClass $dependables
  */
 private function addDefinitionArguments(Definition $definition, stdClass $dependables)
 {
     $class = $definition->getClass();
     $dependables->references[$class] = array();
     for ($arg = 0; $arg < count($definition->getArguments()); $arg++) {
         $dependables->references[$class][$arg] = $definition->getArgument($arg);
     }
 }
开发者ID:qrz-io,项目名称:magento-symfony-container,代码行数:12,代码来源:InjectableCompilerPass.php

示例12: assertClassImplementInterface

 /**
  * @param ContainerBuilder $container
  * @param Definition       $definition
  * @param string           $id
  */
 private function assertClassImplementInterface(ContainerBuilder $container, Definition $definition, $id)
 {
     $class = $this->resolveClassName($container, $definition->getClass());
     $refClass = new ReflectionClass($class);
     if (!$refClass->implementsInterface($this->interfaceToImplement)) {
         throw new InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $this->interfaceToImplement));
     }
 }
开发者ID:php-ddd,项目名称:php-ddd-bundle,代码行数:13,代码来源:AbstractLocatorCompilerPass.php

示例13: instantiateProxy

 /**
  * {@inheritdoc}
  */
 public function instantiateProxy(ContainerInterface $container, Definition $definition, $id, $realInstantiator)
 {
     return $this->factory->createProxy($definition->getClass(), function (&$wrappedInstance, LazyLoadingInterface $proxy) use($realInstantiator) {
         $wrappedInstance = call_user_func($realInstantiator);
         $proxy->setProxyInitializer(null);
         return true;
     });
 }
开发者ID:NivalM,项目名称:VacantesJannaMotors,代码行数:11,代码来源:RuntimeInstantiator.php

示例14: injectContainer

 /**
  * @param Definition $definition
  * @param Reference $container
  */
 private function injectContainer(Definition $definition, Reference $container)
 {
     $class = $definition->getClass();
     if (empty($class) || !is_subclass_of($class, ContainerAwareInterface::class)) {
         return;
     }
     $definition->addMethodCall('setContainer', [$container]);
 }
开发者ID:GMaissa,项目名称:di-builder,代码行数:12,代码来源:ContainerAware.php

示例15: isDefinitionATemplate

 /**
  * Is the definition an interface template?
  *
  * @access private
  * @return boolean
  */
 private function isDefinitionATemplate(Definition $definition)
 {
     try {
         $reflect = new \ReflectionClass($definition->getClass());
     } catch (\ReflectionException $e) {
         return false;
     }
     return $reflect->isInterface();
 }
开发者ID:darsyn,项目名称:service-templates-bundle,代码行数:15,代码来源:ServiceTemplatePass.php


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