當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。