<commit_before><?php

/*
 * This file is part of the symfony package.
 * (c) 2004, 2005 <NAME> <<EMAIL>>
 * (c) 2004, 2005 <NAME>.
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/**
 * sfExecutionFilter is the last filter registered for each filter chain. This
 * filter does all action and view execution.
 *
 * @package    symfony
 * @subpackage filter
 * @author     <NAME> <<EMAIL>>
 * @author     <NAME> <<EMAIL>>
 * @version    SVN: $Id$
 */
class sfExecutionFilter extends sfFilter
{
  /**
   * Execute this filter.
   *
   * @param sfFilterChain The filter chain.
   *
   * @return void
   *
   * @throws <b>sfInitializeException</b> If an error occurs during view initialization.
   * @throws <b>sfViewException</b>       If an error occurs while executing the view.
   */
  public function execute ($filterChain)
  {
    // get the context and controller
    $context    = $this->getContext();
    $controller = $context->getController();

    // create validator manager
    $validatorManager = new sfValidatorManager();
    $validatorManager->initialize($context);

    // get the current action instance
    $actionEntry    = $controller->getActionStack()->getLastEntry();
    $actionInstance = $actionEntry->getActionInstance();

    // get the current action information
    $moduleName = $context->getModuleName();
    $actionName = $context->getActionName();

    // get the request method
    $method = $context->getRequest()->getMethod();

    if (($actionInstance->getRequestMethods() & $method) != $method)
    {
      // this action will skip validation/execution for this method
      // get the default view
      $viewName = $actionInstance->getDefaultView();
    }
    else
    {
      // set default validated status
      $validated = true;

      // get the current action validation configuration
      $validationConfig = $moduleName.'/'.SF_APP_MODULE_VALIDATE_DIR_NAME.'/'.$actionName.'.yml';
      if (is_readable(SF_APP_MODULE_DIR.'/'.$validationConfig))
      {
        // load validation configuration
        // do NOT use require_once
        require(sfConfigCache::checkConfig(SF_APP_MODULE_DIR_NAME.'/'.$validationConfig));
      }

      // manually load validators
      $actionInstance->registerValidators($validatorManager);

      // process validators
      $validated = $validatorManager->execute();

      // process manual validation
      if ($validated && $actionInstance->validate())
      {
        // register our cache configuration
        if (SF_CACHE)
        {
          $cacheManager    = $context->getViewCacheManager();
          $cacheConfigFile = $moduleName.'/'.SF_APP_MODULE_CONFIG_DIR_NAME.'/cache.yml';
          if (is_readable(SF_APP_MODULE_DIR.'/'.$cacheConfigFile))
          {
            require(sfConfigCache::checkConfig(SF_APP_MODULE_DIR_NAME.'/'.$cacheConfigFile, array('moduleName' => $moduleName)));
          }

        }

        // page in cache?
        if (SF_CACHE && !count($_GET) && !count($_POST))
        {
          if (SF_DEBUG && $context->getRequest()->getParameter('ignore_cache', false, 'symfony/request/sfWebRequest') == true)
          {
            if (SF_LOGGING_ACTIVE) $context->getLogger()->info('{sfExecutionFilter} discard page cache');
          }
          else
          {
            // retrieve page content from cache
            $retval = $cacheManager->get(sfRouting::getInstance()->getCurrentInternalUri(), 'page');

            if (SF_LOGGING_ACTIVE) $context->getLogger()->info('{sfExecutionFilter} page cache '.($retval ? 'exists' : 'does not exist'));

            if ($retval !== null)
            {
              if ($controller->getRenderMode() == sfView::RENDER_VAR)
              {
                $actionEntry->setPresentation($retval);
              }
              else
              {
                // conditionnal get support
                // http://fishbowl.pastiche.org/archives/001132.html
                // http://simon.incutio.com/archive/2003/04/23/conditionalGet
                // http://lightpress.org/post/php-http11-dates-and-conditional-get/
                // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9
// FIXME: TBD
//                if (!$this->doConditionalGet(time()))
//                {
                  echo $retval;
//                }
              }

              // stop execution filter
              return;
            }
          }
        }

        // execute the action
        $actionInstance->preExecute();
        $viewName = $actionInstance->execute();
        if ($viewName == '')
        {
          $viewName = sfView::SUCCESS;
        }
        $actionInstance->postExecute();
      }
      else
      {
        if (SF_LOGGING_ACTIVE) $this->context->getLogger()->info('{sfExecutionFilter} action validation failed');

        // validation failed
        $viewName = $actionInstance->handleError();
      }
    }

    if ($viewName != sfView::NONE)
    {
      if (is_array($viewName))
      {
        // we're going to use an entirely different action for this view
        $moduleName = $viewName[0];
        $viewName   = $viewName[1];
      }
      else
      {
        // use a view related to this action
        $viewName = $actionName.$viewName;
      }

      // display this view
      if (!$controller->viewExists($moduleName, $viewName))
      {
        // the requested view doesn't exist
        $file = SF_APP_MODULE_DIR.'/'.$moduleName.'/'.SF_APP_MODULE_VIEW_DIR_NAME.'/'.$viewName.'View.class.php';

        $error = 'Module "%s" does not contain the view "%sView" or the file "%s" is unreadable';
        $error = sprintf($error, $moduleName, $viewName, $file);
<commit_msg>added action specific error handling<commit_after><?php

/*
 * This file is part of the symfony package.
 * (c) 2004, 2005 <NAME> <<EMAIL>>
 * (c) 2004, 2005 <NAME>.
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/**
 * sfExecutionFilter is the last filter registered for each filter chain. This
 * filter does all action and view execution.
 *
 * @package    symfony
 * @subpackage filter
 * @author     <NAME> <<EMAIL>>
 * @author     <NAME> <<EMAIL>>
 * @version    SVN: $Id$
 */
class sfExecutionFilter extends sfFilter
{
  /**
   * Execute this filter.
   *
   * @param sfFilterChain The filter chain.
   *
   * @return void
   *
   * @throws <b>sfInitializeException</b> If an error occurs during view initialization.
   * @throws <b>sfViewException</b>       If an error occurs while executing the view.
   */
  public function execute ($filterChain)
  {
    // get the context and controller
    $context    = $this->getContext();
    $controller = $context->getController();

    // create validator manager
    $validatorManager = new sfValidatorManager();
    $validatorManager->initialize($context);

    // get the current action instance
    $actionEntry    = $controller->getActionStack()->getLastEntry();
    $actionInstance = $actionEntry->getActionInstance();

    // get the current action information
    $moduleName = $context->getModuleName();
    $actionName = $context->getActionName();

    // get the request method
    $method = $context->getRequest()->getMethod();

    if (($actionInstance->getRequestMethods() & $method) != $method)
    {
      // this action will skip validation/execution for this method
      // get the default view
      $viewName = $actionInstance->getDefaultView();
    }
    else
    {
      // set default validated status
      $validated = true;

      // get the current action validation configuration
      $validationConfig = $moduleName.'/'.SF_APP_MODULE_VALIDATE_DIR_NAME.'/'.$actionName.'.yml';
      if (is_readable(SF_APP_MODULE_DIR.'/'.$validationConfig))
      {
        // load validation configuration
        // do NOT use require_once
        require(sfConfigCache::checkConfig(SF_APP_MODULE_DIR_NAME.'/'.$validationConfig));
      }

      // manually load validators
      $actionInstance->registerValidators($validatorManager);

      // process validators
      $validated = $validatorManager->execute();

      // process manual validation
      if ($validated && $actionInstance->validate())
      {
        // register our cache configuration
        if (SF_CACHE)
        {
          $cacheManager    = $context->getViewCacheManager();
          $cacheConfigFile = $moduleName.'/'.SF_APP_MODULE_CONFIG_DIR_NAME.'/cache.yml';
          if (is_readable(SF_APP_MODULE_DIR.'/'.$cacheConfigFile))
          {
            require(sfConfigCache::checkConfig(SF_APP_MODULE_DIR_NAME.'/'.$cacheConfigFile, array('moduleName' => $moduleName)));
          }

        }

        // page in cache?
        if (SF_CACHE && !count($_GET) && !count($_POST))
        {
          if (SF_DEBUG && $context->getRequest()->getParameter('ignore_cache', false, 'symfony/request/sfWebRequest') == true)
          {
            if (SF_LOGGING_ACTIVE) $context->getLogger()->info('{sfExecutionFilter} discard page cache');
          }
          else
          {
            // retrieve page content from cache
            $retval = $cacheManager->get(sfRouting::getInstance()->getCurrentInternalUri(), 'page');

            if (SF_LOGGING_ACTIVE) $context->getLogger()->info('{sfExecutionFilter} page cache '.($retval ? 'exists' : 'does not exist'));

            if ($retval !== null)
            {
              if ($controller->getRenderMode() == sfView::RENDER_VAR)
              {
                $actionEntry->setPresentation($retval);
              }
              else
              {
                // conditionnal get support
                // http://fishbowl.pastiche.org/archives/001132.html
                // http://simon.incutio.com/archive/2003/04/23/conditionalGet
                // http://lightpress.org/post/php-http11-dates-and-conditional-get/
                // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9
// FIXME: TBD
//                if (!$this->doConditionalGet(time()))
//                {
                  echo $retval;
//                }
              }

              // stop execution filter
              return;
            }
          }
        }

        // execute the action
        $actionInstance->preExecute();
        $viewName = $actionInstance->execute();
        if ($viewName == '')
        {
          $viewName = sfView::SUCCESS;
        }
        $actionInstance->postExecute();
      }
      else
      {
        if (SF_LOGGING_ACTIVE) $this->context->getLogger()->info('{sfExecutionFilter} action validation failed');

        // validation failed
        $handleErrorToRun = 'handleError'.ucfirst($actionName);
        $viewName = method_exists($actionInstance, $handleErrorToRun) ? $actionInstance->$handleErrorToRun() : $actionInstance->handleError();
      }
    }

    if ($viewName != sfView::NONE)
    {
      if (is_array($viewName))
      {
        // we're going to use an entirely different action for this view
        $moduleName = $viewName[0];
        $viewName   = $viewName[1];
      }
      else
      {
        // use a view related to this action
        $viewName = $actionName.$viewName;
      }

      // display this view
      if (!$controller->viewExists($moduleName, $viewName))
      {
        // the requested view doesn't exist
        $file = SF_APP_MODULE_DIR.'/'.$moduleName.'/'.SF_APP_MODULE_VIEW_DIR_NAME.'/'.$viewName.'View.class.php';

        $error = 'Module "%s" does not contain the view "%sView" or the file "%s" is unreadable';
        $error = sprintf($error, $moduleName, $viewName, $file);

{'fraction_non_alphanumeric': 0.13162830349531116, 'fraction_numerical': 0.008184143222506393, 'mean_word_length': 2.2415031776733905, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 104, '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': '5992482', 'n_tokens_mistral': 3316, 'n_tokens_neox': 3213, 'n_words': 739}