PHP Classes

File: src/Filters/IndexesFilter.php

Recommend this page to a friend!
  Classes of Sascha Greuel   PHP JSON Path   src/Filters/IndexesFilter.php   Download  
File: src/Filters/IndexesFilter.php
Role: Class source
Content type: text/plain
Description: Class source
Class: PHP JSON Path
Query values from data structures like XPATH
Author: By
Last change:
Date: 3 years ago
Size: 676 bytes
 

Contents

Class file image Download
<?php

/**
 * JSONPath implementation for PHP.
 *
 * @license https://github.com/SoftCreatR/JSONPath/blob/main/LICENSE MIT License
 */

declare(strict_types=1);

namespace
Flow\JSONPath\Filters;

use
Flow\JSONPath\AccessHelper;

class
IndexesFilter extends AbstractFilter
{
   
/**
     * @inheritDoc
     */
   
public function filter($collection): array
    {
       
$return = [];

        foreach (
$this->token->value as $index) {
            if (
AccessHelper::keyExists($collection, $index, $this->magicIsAllowed)) {
               
$return[] = AccessHelper::getValue($collection, $index, $this->magicIsAllowed);
            }
        }

        return
$return;
    }
}