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


PHP Datasource::findParameterInEnv方法代码示例

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


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

示例1: __processParametersInString

 /**
  * This function will replace any parameters in a string with their value.
  * Parameters are defined by being prefixed by a $ character. In certain
  * situations, the parameter will be surrounded by {}, which Symphony
  * takes to mean, evaluate this parameter to a value, other times it will be
  * omitted which is usually used to indicate that this parameter exists
  *
  * @param string $value
  *  The string with the parameters that need to be evaluated
  * @param array $env
  *  The environment variables from the Frontend class which includes
  *  any params set by Symphony or Events or by other Datasources
  * @param boolean $includeParenthesis
  *  Parameters will sometimes not be surrounded by {}. If this is the case
  *  setting this parameter to false will make this function automatically add
  *  them to the parameter. By default this is true, which means all parameters
  *  in the string already are surrounded by {}
  * @param boolean $escape
  *  If set to true, the resulting value will be `urlencode`'d before being returned.
  *  By default this is false
  * @return string
  *  The string will all parameters evaluated. If a parameter was not found, it will
  *  not be replaced at all.
  */
 public function __processParametersInString($value, array $env, $includeParenthesis = true, $escape = false)
 {
     if (trim($value) == '') {
         return null;
     }
     if (!$includeParenthesis) {
         $value = '{' . $value . '}';
     }
     if (preg_match_all('@{([^}]+)}@i', $value, $matches, PREG_SET_ORDER)) {
         foreach ($matches as $match) {
             list($source, $cleaned) = $match;
             $replacement = null;
             $bits = preg_split('/:/', $cleaned, -1, PREG_SPLIT_NO_EMPTY);
             foreach ($bits as $param) {
                 if ($param[0] != '$') {
                     $replacement = $param;
                     break;
                 }
                 $param = trim($param, '$');
                 $replacement = Datasource::findParameterInEnv($param, $env);
                 if (is_array($replacement)) {
                     $replacement = array_map(array('Datasource', 'escapeCommas'), $replacement);
                     if (count($replacement) > 1) {
                         $replacement = implode(',', $replacement);
                     } else {
                         $replacement = end($replacement);
                     }
                 }
                 if (!empty($replacement)) {
                     break;
                 }
             }
             if ($escape == true) {
                 $replacement = urlencode($replacement);
             }
             $value = str_replace($source, $replacement, $value);
         }
     }
     return $value;
 }
开发者ID:bauhouse,项目名称:Piano-Sonata,代码行数:64,代码来源:class.datasource.php


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