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


PHP Helpers::takeParent方法代码示例

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


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

示例1: buildClient

 /**
  * @param string $name
  * @param array $config
  * @return Nette\DI\ServiceDefinition
  */
 protected function buildClient($name, $config)
 {
     $builder = $this->getContainerBuilder();
     $defaultConfig = $this->getConfig($this->clientDefaults);
     if ($parentName = Config\Helpers::takeParent($config)) {
         Nette\Utils\Validators::assertField($this->configuredClients, $parentName, 'array', "parent configuration '%', are you sure it's defined?");
         $defaultConfig = Config\Helpers::merge($this->configuredClients[$parentName], $defaultConfig);
     }
     $config = Config\Helpers::merge($config, $defaultConfig);
     $config = array_intersect_key(self::fixClientConfig($config), $this->clientDefaults);
     $client = $builder->addDefinition($clientName = $this->prefix(($name ? $name . '_' : '') . 'client'))->setClass('Kdyby\\Redis\\RedisClient', ['host' => $config['host'], 'port' => $config['port'], 'database' => $config['database'], 'timeout' => $config['timeout'], 'auth' => $config['auth'], 'persistent' => $config['persistent']]);
     if (empty($builder->parameters[$this->name]['defaultClient'])) {
         $builder->parameters[$this->name]['defaultClient'] = $clientName;
         $this->configuredClients['default'] = $config;
         $builder->addDefinition($this->prefix('default_client'))->setClass('Kdyby\\Redis\\RedisClient')->setFactory('@' . $clientName)->setAutowired(FALSE);
     } else {
         $client->setAutowired(FALSE);
     }
     $this->configuredClients[$name] = $config;
     $client->addSetup('setupLockDuration', [$config['lockDuration'], $config['lockAcquireTimeout']]);
     $client->addSetup('setConnectionAttempts', [$config['connectionAttempts']]);
     $client->addTag('redis.client');
     if (array_key_exists('debugger', $config) && $config['debugger']) {
         $builder->addDefinition($panelName = $clientName . '.panel')->setClass('Kdyby\\Redis\\Diagnostics\\Panel')->setFactory('Kdyby\\Redis\\Diagnostics\\Panel::register')->addSetup('$renderPanel', [$config['debugger'] !== self::PANEL_COUNT_MODE])->addSetup('$name', [$name ?: 'default']);
         $client->addSetup('setPanel', ['@' . $panelName]);
     }
     return $client;
 }
开发者ID:kdyby,项目名称:redis,代码行数:33,代码来源:RedisExtension.php

示例2: dump

 /**
  * Generates configuration in NEON format.
  * @return string
  */
 public function dump(array $data)
 {
     $tmp = array();
     foreach ($data as $name => $secData) {
         if ($parent = Helpers::takeParent($secData)) {
             $name .= ' ' . self::INHERITING_SEPARATOR . ' ' . $parent;
         }
         $tmp[$name] = $secData;
     }
     return "# generated by Nette\n\n" . Neon\Neon::encode($tmp, Neon\Neon::BLOCK);
 }
开发者ID:re1la2pse,项目名称:GromesProjekt,代码行数:15,代码来源:NeonAdapter.php

示例3: dump

 /**
  * Generates configuration in NEON format.
  * @return string
  */
 public function dump(array $data)
 {
     $tmp = array();
     foreach ($data as $name => $secData) {
         if ($parent = Helpers::takeParent($secData)) {
             $name .= ' ' . self::INHERITING_SEPARATOR . ' ' . $parent;
         }
         $tmp[$name] = $secData;
     }
     array_walk_recursive($tmp, function (&$val) {
         if ($val instanceof Statement) {
             $val = NeonAdapter::statementToEntity($val);
         }
     });
     return "# generated by Nette\n\n" . Neon\Neon::encode($tmp, Neon\Neon::BLOCK);
 }
开发者ID:norik16,项目名称:TripMap,代码行数:20,代码来源:NeonAdapter.php

示例4: getSection

 private function getSection(array $data, $key, $file)
 {
     Validators::assertField($data, $key, 'array|null', "section '%' in file '{$file}'");
     $item = $data[$key];
     if ($parent = Helpers::takeParent($item)) {
         $item = Helpers::merge($item, $this->getSection($data, $parent, $file));
     }
     return $item;
 }
开发者ID:cujan,项目名称:atlashornin,代码行数:9,代码来源:Loader.php

示例5: parseService

 /**
  * Parses single service from configuration file.
  * @return void
  */
 public static function parseService(ServiceDefinition $definition, $config)
 {
     if ($config === NULL) {
         return;
     } elseif (is_string($config) && interface_exists($config)) {
         $config = ['class' => NULL, 'implement' => $config];
     } elseif ($config instanceof Statement && is_string($config->getEntity()) && interface_exists($config->getEntity())) {
         $config = ['class' => NULL, 'implement' => $config->getEntity(), 'factory' => array_shift($config->arguments)];
     } elseif (!is_array($config) || isset($config[0], $config[1])) {
         $config = ['class' => NULL, 'create' => $config];
     }
     if (array_key_exists('factory', $config)) {
         $config['create'] = $config['factory'];
         unset($config['factory']);
     }
     $known = ['class', 'create', 'arguments', 'setup', 'autowired', 'dynamic', 'inject', 'parameters', 'implement', 'run', 'tags'];
     if ($error = array_diff(array_keys($config), $known)) {
         throw new Nette\InvalidStateException(sprintf("Unknown or deprecated key '%s' in definition of service.", implode("', '", $error)));
     }
     $config = Helpers::filterArguments($config);
     $arguments = [];
     if (array_key_exists('arguments', $config)) {
         Validators::assertField($config, 'arguments', 'array');
         $arguments = $config['arguments'];
         $definition->setArguments($arguments);
     }
     if (array_key_exists('class', $config) || array_key_exists('create', $config)) {
         $definition->setClass(NULL);
         $definition->setFactory(NULL);
     }
     if (array_key_exists('class', $config)) {
         Validators::assertField($config, 'class', 'string|Nette\\DI\\Statement|null');
         if (!$config['class'] instanceof Statement) {
             $definition->setClass($config['class']);
         }
         $definition->setFactory($config['class'], $arguments);
     }
     if (array_key_exists('create', $config)) {
         Validators::assertField($config, 'create', 'callable|Nette\\DI\\Statement|null');
         $definition->setFactory($config['create'], $arguments);
     }
     if (isset($config['setup'])) {
         if (Config\Helpers::takeParent($config['setup'])) {
             $definition->setSetup([]);
         }
         Validators::assertField($config, 'setup', 'list');
         foreach ($config['setup'] as $id => $setup) {
             Validators::assert($setup, 'callable|Nette\\DI\\Statement', "setup item #{$id}");
             $definition->addSetup($setup);
         }
     }
     if (isset($config['parameters'])) {
         Validators::assertField($config, 'parameters', 'array');
         $definition->setParameters($config['parameters']);
     }
     if (isset($config['implement'])) {
         Validators::assertField($config, 'implement', 'string');
         $definition->setImplement($config['implement']);
         $definition->setAutowired(TRUE);
     }
     if (isset($config['autowired'])) {
         Validators::assertField($config, 'autowired', 'bool');
         $definition->setAutowired($config['autowired']);
     }
     if (isset($config['dynamic'])) {
         Validators::assertField($config, 'dynamic', 'bool');
         $definition->setDynamic($config['dynamic']);
     }
     if (isset($config['inject'])) {
         Validators::assertField($config, 'inject', 'bool');
         $definition->addTag(Extensions\InjectExtension::TAG_INJECT, $config['inject']);
     }
     if (isset($config['run'])) {
         $config['tags']['run'] = (bool) $config['run'];
     }
     if (isset($config['tags'])) {
         Validators::assertField($config, 'tags', 'array');
         if (Config\Helpers::takeParent($config['tags'])) {
             $definition->setTags([]);
         }
         foreach ($config['tags'] as $tag => $attrs) {
             if (is_int($tag) && is_string($attrs)) {
                 $definition->addTag($attrs);
             } else {
                 $definition->addTag($tag, $attrs);
             }
         }
     }
 }
开发者ID:kukulich,项目名称:di,代码行数:93,代码来源:Compiler.php

示例6: parseService

 /**
  * Parses single service from configuration file.
  * @return void
  */
 public static function parseService(ServiceDefinition $definition, $config)
 {
     if ($config === NULL) {
         return;
     } elseif (is_string($config) && interface_exists($config)) {
         $config = array('class' => NULL, 'implement' => $config);
     } elseif ($config instanceof \stdClass && interface_exists($config->value)) {
         $config = array('class' => NULL, 'implement' => $config->value, 'factory' => array_shift($config->attributes));
     } elseif (!is_array($config)) {
         $config = array('class' => NULL, 'create' => $config);
     }
     if (array_key_exists('factory', $config)) {
         $config['create'] = $config['factory'];
         unset($config['factory']);
     }
     $known = array('class', 'create', 'arguments', 'setup', 'autowired', 'inject', 'parameters', 'implement', 'run', 'tags');
     if ($error = array_diff(array_keys($config), $known)) {
         throw new Nette\InvalidStateException("Unknown or deprecated key '" . implode("', '", $error) . "' in definition of service.");
     }
     $arguments = array();
     if (array_key_exists('arguments', $config)) {
         Validators::assertField($config, 'arguments', 'array');
         $arguments = self::filterArguments($config['arguments']);
         $definition->setArguments($arguments);
     }
     if (array_key_exists('class', $config) || array_key_exists('create', $config)) {
         $definition->class = NULL;
         $definition->factory = NULL;
     }
     if (array_key_exists('class', $config)) {
         Validators::assertField($config, 'class', 'string|stdClass|null');
         if ($config['class'] instanceof \stdClass) {
             $definition->setClass($config['class']->value, self::filterArguments($config['class']->attributes));
         } else {
             $definition->setClass($config['class'], $arguments);
         }
     }
     if (array_key_exists('create', $config)) {
         Validators::assertField($config, 'create', 'callable|stdClass|null');
         if ($config['create'] instanceof \stdClass) {
             $definition->setFactory($config['create']->value, self::filterArguments($config['create']->attributes));
         } else {
             $definition->setFactory($config['create'], $arguments);
         }
     }
     if (isset($config['setup'])) {
         if (Config\Helpers::takeParent($config['setup'])) {
             $definition->setup = array();
         }
         Validators::assertField($config, 'setup', 'list');
         foreach ($config['setup'] as $id => $setup) {
             Validators::assert($setup, 'callable|stdClass', "setup item #{$id}");
             if ($setup instanceof \stdClass) {
                 Validators::assert($setup->value, 'callable', "setup item #{$id}");
                 $definition->addSetup($setup->value, self::filterArguments($setup->attributes));
             } else {
                 $definition->addSetup($setup);
             }
         }
     }
     if (isset($config['parameters'])) {
         Validators::assertField($config, 'parameters', 'array');
         $definition->setParameters($config['parameters']);
     }
     if (isset($config['implement'])) {
         Validators::assertField($config, 'implement', 'string');
         $definition->setImplement($config['implement']);
         $definition->setAutowired(TRUE);
     }
     if (isset($config['autowired'])) {
         Validators::assertField($config, 'autowired', 'bool');
         $definition->setAutowired($config['autowired']);
     }
     if (isset($config['inject'])) {
         Validators::assertField($config, 'inject', 'bool');
         $definition->setInject($config['inject']);
     }
     if (isset($config['run'])) {
         $config['tags']['run'] = (bool) $config['run'];
     }
     if (isset($config['tags'])) {
         Validators::assertField($config, 'tags', 'array');
         if (Config\Helpers::takeParent($config['tags'])) {
             $definition->tags = array();
         }
         foreach ($config['tags'] as $tag => $attrs) {
             if (is_int($tag) && is_string($attrs)) {
                 $definition->addTag($attrs);
             } else {
                 $definition->addTag($tag, $attrs);
             }
         }
     }
 }
开发者ID:cujan,项目名称:atlashornin,代码行数:98,代码来源:Compiler.php

示例7: dump

 /**
  * Generates configuration in INI format.
  * @return string
  */
 public function dump(array $data) : string
 {
     $output = [];
     foreach ($data as $name => $secData) {
         if (!is_array($secData)) {
             $output = [];
             self::build($data, $output, '');
             break;
         }
         if ($parent = Helpers::takeParent($secData)) {
             $output[] = "[{$name} " . self::INHERITING_SEPARATOR . " {$parent}]";
         } else {
             $output[] = "[{$name}]";
         }
         self::build($secData, $output, '');
         $output[] = '';
     }
     return "; generated by Nette\n\n" . implode(PHP_EOL, $output);
 }
开发者ID:kukulich,项目名称:di,代码行数:23,代码来源:IniAdapter.php

示例8: loadDefinition

 /**
  * Parses single service definition from configuration.
  * @return void
  */
 public static function loadDefinition(ServiceDefinition $definition, $config)
 {
     if ($config === NULL) {
         return;
     } elseif (is_string($config) && interface_exists($config)) {
         $config = ['class' => NULL, 'implement' => $config];
     } elseif ($config instanceof Statement && is_string($config->getEntity()) && interface_exists($config->getEntity())) {
         $config = ['class' => NULL, 'implement' => $config->getEntity(), 'factory' => array_shift($config->arguments)];
     } elseif (!is_array($config) || isset($config[0], $config[1])) {
         $config = ['class' => NULL, 'factory' => $config];
     }
     if (array_key_exists('create', $config)) {
         trigger_error("Key 'create' is deprecated, use 'factory' or 'class' in configuration.", E_USER_DEPRECATED);
         $config['factory'] = $config['create'];
         unset($config['create']);
     }
     $known = ['class', 'factory', 'arguments', 'setup', 'autowired', 'dynamic', 'inject', 'parameters', 'implement', 'run', 'tags'];
     if ($error = array_diff(array_keys($config), $known)) {
         $hints = array_filter(array_map(function ($error) use($known) {
             return Nette\Utils\ObjectMixin::getSuggestion($known, $error);
         }, $error));
         $hint = $hints ? ", did you mean '" . implode("', '", $hints) . "'?" : '.';
         throw new Nette\InvalidStateException(sprintf("Unknown key '%s' in definition of service{$hint}", implode("', '", $error)));
     }
     $config = Helpers::filterArguments($config);
     if (array_key_exists('class', $config) || array_key_exists('factory', $config)) {
         $definition->setClass(NULL);
         $definition->setFactory(NULL);
     }
     if (array_key_exists('class', $config)) {
         Validators::assertField($config, 'class', 'string|Nette\\DI\\Statement|null');
         if (!$config['class'] instanceof Statement) {
             $definition->setClass($config['class']);
         }
         $definition->setFactory($config['class']);
     }
     if (array_key_exists('factory', $config)) {
         Validators::assertField($config, 'factory', 'callable|Nette\\DI\\Statement|null');
         $definition->setFactory($config['factory']);
     }
     if (array_key_exists('arguments', $config)) {
         Validators::assertField($config, 'arguments', 'array');
         $arguments = $config['arguments'];
         if (!Config\Helpers::takeParent($arguments) && !Nette\Utils\Arrays::isList($arguments) && $definition->getFactory()) {
             $arguments += $definition->getFactory()->arguments;
         }
         $definition->setArguments($arguments);
     }
     if (isset($config['setup'])) {
         if (Config\Helpers::takeParent($config['setup'])) {
             $definition->setSetup([]);
         }
         Validators::assertField($config, 'setup', 'list');
         foreach ($config['setup'] as $id => $setup) {
             Validators::assert($setup, 'callable|Nette\\DI\\Statement|array:1', "setup item #{$id}");
             if (is_array($setup)) {
                 $setup = new Statement(key($setup), array_values($setup));
             }
             $definition->addSetup($setup);
         }
     }
     if (isset($config['parameters'])) {
         Validators::assertField($config, 'parameters', 'array');
         $definition->setParameters($config['parameters']);
     }
     if (isset($config['implement'])) {
         Validators::assertField($config, 'implement', 'string');
         $definition->setImplement($config['implement']);
         $definition->setAutowired(TRUE);
     }
     if (isset($config['autowired'])) {
         Validators::assertField($config, 'autowired', 'bool|string|array');
         $definition->setAutowired($config['autowired']);
     }
     if (isset($config['dynamic'])) {
         Validators::assertField($config, 'dynamic', 'bool');
         $definition->setDynamic($config['dynamic']);
     }
     if (isset($config['inject'])) {
         Validators::assertField($config, 'inject', 'bool');
         $definition->addTag(Extensions\InjectExtension::TAG_INJECT, $config['inject']);
     }
     if (isset($config['run'])) {
         trigger_error("Option 'run' is deprecated, use 'run' as tag.", E_USER_DEPRECATED);
         $config['tags']['run'] = (bool) $config['run'];
     }
     if (isset($config['tags'])) {
         Validators::assertField($config, 'tags', 'array');
         if (Config\Helpers::takeParent($config['tags'])) {
             $definition->setTags([]);
         }
         foreach ($config['tags'] as $tag => $attrs) {
             if (is_int($tag) && is_string($attrs)) {
                 $definition->addTag($attrs);
             } else {
                 $definition->addTag($tag, $attrs);
//.........这里部分代码省略.........
开发者ID:nette,项目名称:di,代码行数:101,代码来源:Compiler.php


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