Jackalope\Node::filterNames PHP Method

filterNames() protected static method

Filter the list of names according to the filter expression / array
protected static filterNames ( string | array $filter, array $names ) : array
$filter string | array according to getNodes|getProperties
$names array list of names to filter
return array the names in $names that match the filter
    protected static function filterNames($filter, $names)
    {
        if ($filter !== null) {
            $filtered = array();
            $filter = (array) $filter;
            foreach ($filter as $k => $f) {
                $f = trim($f);
                $filter[$k] = strtr($f, array('*' => '.*', '.' => '\\.', '\\' => '\\\\', '{' => '\\{', '}' => '\\}', '(' => '\\(', ')' => '\\)', '+' => '\\+', '^' => '\\^', '$' => '\\$'));
            }
            foreach ($names as $name) {
                foreach ($filter as $f) {
                    if (preg_match('/^' . $f . '$/', $name)) {
                        $filtered[] = $name;
                    }
                }
            }
        } else {
            $filtered = $names;
        }
        return $filtered;
    }