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


PHP Helpers::prefixServiceName方法代码示例

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


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

示例1: loadDefinitions

 /**
  * Adds service definitions from configuration.
  * @return void
  */
 public static function loadDefinitions(ContainerBuilder $builder, array $services, $namespace = NULL)
 {
     $depths = [];
     foreach ($services as $name => $def) {
         $path = [];
         while (Config\Helpers::isInheriting($def)) {
             $path[] = $def;
             $def = isset($services[$def[Config\Helpers::EXTENDS_KEY]]) ? $services[$def[Config\Helpers::EXTENDS_KEY]] : [];
             if (in_array($def, $path, TRUE)) {
                 throw new ServiceCreationException("Circular reference detected for service '{$name}'.");
             }
         }
         $depths[$name] = count($path);
     }
     array_multisort($depths, $services);
     foreach ($services as $name => $def) {
         if ((string) (int) $name === (string) $name) {
             $postfix = $def instanceof Statement && is_string($def->getEntity()) ? '.' . $def->getEntity() : (is_scalar($def) ? ".{$def}" : '');
             $name = count($builder->getDefinitions()) + 1 . preg_replace('#\\W+#', '_', $postfix);
         } elseif ($namespace) {
             $name = $namespace . '.' . $name;
         }
         if ($def === FALSE) {
             $builder->removeDefinition($name);
             continue;
         }
         if ($namespace) {
             $def = Helpers::prefixServiceName($def, $namespace);
         }
         $params = $builder->parameters;
         if (is_array($def) && isset($def['parameters'])) {
             foreach ((array) $def['parameters'] as $k => $v) {
                 $v = explode(' ', is_int($k) ? $v : $k);
                 $params[end($v)] = $builder::literal('$' . end($v));
             }
         }
         $def = Helpers::expand($def, $params);
         if (($parent = Config\Helpers::takeParent($def)) && $parent !== $name) {
             trigger_error("Section inheritance {$name} < {$parent} is deprecated.", E_USER_DEPRECATED);
             $builder->removeDefinition($name);
             $definition = $builder->addDefinition($name, $parent === Config\Helpers::OVERWRITE ? NULL : clone $builder->getDefinition($parent));
         } elseif ($builder->hasDefinition($name)) {
             $definition = $builder->getDefinition($name);
         } else {
             $definition = $builder->addDefinition($name);
         }
         try {
             static::loadDefinition($definition, $def);
         } catch (\Exception $e) {
             throw new ServiceCreationException("Service '{$name}': " . $e->getMessage(), 0, $e);
         }
     }
 }
开发者ID:nette,项目名称:di,代码行数:57,代码来源:Compiler.php


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