getValue() public static méthode

public static getValue ( $collection, $key, $magicIsAllowed = false )
 /**
  * @param $collection
  * @return array
  */
 public function filter($collection)
 {
     $return = [];
     foreach ($this->token->value as $index) {
         if (AccessHelper::keyExists($collection, $index, $this->magicIsAllowed)) {
             $return[] = AccessHelper::getValue($collection, $index, $this->magicIsAllowed);
         }
     }
     return $return;
 }
Exemple #2
0
 /**
  * @param array $collection
  * @return array
  */
 public function filter($collection)
 {
     if (AccessHelper::keyExists($collection, $this->token->value, $this->magicIsAllowed)) {
         return array(AccessHelper::getValue($collection, $this->token->value, $this->magicIsAllowed));
     } else {
         if ($this->token->value === "*") {
             return AccessHelper::arrayValues($collection);
         }
     }
     return array();
 }
 /**
  * @param array $collection
  * @throws \Exception
  * @return array
  */
 public function filter($collection)
 {
     $return = [];
     preg_match('/^' . static::MATCH_QUERY_OPERATORS . '$/x', $this->token->value, $matches);
     if (!isset($matches[1])) {
         throw new \Exception("Malformed filter query");
     }
     $key = $matches['key'] ?: $matches['keySquare'];
     if ($key === "") {
         throw new \Exception("Malformed filter query: key was not set");
     }
     $operator = isset($matches['operator']) ? $matches['operator'] : null;
     $comparisonValue = isset($matches['comparisonValue']) ? $matches['comparisonValue'] : null;
     if (strtolower($comparisonValue) === "false") {
         $comparisonValue = false;
     }
     if (strtolower($comparisonValue) === "true") {
         $comparisonValue = true;
     }
     if (strtolower($comparisonValue) === "null") {
         $comparisonValue = null;
     }
     $comparisonValue = preg_replace('/^[\'"]/', '', $comparisonValue);
     $comparisonValue = preg_replace('/[\'"]$/', '', $comparisonValue);
     foreach ($collection as $value) {
         if (AccessHelper::keyExists($value, $key, $this->magicIsAllowed)) {
             $value1 = AccessHelper::getValue($value, $key, $this->magicIsAllowed);
             if ($operator === null && AccessHelper::keyExists($value, $key, $this->magicIsAllowed)) {
                 $return[] = $value;
             }
             if (($operator === "=" || $operator === "==") && $value1 == $comparisonValue) {
                 $return[] = $value;
             }
             if (($operator === "!=" || $operator === "!==" || $operator === "<>") && $value1 != $comparisonValue) {
                 $return[] = $value;
             }
             if ($operator == ">" && $value1 > $comparisonValue) {
                 $return[] = $value;
             }
             if ($operator == "<" && $value1 < $comparisonValue) {
                 $return[] = $value;
             }
         }
     }
     return $return;
 }
 /**
  * @param array $collection
  * @return array
  */
 public function filter($collection)
 {
     $result = array();
     preg_match('/@\\.(?<key>\\w+)\\s*(?<operator>-|\\+|\\*|\\/)\\s*(?<numeric>\\d+)/', $this->token->value, $matches);
     $matchKey = $matches['key'];
     if (AccessHelper::keyExists($collection, $matchKey, $this->magicIsAllowed)) {
         $value = AccessHelper::getValue($collection, $matchKey, $this->magicIsAllowed);
     } else {
         if ($matches['key'] === 'length') {
             $value = count($collection);
         } else {
             return;
         }
     }
     switch ($matches['operator']) {
         case '+':
             $resultKey = $value + $matches['numeric'];
             break;
         case '*':
             $resultKey = $value * $matches['numeric'];
             break;
         case '-':
             $resultKey = $value - $matches['numeric'];
             break;
         case '/':
             $resultKey = $value / $matches['numeric'];
             break;
         default:
             throw new JSONPathException("Unsupported operator in expression");
             break;
     }
     if (AccessHelper::keyExists($collection, $resultKey, $this->magicIsAllowed)) {
         $result[] = AccessHelper::getValue($collection, $resultKey, $this->magicIsAllowed);
     }
     return $result;
 }
Exemple #5
0
 public function offsetGet($offset)
 {
     $value = AccessHelper::getValue($this->data, $offset);
     return AccessHelper::isCollectionType($value) ? new static($value, $this->options) : $value;
 }