<commit_before><?php

require_once(dirname(__file__) . '/../lib/kirby/kirby.php');
require_once(dirname(__file__) . '/../lib/kirby/plugins/twig.php');
require_once(dirname(__file__) . '/autoloader.php');

class Dispatcher {
  private static $instance = null;
  private static $config = null;
  
  private function __construct() {
    spl_autoload_register('AutoLoader::auto_load');
    set_exception_handler('ErrorHandler::handle_error');
    
    $config = Config::getInstance();
    if($config->get('db.name', null) != null) {
      foreach(array('db.host', 'db.user', 'db.password', 'db.name') as $key) {
        c::set($key, $config->get($key, ''));
      }
    }
    
    c::set('twig.root', realpath(dirname(__file__) . '/../templates'));
    c::set('twig.debug', $config->get('debug', false));
  }
  
  static function getInstance() {
    if(self::$instance === null) {
      self::$instance = new self;
    }
    return self::$instance;
  }
  
  public function dispatch($uri) {
    require_once(dirname(__file__) . '/../config/urls.php');
    
    $responder_class = null;
    $params = array();
    foreach($urlpattern as $regex => $class) {
      if(preg_match($regex, $uri, $matches)) {
        $responder_class = $class;
        for($i = 1; $i < count($matches); $i++) { $params[] = $matches[$i]; }
		break;
      }
    }
    
    // If its not possible to determine which class to load, just do an 404
    if($responder_class == null) {
      $responder_class = 'Error404';
    }
    
    // If the defined class does not match PHP class guidelines throw an exception
    if(!preg_match('/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/', $responder_class)) {
      throw new DispatcherException('No valid responder defined for /' . $module . '/' . $action);
    }
    
    // If the class does not exist throw an exception
    if(class_exists($responder_class, true)) {
      $responder = new $responder_class();
      $method = strtolower($_SERVER['REQUEST_METHOD']);
      if(method_exists($responder, $method)) {
        $responder->$method($params);
      } else {
        throw new DispatcherException('Method ' . $method . ' is not valid for ' . $responder_class);
      }
    } else {
      throw new DispatcherException('Handler class ' . $responder_class . ' for uri ' . $uri . ' not found!');
    }
  }
  
}

class DispatcherException extends Exception {}<commit_msg>Workaround for broken ini parser<commit_after><?php

require_once(dirname(__file__) . '/../lib/kirby/kirby.php');
require_once(dirname(__file__) . '/../lib/kirby/plugins/twig.php');
require_once(dirname(__file__) . '/autoloader.php');

class Dispatcher {
  private static $instance = null;
  private static $config = null;
  
  private function __construct() {
    spl_autoload_register('AutoLoader::auto_load');
    set_exception_handler('ErrorHandler::handle_error');
    
    $config = Config::getInstance();
    if($config->get('db.name', null) != null) {
      foreach(array('db.host', 'db.user', 'db.password', 'db.name') as $key) {
        c::set($key, $config->get($key, ''));
      }
    }
    
    c::set('twig.root', realpath(dirname(__file__) . '/../templates'));
    c::set('twig.debug', $config->get('debug', 0) == 1);
  }
  
  static function getInstance() {
    if(self::$instance === null) {
      self::$instance = new self;
    }
    return self::$instance;
  }
  
  public function dispatch($uri) {
    require_once(dirname(__file__) . '/../config/urls.php');
    
    $responder_class = null;
    $params = array();
    foreach($urlpattern as $regex => $class) {
      if(preg_match($regex, $uri, $matches)) {
        $responder_class = $class;
        for($i = 1; $i < count($matches); $i++) { $params[] = $matches[$i]; }
		break;
      }
    }
    
    // If its not possible to determine which class to load, just do an 404
    if($responder_class == null) {
      $responder_class = 'Error404';
    }
    
    // If the defined class does not match PHP class guidelines throw an exception
    if(!preg_match('/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/', $responder_class)) {
      throw new DispatcherException('No valid responder defined for /' . $module . '/' . $action);
    }
    
    // If the class does not exist throw an exception
    if(class_exists($responder_class, true)) {
      $responder = new $responder_class();
      $method = strtolower($_SERVER['REQUEST_METHOD']);
      if(method_exists($responder, $method)) {
        $responder->$method($params);
      } else {
        throw new DispatcherException('Method ' . $method . ' is not valid for ' . $responder_class);
      }
    } else {
      throw new DispatcherException('Handler class ' . $responder_class . ' for uri ' . $uri . ' not found!');
    }
  }
  
}

class DispatcherException extends Exception {}
{'fraction_non_alphanumeric': 0.16986644407345575, 'fraction_numerical': 0.005008347245409015, 'mean_word_length': 3.0041771094402674, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, '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': '7019095', 'n_tokens_mistral': 1556, 'n_tokens_neox': 1540, 'n_words': 331}