<commit_before><?php
/*
 * Limb PHP Framework
 *
 * @link http://limb-project.com
 * @copyright  Copyright &copy; 2004-2009 BIT(http://bit-creative.com)
 * @license    LGPL http://www.gnu.org/copyleft/lesser.html
 */
lmb_require('limb/web_app/src/request/lmbRequestDispatcher.interface.php');
lmb_require('limb/filter_chain/src/lmbInterceptingFilter.interface.php');

/**
 * class lmbRequestDispatchingFilter.
 *
 * @package web_app
 * @version $Id: lmbRequestDispatchingFilter.class.php 7486 2009-01-26 19:13:20Z pachanga $
 */
class lmbRequestDispatchingFilter implements lmbInterceptingFilter
{
  protected $toolkit;
  protected $dispatcher;
  protected $default_controller_name;

  function __construct($dispatcher, $default_controller_name = 'not_found')
  {
    $this->toolkit = lmbToolkit :: instance();
    $this->dispatcher = $dispatcher;
    $this->setDefaultControllerName($default_controller_name);
  }

  function setDefaultControllerName($default_controller_name)
  {
    $this->default_controller_name = $default_controller_name;
  }

  function run($filter_chain)
  {
    $dispatched_params = $this->dispatcher->dispatch($this->toolkit->getRequest());

    $this->_putOtherParamsToRequest($dispatched_params);

    $controller = $this->_createController($dispatched_params);

    if(isset($dispatched_params['action']) && $controller->actionExists($dispatched_params['action']))
      $controller->setCurrentAction($dispatched_params['action']);
    elseif(!isset($dispatched_params['action']))
      $controller->setCurrentAction($controller->getDefaultAction());
    else
      $controller = $this->_createDefaultController();

    $this->toolkit->setDispatchedController($controller);

    $filter_chain->next();
  }

  protected function _createController($dispatched_params)
  {
    if(!isset($dispatched_params['controller']))
      $dispatched_params['controller'] = $this->default_controller_name;

    try
    {
      $controller = $this->toolkit->createController($dispatched_params['controller']);
    }
    catch(lmbException $e)
    {
      $controller = $this->toolkit->createController($this->default_controller_name);
    }

    return $controller;
  }
<commit_msg>-- Increase selectivity of exception catching<commit_after><?php
/*
 * Limb PHP Framework
 *
 * @link http://limb-project.com
 * @copyright  Copyright &copy; 2004-2009 BIT(http://bit-creative.com)
 * @license    LGPL http://www.gnu.org/copyleft/lesser.html
 */
lmb_require('limb/web_app/src/request/lmbRequestDispatcher.interface.php');
lmb_require('limb/filter_chain/src/lmbInterceptingFilter.interface.php');

/**
 * class lmbRequestDispatchingFilter.
 *
 * @package web_app
 * @version $Id: lmbRequestDispatchingFilter.class.php 7486 2009-01-26 19:13:20Z pachanga $
 */
class lmbRequestDispatchingFilter implements lmbInterceptingFilter
{
  protected $toolkit;
  protected $dispatcher;
  protected $default_controller_name;

  function __construct($dispatcher, $default_controller_name = 'not_found')
  {
    $this->toolkit = lmbToolkit :: instance();
    $this->dispatcher = $dispatcher;
    $this->setDefaultControllerName($default_controller_name);
  }

  function setDefaultControllerName($default_controller_name)
  {
    $this->default_controller_name = $default_controller_name;
  }

  function run($filter_chain)
  {
    $dispatched_params = $this->dispatcher->dispatch($this->toolkit->getRequest());

    $this->_putOtherParamsToRequest($dispatched_params);

    $controller = $this->_createController($dispatched_params);

    if(isset($dispatched_params['action']) && $controller->actionExists($dispatched_params['action']))
      $controller->setCurrentAction($dispatched_params['action']);
    elseif(!isset($dispatched_params['action']))
      $controller->setCurrentAction($controller->getDefaultAction());
    else
      $controller = $this->_createDefaultController();

    $this->toolkit->setDispatchedController($controller);

    $filter_chain->next();
  }

  protected function _createController($dispatched_params)
  {
    if(!isset($dispatched_params['controller']))
      $dispatched_params['controller'] = $this->default_controller_name;

    try
    {
      $controller = $this->toolkit->createController($dispatched_params['controller']);
    }
    catch(lmbFileNotFoundException $e)
    {
      $controller = $this->_createDefaultController();
    }

    return $controller;
  }

{'fraction_non_alphanumeric': 0.13909689130928068, 'fraction_numerical': 0.011799410029498525, 'mean_word_length': 5.156424581005586, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6742249', 'n_tokens_mistral': 1380, 'n_tokens_neox': 1321, 'n_words': 171}