Check rule switch

@param  string $rule - rule to check
@param  string $path - path to check
@return bool
346842
protected function checkRuleSwitch($rule, $path)
    {
        switch ($this->isInlineDirective($rule)) {
            case self::DIRECTIVE_CLEAN_PARAM:
                if ($this->checkCleanParamRule($this->stripInlineDirective($rule), $path)) {
                    return true;
                }
                break;
            case self::DIRECTIVE_HOST;
                if ($this->checkHostRule($this->stripInlineDirective($rule))) {
                    return true;
                }
                break;
            default:
                if ($this->checkBasicRule($rule, $path)) {
                    return true;
                }
        }
        return false;
    }
1129836
public function isBoolean($path)
    {
        $value = $this->get($path, $this);

        return $value === $this ? false : is_bool($value);
    }
1272560
public function match($path, $method, $action = null)
    {
        $rule = new Rule\HttpMethodRule();
        $rule->setPath($path);
        $rule->setMethod($method);
        $rule->setAction($action);
        $this->rules[] = $rule;
        return $rule;
    }
211168
protected static function _execute($rule) {
		if (!isset($rule[2])) {
			$rule[2] = true;
		}

		if (!isset($rule[1])) {
			$rule[1] = array();
		}

		list($callback, $args, $successOn) = $rule;

		if (!is_callable($callback)) {
			if (is_array($callback)) {
				$callback = implode('::', $callback);
			}
			throw new CommonRevealException(__d('common', "Callback '%s()' is not defined.", $callback));
		}

		if (!is_array($args)) {
			$args = array($args);
		}

		if (count($args)) {
			$result = call_user_func_array($callback, $args);
		} else {
			$result = call_user_func($callback);
		}

		if (is_array($successOn)) {
			return in_array($result, $successOn);
		} else {
			return $result == $successOn;
		}
	}
846123
protected function __checkRule($rule) {
        $fields = explode(',', $rule[0]);
        if (is_string($rule[1])) {
            $conditions = explode(',', $rule[1]);
            foreach ($conditions as $k => $item) {
                $item = trim($item);
                $conditions[$k] = isset($this->aliases[$item]) ? $this->aliases[$item] : $item;
            }
        } else {
            $conditions = array($rule[1]);
        }
        $valid = true;
        foreach ($conditions as $condition) {
            foreach ($fields as $field) {
                $field = trim($field);
                $label = isset($this->labels[$field]) ? $this->labels[$field] : ucwords(str_replace('_', ' ', $field));
                $errorMessage = isset($rule['message']) ? $this->translate(str_replace(array('__VALUE__', '__LABEL__'), array((!is_null($this->getValue($field))) ? $this->getValue($field) : ' - no value -', $label), $rule['message'])) : null;
                if ('required' == $condition && ((is_null($this->getValue($field))) || (is_array($this->getValue($field)) && !count($this->getValue($field))) || (is_string($this->getValue($field)) && '' == trim($this->getValue($field))))) {
                    if (!isset($this->errors[$field])) {
                        $this->errors[$field] = array();
                    }
                    $this->errors[$field][] = $errorMessage ? $errorMessage : $this->translate($label . ' is required!');
                    $valid = false; // if it's required but not defined then the rule it's not valid.
                    continue;
                } elseif (is_null($fieldValue = $this->getValue($field)) || (is_array($fieldValue) ? !count($fieldValue) : !trim($fieldValue))) { // if it's not required and not defined then there is nothing to check
                    if (isset($rule['default_value'])){
                        $this->setValue($field, $rule['default_value']);
                    }
                    continue;
                }
                if ('required' == $condition || 'safe' == $condition) { // skip required as it was checked above also skip safe as it is a model condition and not implemented here
                    continue;
                }
                try {
                    // actually check conditions here (except for required which is an exception from the rule
                    if (is_string($condition)) { // check local condition
                        $valid = $valid && $this->{'filter' . ucwords($condition)}($field, $rule, $label, $errorMessage);
                    } elseif (is_callable($condition)) { // check method condition
                        $valid = $valid && $condition($this, $field, $rule, $label, $errorMessage);
                    }
                } catch (\Exception $e) {
                    $valid = false;
                    if (!isset($this->errors[$field])) {
                        $this->errors[$field] = array();
                    }
                    $this->errors[$field][] = is_array($e) ? $e['message'] : $e->getMessage();
                }
            }
        }
        return $valid;
    }
793260
public function isValidPath($path)
    {
        $isValidPath = false;

        $pathValue = $this->getValueByPath($path);
        if (!is_null($pathValue)) {
            $isValidPath = true;
        }

        return $isValidPath;
    }
695238
public function has ($path) {
		try {
			$this -> get($path);
			return true;
		} catch (InvalidKeyException $e) {
			return false;
		} catch (NonExistentKeyException $e) {
			return false;
		}
	}
669931
public static function isAbsolutePath($path)
    {
        if (isset($path[0]) and ($path[0] == '/' or $path[0] == '\\')) {
            return true;
        }
        if (preg_match('/^[A-Za-z0-9]+:/', $path) === 1) {
            return true;
        }
        return false;
    }
1320819
private function checkPaths($path, array $paths)
    {
        $reserved = [
            '?' => '\?',
            '.' => '\.',
            '*' => '.*',
            '+' => '\+',
            '(' => '\(',
            ')' => '\)',
            '[' => '\[',
            ']' => '\]',
        ];
        $errorHandler = new ErrorHandler();
        set_error_handler([$errorHandler, 'callback'], E_NOTICE | E_WARNING);
        foreach ($paths as $rule) {
            $escaped = str_replace(array_keys($reserved), array_values($reserved), $rule);
            if (preg_match('#^' . $escaped . '#', $path) === 1) {
                restore_error_handler();
                return mb_strlen($rule);
            }
        }
        restore_error_handler();
        return false;
    }
1178649
public function removeRule($field, $rule)
    {
        if (isset($this->rules[$field][$rule])) {
            unset($this->rules[$field][$rule]);
            return true;
        }
        return false;
    }
416483
public function setRule($rule, $route)
    {
        $this->rule[$route->getDomain()][$rule][$route->getMethod()] = $route;
    }
811666
private function validatePath($path)
    {
        $last = strlen($path)-1;
        if ($path[$last] == '/') {
            $path = substr($path, 0, -1);
        }
        return $path;
    }
155122
public function checkPath($path = null)
  {
    if($path === null)
    {
      $path = $this->path;
    }

    if(strlen($path) == 0)
    {
      return TRUE;
    }

    $pattern = "/^" . $this->regex["path"] . "$/";
    $status = @preg_match($pattern, $path);

    if($status === FALSE)
    {
      throw new Exception("URI path validation failed");
    }

    return ($status == 1);
  }
1147824
protected function doMatch($pattern, $path, $fullMatch)
    {

        if (($pattern[0] == '/') != ($path[0] == '/')) {
            return false;
        }
        if ('/' == substr($pattern, '-1')) {
            $pattern .= '**';
        }

        $pattDirs = $this->tokenizeToStringArray($pattern);
        $pathDirs = $this->tokenizeToStringArray($path);

        $pattIdxStart = 0;
        $pattIdxEnd = count($pattDirs) - 1;
        $pathIdxStart = 0;
        $pathIdxEnd = count($pathDirs) - 1;

        // Match all elements up to the first **
        while ($pattIdxStart <= $pattIdxEnd and $pathIdxStart <= $pathIdxEnd) {
            $patDir = $pattDirs[$pattIdxStart];
            if ('**' == $patDir) {
                break;
            }
            if (!$this->matchStrings($patDir, $pathDirs[$pathIdxStart])) {
                return false;
            }
            $pattIdxStart++;
            $pathIdxStart++;
        }

        if ($pathIdxStart > $pathIdxEnd) {
            // Path is exhausted, only match if rest of pattern is * or **'s
            if ($pattIdxStart > $pattIdxEnd) {
                return ('/' == substr($pattern, '-1') ? '/' == substr($path, '-1') :
                        !('/' == substr($path, '-1')));
            }
            if (!$fullMatch) {
                return true;
            }
            if ($pattIdxStart == $pattIdxEnd and '*' == $pattDirs[$pattIdxStart] and '/' == substr($path, -1)) {
                return true;
            }
            for ($i = $pattIdxStart; $i <= $pattIdxEnd; $i++) {
                if (!'**' == $pattDirs[$i]) {
                    return false;
                }
            }

            return false;
        } elseif ($pattIdxStart > $pattIdxEnd) {
            // String not exhausted, but pattern is. Failure.
            return false;
        } elseif (!$fullMatch and "**" == $pattDirs[$pattIdxStart]) {
            // Path start definitely matches due to "**" part in pattern.
            return true;
        }

        // up to last '**'
        while ($pattIdxStart <= $pattIdxEnd and $pathIdxStart <= $pathIdxEnd) {
            $patDir = $pattDirs[$pattIdxEnd];
            if ('**' == $patDir) {
                break;
            }
            if (!$this->matchStrings($patDir, $pathDirs[$pathIdxEnd])) {
                return false;
            }
            $pattIdxEnd--;
            $pathIdxEnd--;
        }
        if ($pathIdxStart > $pathIdxEnd) {
            // String is exhausted
            for ($i = $pattIdxStart; $i <= $pattIdxEnd; $i++) {
                if (!('**' == $pattDirs[$i])) {
                    return false;
                }
            }

            return true;
        }

        while ($pattIdxStart != $pattIdxEnd and $pathIdxStart <= $pathIdxEnd) {
            $patIdxTmp = -1;
            for ($i = $pattIdxStart + 1; $i <= $pattIdxEnd; $i++) {
                if ('**' == $pattDirs[$i]) {
                    $patIdxTmp = $i;
                    break;
                }
            }
            if ($patIdxTmp == $pattIdxStart + 1) {
                // '**/**' situation, so skip one
                $pattIdxStart++;
                continue;
            }

            // Find the pattern between padIdxStart & padIdxTmp in str between
            // strIdxStart & strIdxEnd
            $patLength = ($patIdxTmp - $pattIdxStart - 1);
            $strLength = ($pathIdxEnd - $pathIdxStart + 1);
            $foundIdx = -1;

            for ($i = 0; $i <= $strLength - $patLength; $i++) {
                for ($j = 0; $j < $patLength; $j++) {
                    $subPat = $pattDirs[$pattIdxStart + $j + 1];
                    $subStr = $pathDirs[$pathIdxStart + $i + $j];
                    if (!$this->matchStrings($subPat, $subStr)) {
                        continue 2;
                    }
                }
                $foundIdx = $pathIdxStart + $i;
                break;
            }

            if ($foundIdx == -1) {
                return false;
            }

            $pattIdxStart = $patIdxTmp;
            $pathIdxStart = $foundIdx + $patLength;

        }

        for ($i = $pattIdxStart; $i <= $pattIdxEnd; $i++) {
            if (!'**' == $pattDirs[$i]) {
                return false;
            }
        }

        return true;

    }
359352
private function validateIncludeRegex(string $path): bool
    {
        $includeRegex = $this->config->getIncludeRegex();
        return $includeRegex === null || Validator::regex($includeRegex)->validate($path) === true;
    }
556611
public function mkdir($path)
	{
		// If native FTP support is enabled let's use it...
		if (FTP_NATIVE)
		{
			if (@ftp_mkdir($this->conn, $path) === false)
			{
				Log::add(__METHOD__ . 'Bad response.', Log::WARNING, 'jerror');

				return false;
			}

			return true;
		}

		// Send change directory command and verify success
		if (!$this->_putCmd('MKD ' . $path, 257))
		{
			Log::add(
				sprintf('%1$s: Bad response.  Server response: %2$s [Expected: 257].  Path sent: %3$s', __METHOD__, $this->response, $path),
				Log::WARNING, 'jerror'
			);

			return false;
		}

		return true;
	}
111167
public function validatePath($path = null)
    {
        if ($path === null) {
            $path = $this->_path;
        }

        // If the path is empty, then it is considered valid
        if (strlen($path) === 0) {
            return true;
        }

        // Determine whether the path is well-formed
        $pattern = '/^' . $this->_regex['path'] . '$/';
        $status  = @preg_match($pattern, $path);
        if ($status === false) {
            require_once 'Zend/Uri/Exception.php';
            throw new Zend_Uri_Exception('Internal error: path validation failed');
        }

        return (boolean) $status;
    }