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


PHP ContainerBuilder::hasDefinition方法代码示例

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


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

示例1: createRepositoryService

 protected function createRepositoryService($repositoryData, ContainerBuilder $builder, $mapperName)
 {
     $repositoryName = $this->prefix('repositories.' . $repositoryData['name']);
     if (!$builder->hasDefinition($repositoryName)) {
         $builder->addDefinition($repositoryName)->setClass($repositoryData['class'])->setArguments(['@' . $mapperName, '@' . $this->prefix('dependencyProvider')])->addSetup('onModelAttach', ['@' . $this->prefix('model')]);
     }
 }
开发者ID:Zarganwar,项目名称:orm,代码行数:7,代码来源:OrmExtension.php

示例2: parseServices

 /**
  * Parses section 'services' from configuration file.
  * @return void
  */
 public static function parseServices(Nette\DI\ContainerBuilder $container, array $config, $namespace = NULL)
 {
     $services = isset($config['services']) ? $config['services'] : array();
     $factories = isset($config['factories']) ? $config['factories'] : array();
     $all = array_merge($services, $factories);
     uasort($all, function ($a, $b) {
         return strcmp(Helpers::isInheriting($a), Helpers::isInheriting($b));
     });
     foreach ($all as $origName => $def) {
         $shared = array_key_exists($origName, $services);
         if ((string) (int) $origName === (string) $origName) {
             $name = (string) (count($container->getDefinitions()) + 1);
         } elseif ($shared && array_key_exists($origName, $factories)) {
             throw new Nette\DI\ServiceCreationException("It is not allowed to use services and factories with the same name: '{$origName}'.");
         } else {
             $name = ($namespace ? $namespace . '.' : '') . strtr($origName, '\\', '_');
         }
         if (($parent = Helpers::takeParent($def)) && $parent !== $name) {
             $container->removeDefinition($name);
             $definition = $container->addDefinition($name);
             if ($parent !== Helpers::OVERWRITE) {
                 foreach ($container->getDefinition($parent) as $k => $v) {
                     $definition->{$k} = unserialize(serialize($v));
                     // deep clone
                 }
             }
         } elseif ($container->hasDefinition($name)) {
             $definition = $container->getDefinition($name);
             if ($definition->shared !== $shared) {
                 throw new Nette\DI\ServiceCreationException("It is not allowed to use service and factory with the same name '{$name}'.");
             }
         } else {
             $definition = $container->addDefinition($name);
         }
         try {
             static::parseService($definition, $def, $shared);
         } catch (\Exception $e) {
             throw new Nette\DI\ServiceCreationException("Service '{$name}': " . $e->getMessage(), NULL, $e);
         }
     }
 }
开发者ID:genextwebs,项目名称:dropbox-sample,代码行数:45,代码来源:Compiler.php

示例3: parseServices

 /**
  * Parses section 'services' from (unexpanded) configuration file.
  * @return void
  */
 public static function parseServices(ContainerBuilder $builder, array $config, string $namespace = NULL)
 {
     $services = isset($config['services']) ? $config['services'] : [];
     $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;
         }
         $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) {
             $builder->removeDefinition($name);
             $definition = $builder->addDefinition($name, $parent === Config\Helpers::OVERWRITE ? NULL : unserialize(serialize($builder->getDefinition($parent))));
         } elseif ($builder->hasDefinition($name)) {
             $definition = $builder->getDefinition($name);
         } else {
             $definition = $builder->addDefinition($name);
         }
         try {
             static::parseService($definition, $def);
         } catch (\Exception $e) {
             throw new ServiceCreationException("Service '{$name}': " . $e->getMessage(), 0, $e);
         }
     }
 }
开发者ID:kukulich,项目名称:di,代码行数:50,代码来源:Compiler.php

示例4: parseServices

 /**
  * Parses section 'services' from (unexpanded) configuration file.
  * @return void
  */
 public static function parseServices(ContainerBuilder $builder, array $config, $namespace = NULL)
 {
     $services = isset($config['services']) ? $config['services'] : array();
     $factories = isset($config['factories']) ? $config['factories'] : array();
     $all = array_merge($services, $factories);
     uasort($all, function ($a, $b) {
         return strcmp(Config\Helpers::isInheriting($a), Config\Helpers::isInheriting($b));
     });
     if (!empty($config['factories'])) {
         trigger_error("Section 'factories' is deprecated, move definitions to section 'services' and append key 'autowired: no'.", E_USER_DEPRECATED);
     }
     foreach ($all as $origName => $def) {
         if ((string) (int) $origName === (string) $origName) {
             $name = count($builder->getDefinitions()) . preg_replace('#\\W+#', '_', $def instanceof \stdClass ? ".{$def->value}" : (is_scalar($def) ? ".{$def}" : ''));
         } elseif (array_key_exists($origName, $services) && array_key_exists($origName, $factories)) {
             throw new ServiceCreationException("It is not allowed to use services and factories with the same name: '{$origName}'.");
         } else {
             $name = ($namespace ? $namespace . '.' : '') . strtr($origName, '\\', '_');
         }
         $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) {
             $builder->removeDefinition($name);
             $definition = $builder->addDefinition($name, $parent === Config\Helpers::OVERWRITE ? NULL : unserialize(serialize($builder->getDefinition($parent))));
         } elseif ($builder->hasDefinition($name)) {
             $definition = $builder->getDefinition($name);
         } else {
             $definition = $builder->addDefinition($name);
         }
         try {
             static::parseService($definition, $def);
         } catch (\Exception $e) {
             throw new ServiceCreationException("Service '{$name}': " . $e->getMessage(), NULL, $e);
         }
         if (array_key_exists($origName, $factories)) {
             $definition->setAutowired(FALSE);
         }
         if ($definition->class === 'self') {
             $definition->class = $origName;
             trigger_error("Replace service definition '{$origName}: self' with '- {$origName}'.", E_USER_DEPRECATED);
         }
         if ($definition->factory && $definition->factory->entity === 'self') {
             $definition->factory->entity = $origName;
             trigger_error("Replace service definition '{$origName}: self' with '- {$origName}'.", E_USER_DEPRECATED);
         }
     }
 }
开发者ID:cujan,项目名称:atlashornin,代码行数:57,代码来源:Compiler.php

示例5: parseServices

 /**
  * Parses section 'services' from configuration file.
  *
  * @return void
  */
 public static function parseServices(Nette\DI\ContainerBuilder $container, array $config, $namespace = null)
 {
     $services = isset($config['services']) ? $config['services'] : array();
     $factories = isset($config['factories']) ? $config['factories'] : array();
     if ($tmp = array_intersect_key($services, $factories)) {
         $tmp = implode("', '", array_keys($tmp));
         throw new Nette\DI\ServiceCreationException("It is not allowed to use services and factories with the same names: '{$tmp}'.");
     }
     $all = $services + $factories;
     uasort($all, function ($a, $b) {
         return strcmp(Helpers::isInheriting($a), Helpers::isInheriting($b));
     });
     foreach ($all as $name => $def) {
         $shared = array_key_exists($name, $services);
         $name = ($namespace ? $namespace . '.' : '') . $name;
         if (($parent = Helpers::takeParent($def)) && $parent !== $name) {
             $container->removeDefinition($name);
             $definition = $container->addDefinition($name);
             if ($parent !== Helpers::OVERWRITE) {
                 foreach ($container->getDefinition($parent) as $k => $v) {
                     $definition->{$k} = unserialize(serialize($v));
                     // deep clone
                 }
             }
         } elseif ($container->hasDefinition($name)) {
             $definition = $container->getDefinition($name);
             if ($definition->shared !== $shared) {
                 throw new Nette\DI\ServiceCreationException("It is not allowed to use service and factory with the same name '{$name}'.");
             }
         } else {
             $definition = $container->addDefinition($name);
         }
         try {
             static::parseService($definition, $def, $shared);
         } catch (\Exception $e) {
             throw new Nette\DI\ServiceCreationException("Service '{$name}': " . $e->getMessage(), null, $e);
         }
     }
 }
开发者ID:BozzaCoon,项目名称:SPHERE-Framework,代码行数:44,代码来源:Compiler.php

示例6: parseServices

 /**
  * Parses section 'services' from (unexpanded) configuration file.
  * @return void
  */
 public static function parseServices(ContainerBuilder $builder, array $config, $namespace = NULL)
 {
     if (!empty($config['factories'])) {
         throw new Nette\DeprecatedException("Section 'factories' is deprecated, move definitions to section 'services' and append key 'autowired: no'.");
     }
     $services = isset($config['services']) ? $config['services'] : array();
     $depths = array();
     foreach ($services as $name => $def) {
         $path = array();
         while (Config\Helpers::isInheriting($def)) {
             $path[] = $def;
             $def = isset($services[$def[Config\Helpers::EXTENDS_KEY]]) ? $services[$def[Config\Helpers::EXTENDS_KEY]] : array();
             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 $origName => $def) {
         if ((string) (int) $origName === (string) $origName) {
             $postfix = $def instanceof Statement && is_string($def->getEntity()) ? '.' . $def->getEntity() : (is_scalar($def) ? ".{$def}" : '');
             $name = count($builder->getDefinitions()) + 1 . preg_replace('#\\W+#', '_', $postfix);
         } else {
             $name = ($namespace ? $namespace . '.' : '') . strtr($origName, '\\', '_');
         }
         $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) {
             $builder->removeDefinition($name);
             $definition = $builder->addDefinition($name, $parent === Config\Helpers::OVERWRITE ? NULL : unserialize(serialize($builder->getDefinition($parent))));
         } elseif ($builder->hasDefinition($name)) {
             $definition = $builder->getDefinition($name);
         } else {
             $definition = $builder->addDefinition($name);
         }
         try {
             static::parseService($definition, $def);
         } catch (\Exception $e) {
             throw new ServiceCreationException("Service '{$name}': " . $e->getMessage(), NULL, $e);
         }
         if ($definition->getClass() === 'self' || $definition->getFactory() && $definition->getFactory()->getEntity() === 'self') {
             throw new Nette\DeprecatedException("Replace service definition '{$origName}: self' with '- {$origName}'.");
         }
     }
 }
开发者ID:DIPcom,项目名称:Sandmin,代码行数:56,代码来源:Compiler.php

示例7: setupApplication

 /**
  * @param \Nette\DI\ContainerBuilder $container
  * @param array $config
  */
 private function setupApplication(ContainerBuilder $container)
 {
     if ($container->hasDefinition('nette.presenterFactory')) {
         $container->getDefinition('nette.presenterFactory')->addSetup('setMapping', [['Lohini' => 'LohiniModule\\*\\*Presenter']]);
     }
 }
开发者ID:lohini,项目名称:framework,代码行数:10,代码来源:LohiniExtension.php

示例8: parseServices

 static function parseServices(Nette\DI\ContainerBuilder $container, array $config)
 {
     $all = isset($config['services']) ? $config['services'] : array();
     $all += isset($config['factories']) ? $config['factories'] : array();
     uasort($all, function ($a, $b) {
         return strcmp(Config::isInheriting($a), Config::isInheriting($b));
     });
     foreach ($all as $name => $def) {
         if ($parent = Config::takeParent($def)) {
             $container->removeDefinition($name);
             $definition = $container->addDefinition($name);
             if ($parent !== Config::OVERWRITE) {
                 foreach ($container->getDefinition($parent) as $k => $v) {
                     $definition->{$k} = $v;
                 }
             }
         } elseif ($container->hasDefinition($name)) {
             $definition = $container->getDefinition($name);
         } else {
             $definition = $container->addDefinition($name);
         }
         try {
             static::parseService($definition, $def, isset($config['services'][$name]));
         } catch (\Exception $e) {
             throw new Nette\DI\ServiceCreationException("Service '{$name}': " . $e->getMessage(), NULL, $e);
         }
     }
 }
开发者ID:skapytek,项目名称:scripts,代码行数:28,代码来源:nette.min.php


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