<commit_before><?php

/**
 * flexRouter - a small, lightweight php-router for clean, restful urls. Extremely easy to setup and configure.
 * Supports setting up routes based on their mode (GET, POST). E.x: GET /user/:id/profile or POST /user/:id:/update-profile
 * Now supports wildcards aswell. E.g. /picture/:id/edit*
 * @author <NAME> <<EMAIL>>
 * @version 1.4 03.06.2016
 */
class flexRouter {

  public $mode;
  public $params;
  public $dynParams;
  public $basePath;

  private $pathCt = 0;

  public function __construct() {

    // Determine the path
    if (!isset($_GET['path'])) $_GET['path'] = '';
    $this->params = explode('/', $_GET['path']);
    $this->pathCt = count($this->params);

    for ($i = 0; $i < $this->pathCt - 1; $i++) {
      $this->basePath .= '../';
    }

    // Determine the mode
    $this->mode = (empty($_POST) ? 'GET' : 'POST');
  }

  /**
   * Mode: GET/POST
   * Pattern: /users/:id/update
   */
  public function route($mode, $pattern) {
    $this->dynParams = array();

    // Validate mode
    if (is_array($mode)) {
      $modeValid = false;
      for ($i = 0; $i < count($mode); $i++) {
        $cM = $mode[$i];
        if (strtolower($cM) == strtolower($this->mode)) $modeValid = true;
        if ($modeValid) break;
      }
      if (!$modeValid) return false;
    } else {
      if (strtolower($mode) != strtolower($this->mode)) return false;
    }

    // Validate pattern
    $wildCard = (substr($pattern, -1) == "*" ? true : false);
    if ($wildCard) $pattern = substr($pattern, 0, strlen($pattern) - 1);

    $routePattern = explode('/', $pattern);
    if (empty($routePattern[0])) unset($routePattern[0]);
    $routePattern = array_values($routePattern);
    $routePatternCt = count($routePattern);

    $validWildCard = ($wildCard && $this->pathCt >= $routePatternCt);
    if (!$validWildCard && ($routePatternCt != $this->pathCt)) return false;


    for ($i = 0; $i < $routePatternCt; $i++) {
        $patternElement = $routePattern[$i];
      if ($patternElement[0] == ':') {
        $this->dynParams[$patternElement] = $this->params[$i];
        continue;
      }

      if ($patternElement != $this->params[$i]) return false;
      // end of routePattern-loop
    }

    return true;

    // end route-function
  }

  public function param($tag) {
    return $this->dynParams[$tag];
  }

  // end flexRouter
}

?><commit_msg>includes routed-var<commit_after><?php
/**
 * flexRouter - a small, lightweight php-router for clean, restful urls. Extremely easy to setup and configure.
 * Supports setting up routes based on their mode (GET, POST). E.x: GET /user/:id/profile or POST /user/:id:/update-profile
 * Now supports wildcards aswell. E.g. /picture/:id/edit*
 * @author <NAME> <<EMAIL>>
 * @version 1.5 15.06.2016
 */
class flexRouter {
    public $mode;
    public $params;
    public $dynParams;
    public $basePath;
    private $pathCt = 0;

    public $routed = false;

    public function __construct() {
        // Determine the path
        if (!isset($_GET['path'])) $_GET['path'] = '';
        $this->params = explode('/', $_GET['path']);
        $this->pathCt = count($this->params);
        for ($i = 0; $i < $this->pathCt - 1; $i++) {
            $this->basePath .= '../';
        }
        // Determine the mode
        $this->mode = (empty($_POST) ? 'GET' : 'POST');
    }
    /**
     * Mode: GET/POST
     * Pattern: /users/:id/update
     */
    public function route($mode, $pattern) {
        $this->dynParams = array();
        // Validate mode
        if (is_array($mode)) {
            $modeValid = false;
            for ($i = 0; $i < count($mode); $i++) {
                $cM = $mode[$i];
                if (strtolower($cM) == strtolower($this->mode)) $modeValid = true;
                if ($modeValid) break;
            }
            if (!$modeValid) return false;
        } else {
            if (strtolower($mode) != strtolower($this->mode)) return false;
        }
        // Validate pattern
        $wildCard = (substr($pattern, -1) == "*" ? true : false);
        if ($wildCard) $pattern = substr($pattern, 0, strlen($pattern) - 1);
        $routePattern = explode('/', $pattern);
        if (empty($routePattern[0])) unset($routePattern[0]);
        $routePattern = array_values($routePattern);
        $routePatternCt = count($routePattern);
        $validWildCard = ($wildCard && $this->pathCt >= $routePatternCt);
        if (!$validWildCard && ($routePatternCt != $this->pathCt)) return false;
        for ($i = 0; $i < $routePatternCt; $i++) {
            $patternElement = $routePattern[$i];
            if ($patternElement[0] == ':') {
                $this->dynParams[$patternElement] = $this->params[$i];
                continue;
            }
            if ($patternElement != $this->params[$i]) return false;
            // end of routePattern-loop
        }
        $this->routed = true;
        return true;
        // end route-function
    }
    public function param($tag) {
        return $this->dynParams[$tag];
    }
    // end flexRouter
}
?>
{'fraction_non_alphanumeric': 0.17910742496050552, 'fraction_numerical': 0.008293838862559242, 'mean_word_length': 2.387959866220736, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5724936', 'n_tokens_mistral': 1651, 'n_tokens_neox': 1568, 'n_words': 394}