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


PHP ContainerBuilder::getServiceName方法代码示例

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


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

示例1: formatStatement

 /**
  * Formats PHP code for class instantiating, function calling or property setting in PHP.
  * @return string
  */
 private function formatStatement(Statement $statement)
 {
     $entity = $statement->getEntity();
     $arguments = $statement->arguments;
     if (is_string($entity) && Strings::contains($entity, '?')) {
         // PHP literal
         return $this->formatPhp($entity, $arguments);
     } elseif ($service = $this->builder->getServiceName($entity)) {
         // factory calling
         return $this->formatPhp('$this->?(?*)', [Container::getMethodName($service), $arguments]);
     } elseif ($entity === 'not') {
         // operator
         return $this->formatPhp('!?', [$arguments[0]]);
     } elseif (is_string($entity)) {
         // class name
         return $this->formatPhp("new {$entity}" . ($arguments ? '(?*)' : ''), [$arguments]);
     } elseif ($entity[0] === '') {
         // globalFunc
         return $this->formatPhp("{$entity['1']}(?*)", [$arguments]);
     } elseif ($entity[0] instanceof Statement) {
         $inner = $this->formatPhp('?', [$entity[0]]);
         if (substr($inner, 0, 4) === 'new ') {
             $inner = "({$inner})";
         }
         return $this->formatPhp("{$inner}->?(?*)", [$entity[1], $arguments]);
     } elseif ($entity[1][0] === '$') {
         // property getter, setter or appender
         $name = substr($entity[1], 1);
         if ($append = substr($name, -2) === '[]') {
             $name = substr($name, 0, -2);
         }
         if ($this->builder->getServiceName($entity[0])) {
             $prop = $this->formatPhp('?->?', [$entity[0], $name]);
         } else {
             $prop = $this->formatPhp($entity[0] . '::$?', [$name]);
         }
         return $arguments ? $this->formatPhp($prop . ($append ? '[]' : '') . ' = ?', [$arguments[0]]) : $prop;
     } elseif ($service = $this->builder->getServiceName($entity[0])) {
         // service method
         return $this->formatPhp('?->?(?*)', [$entity[0], $entity[1], $arguments]);
     } else {
         // static method
         return $this->formatPhp("{$entity['0']}::{$entity['1']}(?*)", [$arguments]);
     }
 }
开发者ID:nette,项目名称:di,代码行数:49,代码来源:PhpGenerator.php

示例2: validateSubscribers

 /**
  * @param \Nette\DI\ContainerBuilder $builder
  * @param \Nette\DI\ServiceDefinition $manager
  * @throws AssertionException
  */
 private function validateSubscribers(Nette\DI\ContainerBuilder $builder, Nette\DI\ServiceDefinition $manager)
 {
     foreach ($manager->setup as $stt) {
         if ($stt->entity !== 'addEventSubscriber') {
             $this->allowedManagerSetup[] = $stt;
             continue;
         }
         try {
             $serviceName = $builder->getServiceName(reset($stt->arguments));
             $def = $builder->getDefinition($serviceName);
         } catch (\Exception $e) {
             throw new AssertionException("Please, do not register listeners directly to service '" . $this->prefix('manager') . "'. " . "Use section '" . $this->name . ": subscribers: ', or tag the service as '" . self::SUBSCRIBER_TAG . "'.", 0, $e);
         }
         if (!$def->class) {
             throw new AssertionException("Please, specify existing class for " . (is_numeric($serviceName) ? 'anonymous ' : '') . "service '{$serviceName}' explicitly, " . "and make sure, that the class exists and can be autoloaded.");
         } elseif (!class_exists($def->class)) {
             throw new AssertionException("Class '{$def->class}' of " . (is_numeric($serviceName) ? 'anonymous ' : '') . "service '{$serviceName}' cannot be found. " . "Please make sure, that the class exists and can be autoloaded.");
         }
         if (!in_array('Doctrine\\Common\\EventSubscriber', class_implements($def->class))) {
             // the minimum is Doctrine EventSubscriber, but recommend is Kdyby Subscriber
             throw new AssertionException("Subscriber '{$serviceName}' doesn't implement Kdyby\\Events\\Subscriber.");
         }
         $eventNames = array();
         $listenerInst = self::createInstanceWithoutConstructor($def->class);
         foreach ($listenerInst->getSubscribedEvents() as $eventName => $params) {
             if (is_numeric($eventName) && is_string($params)) {
                 // [EventName, ...]
                 list(, $method) = Kdyby\Events\Event::parseName($params);
                 $eventNames[] = ltrim($params, '\\');
                 if (!method_exists($listenerInst, $method)) {
                     throw new AssertionException("Event listener " . $def->class . "::{$method}() is not implemented.");
                 }
             } elseif (is_string($eventName)) {
                 // [EventName => ???, ...]
                 $eventNames[] = ltrim($eventName, '\\');
                 if (is_string($params)) {
                     // [EventName => method, ...]
                     if (!method_exists($listenerInst, $params)) {
                         throw new AssertionException("Event listener " . $def->class . "::{$params}() is not implemented.");
                     }
                 } elseif (is_string($params[0])) {
                     // [EventName => [method, priority], ...]
                     if (!method_exists($listenerInst, $params[0])) {
                         throw new AssertionException("Event listener " . $def->class . "::{$params[0]}() is not implemented.");
                     }
                 } else {
                     foreach ($params as $listener) {
                         // [EventName => [[method, priority], ...], ...]
                         if (!method_exists($listenerInst, $listener[0])) {
                             throw new AssertionException("Event listener " . $def->class . "::{$listener[0]}() is not implemented.");
                         }
                     }
                 }
             }
         }
         $this->listeners[$serviceName] = array_unique($eventNames);
     }
 }
开发者ID:hranicka,项目名称:kdyby-events,代码行数:63,代码来源:EventsExtension.php


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