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


PHP Strings::expand方法代码示例

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


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

示例1: expand

 /**
  * Expands %placeholders% in string.
  * @param  mixed
  * @return mixed
  */
 public function expand($s)
 {
     return is_string($s) ? Nette\Utils\Strings::expand($s, $this->params) : $s;
 }
开发者ID:kovkus,项目名称:r-cms,代码行数:9,代码来源:Container.php

示例2: addDefinitions

 /**
  * Adds new services from list of definitions. Expands %param% and @service values.
  * Format:
  *   serviceName => array(
  *      class => 'ClassName' or factory => 'Factory::create'
  *      arguments => array(...)
  *      methods => array(
  *         array(methodName, array(...))
  *         ...
  *      )
  *      tags => array(...)
  *      alias => 'Service'
  *   )
  */
 public function addDefinitions(IContainer $container, array $definitions)
 {
     foreach ($definitions as $name => $definition) {
         if (is_scalar($definition)) {
             if (substr($definition, 0, 1) === '@') {
                 $definition = array('alias' => substr($definition, 1));
             } else {
                 $definition = array('class' => $definition);
             }
         }
         $arguments = isset($definition['arguments']) ? $definition['arguments'] : array();
         $expander = function (&$val) use($container) {
             if (substr($val, 0, 1) === '@') {
                 $val = $container->getService(substr($val, 1));
             } elseif (is_string($val)) {
                 $val = Nette\Utils\Strings::expand($val, $container->params);
             }
         };
         if (isset($definition['class']) || isset($definition['factory'])) {
             if (isset($definition['class'])) {
                 $class = $definition['class'];
             } else {
                 $class = NULL;
                 array_unshift($arguments, $definition['factory']);
             }
             $methods = isset($definition['methods']) ? $definition['methods'] : array();
             $factory = function ($container) use($class, $arguments, $methods, $expander) {
                 array_walk_recursive($arguments, $expander);
                 if ($class) {
                     $class = Nette\Utils\Strings::expand($class, $container->params);
                     if ($arguments) {
                         $service = Nette\Reflection\ClassType::from($class)->newInstanceArgs($arguments);
                     } else {
                         $service = new $class();
                     }
                 } else {
                     $factory = $arguments[0];
                     $arguments[0] = $container;
                     $service = call_user_func_array($factory, $arguments);
                 }
                 array_walk_recursive($methods, $expander);
                 foreach ($methods as $method) {
                     call_user_func_array(array($service, $method[0]), isset($method[1]) ? $method[1] : array());
                 }
                 return $service;
             };
         } elseif (isset($definition['alias'])) {
             $factory = function ($container) use($definition) {
                 return $container->getService($definition['alias']);
             };
         } else {
             throw new Nette\InvalidStateException("The definition of service '{$name}' is missing factory method.");
         }
         if (isset($definition['tags'])) {
             $tags = (array) $definition['tags'];
             array_walk_recursive($tags, $expander);
         } else {
             $tags = NULL;
         }
         $container->addService($name, $factory, $tags);
     }
 }
开发者ID:kovkus,项目名称:r-cms,代码行数:76,代码来源:ContainerBuilder.php


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