Example #1
0
 /** Performs matching on paths specified by arrays or objects.
  * @internal **/
 private static function _extractPaths($node, $paths, $context)
 {
     $return = array();
     foreach ($paths as $key => $val) {
         if (is_int($key)) {
             // merge into current level
             $x = Matcher::_evalPath($node, $val, $context);
             if (is_scalar($x) || $x === null) {
                 throw new \Exception("Cannot merge scalar value" . (is_string($val) ? " produced by path `{$val}`" : "") . " Expected array or object.");
             }
             if (is_object($x)) {
                 $x = (array) $x;
             }
             $return = array_merge($return, $x);
         } else {
             $return[$key] = Matcher::_evalPath($node, $val, $context);
         }
     }
     return is_object($paths) ? (object) $return : $return;
 }