<commit_before><?php

/**
 * sfOpenPNEFilterConfigHandler allows you to register filters with the system.
 *
 * @package    OpenPNE
 * @subpackage config
 * @author     <NAME> <<EMAIL>>
 */
class sfOpenPNEFilterConfigHandler extends sfFilterConfigHandler
{
  /**
   * @see sfFilterConfigHandler::addFilter()
   */
  protected function addFilter($category, $class, $parameters)
  {
    $result = parent::addFilter($category, $class, $parameters);
    if ('execution' === $category) {
        $result = $this->addActionFilter($category, $class, $parameters).$result;
    }
    return $result;
  }

  /**
   * Adds an action filter statement to the data.
   *
   * @param string The category name
   * @param string The filter class name
   * @param array  Filter default parameters
   *
   * @return string The PHP statement
   */
  protected function addActionFilter($category, $class, $parameters)
  {
    $finder = sfFinder::type('file')->name('*.php');
    $files = array();
    $data = '';

    // module filter directories
    if ($matches = glob(sfConfig::get('sf_app_module_dir').'/*/filters')) {
      $files = array_merge($files, $finder->in($matches));
    }

    // plugin module filter directories
    if ($matches = glob(sfConfig::get('sf_plugins_dir').'/*/apps/'.sfConfig::get('sf_app').'/modules/*/filters')) {
      $files = array_merge($files, $finder->in($matches));
    }

    $regex = '~^\s*(?:abstract\s+|final\s+)?(?:class|interface)\s+(\w+)~mi';
    foreach ($files as $file)
    {
      $modulesDirPos = strrpos($file, 'modules/') + strlen('modules/');
      $moduleNameLength = strpos($file, '/', $modulesDirPos) - $modulesDirPos;
      $moduleName = substr($file, $modulesDirPos, $moduleNameLength);

      preg_match_all($regex, file_get_contents($file), $classes);
      foreach ($classes[1] as $class) {
        $data .= <<<EOF
if ('$moduleName' == \$actionInstance->getModuleName()) {  {$this->addFilter($class, $class, $parameters)}
}
EOF;
      }
    }

    return $data;
  }
}<commit_msg>#2940:fixed missing requiring action filters in sfOpenPNEFilterConfigHandler::addActionFilter()<commit_after><?php

/**
 * sfOpenPNEFilterConfigHandler allows you to register filters with the system.
 *
 * @package    OpenPNE
 * @subpackage config
 * @author     <NAME> <<EMAIL>>
 */
class sfOpenPNEFilterConfigHandler extends sfFilterConfigHandler
{
  /**
   * @see sfFilterConfigHandler::addFilter()
   */
  protected function addFilter($category, $class, $parameters)
  {
    $result = parent::addFilter($category, $class, $parameters);
    if ('execution' === $category) {
        $result = $this->addActionFilter($category, $class, $parameters).$result;
    }
    return $result;
  }

  /**
   * Adds an action filter statement to the data.
   *
   * @param string The category name
   * @param string The filter class name
   * @param array  Filter default parameters
   *
   * @return string The PHP statement
   */
  protected function addActionFilter($category, $class, $parameters)
  {
    $finder = sfFinder::type('file')->name('*.php');
    $files = array();
    $data = '';

    // module filter directories
    if ($matches = glob(sfConfig::get('sf_app_module_dir').'/*/filters')) {
      $files = array_merge($files, $finder->in($matches));
    }

    // plugin module filter directories
    if ($matches = glob(sfConfig::get('sf_plugins_dir').'/*/apps/'.sfConfig::get('sf_app').'/modules/*/filters')) {
      $files = array_merge($files, $finder->in($matches));
    }

    $regex = '~^\s*(?:abstract\s+|final\s+)?(?:class|interface)\s+(\w+)~mi';
    foreach ($files as $file)
    {
      $modulesDirPos = strrpos($file, 'modules/') + strlen('modules/');
      $moduleNameLength = strpos($file, '/', $modulesDirPos) - $modulesDirPos;
      $moduleName = substr($file, $modulesDirPos, $moduleNameLength);

      preg_match_all($regex, file_get_contents($file), $classes);
      foreach ($classes[1] as $class) {
        $data .= <<<EOF
if ('$moduleName' == \$actionInstance->getModuleName()) {
  require_once '$file';
  {$this->addFilter($class, $class, $parameters)}
}
EOF;
      }
    }

    return $data;
  }
}
{'fraction_non_alphanumeric': 0.17361948396431154, 'fraction_numerical': 0.0014468290330359296, 'mean_word_length': 3.6502242152466366, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 21, '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': '5980', 'n_tokens_mistral': 1301, 'n_tokens_neox': 1275, 'n_words': 278}