예제 #1
0
 /**
  * @param  string $value
  * @return mixed
  * @throws UnsetGlobalException
  * @throws \Exception
  */
 public static function handleArrayVariable($value)
 {
     $isLiteral = (string) (int) $value == $value || in_array((string) $value[0], ['\'', '"']);
     $unquoted = trim($value, '\'"');
     if ($isLiteral) {
         return $unquoted;
     }
     return Globals::get($unquoted);
 }
예제 #2
0
 /**
  * Replace incline and full replace key inside a test object
  * @param object|array $inputObject
  * @return object|array
  * @todo add special exception, when global is not found test should
  * be ignored with special warning (EG unavailable)
  */
 private function searchAndReplace($inputObject)
 {
     if (is_object($inputObject)) {
         $object = clone $inputObject;
     } else {
         $object = $inputObject;
     }
     $pattern_replace = Expression::getExpression(Expression::EXPRESSION_TYPE_REPLACE);
     $pattern_inline_replace = Expression::getExpression(Expression::EXPRESSION_TYPE_INLINE_REPLACE);
     list($prefix, $suffix) = Expression::getPrefixSuffix(Expression::EXPRESSION_TYPE_INLINE_REPLACE);
     foreach ($object as $key => &$value) {
         if (is_array($value) || is_object($value)) {
             $value = $this->searchAndReplace($value);
         }
         if (is_string($value)) {
             $matches = [];
             //Complete replace
             if (!!preg_match($pattern_replace, $value, $matches)) {
                 $globalsKey = $matches['value'];
                 //replace
                 $value = Globals::get($globalsKey);
             } elseif (!!preg_match_all($pattern_inline_replace, $value, $matches)) {
                 //Foreach variable replace in string
                 foreach ($matches['value'] as $globalsKey) {
                     $value = str_replace($prefix . $globalsKey . $suffix, Globals::get($globalsKey), $value);
                 }
             }
         }
     }
     return $object;
 }