Habari\Theme::check_scope_criteria PHP Метод

check_scope_criteria() публичный Метод

Matches the scope criteria against the current request
public check_scope_criteria ( array $criteria ) : boolean
$criteria array An array of scope criteria data in RPN, where values are arrays and operators are strings
Результат boolean True if the criteria matches the current request
    function check_scope_criteria($criteria)
    {
        $stack = array();
        foreach ($criteria as $crit) {
            if (is_array($crit)) {
                $value = false;
                switch ($crit[0]) {
                    case 'request':
                        $value = URL::get_matched_rule()->name == $crit[1];
                        break;
                    case 'token':
                        if (isset($crit[2])) {
                            $value = User::identify()->can($crit[1], $crit[2]);
                        } else {
                            $value = User::identify()->can($crit[1]);
                        }
                        break;
                    default:
                        $value = Plugins::filter('scope_criteria_value', $value, $crit[1], $crit[2]);
                        break;
                }
                $stack[] = $value;
            } else {
                switch ($crit) {
                    case 'not':
                        $stack[] = !array_pop($stack);
                        break;
                    case 'or':
                        $value1 = array_pop($stack);
                        $value2 = array_pop($stack);
                        $stack[] = $value1 || $value2;
                        break;
                    case 'and':
                        $value1 = array_pop($stack);
                        $value2 = array_pop($stack);
                        $stack[] = $value1 && $value2;
                        break;
                    default:
                        Plugins::act('scope_criteria_operator', $stack, $crit);
                        break;
                }
            }
        }
        return array_pop($stack);
    }