<commit_before><?php

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

/**
 * PartialHelper.
 *
 * @package    symfony
 * @subpackage helper
 * @author     <NAME> <<EMAIL>>
 * @version    SVN: $Id$
 */

function include_component_slot($name)
{
  $context = sfContext::getInstance();

  $actionStackEntry = $context->getController()->getActionStack()->getLastEntry();
  $viewInstance     = $actionStackEntry->getViewInstance();

  if (!$viewInstance->hasComponentSlot($name))
  {
    // cannot find component slot
    $error = 'The component slot "%s" is not set';
    $error = sprintf($error, $name);

    throw new sfConfigurationException($error);
  }

  $componentSlot = $viewInstance->getComponentSlot($name);

  include_component($componentSlot[0], $componentSlot[1]);
}

function include_component($moduleName, $componentName, $vars = array())
{
  $context    = sfContext::getInstance();
  $controller = $context->getController();

  if (!$controller->componentExists($moduleName, $componentName))
  {
    // cannot find component
    $error = 'The component does not exist: "%s", "%s"';
    $error = sprintf($error, $moduleName, $componentName);

    throw new sfConfigurationException($error);
  }

  // create an instance of the action
  $componentInstance = $controller->getComponent($moduleName, $componentName);

  // initialize the action
  if ($componentInstance->initialize($context))
  {
    $componentInstance->getVarHolder()->add($vars);

    // dispatch component
    $componentToRun = 'execute'.ucfirst($componentName);
    if (!method_exists($componentInstance, $componentToRun))
    {
      if (method_exists($componentInstance, 'execute'))
      {
        $componentToTun = 'execute';
      }
      else
      {
        // component not found
        $error = 'sfComponent initialization failed for module "%s", component "%s"';
        $error = sprintf($error, $moduleName, $componentName);
        throw new sfInitializationException($error);
      }
    }

    if (sfConfig::get('sf_logging_active')) $context->getLogger()->info('{sfComponent} call "'.$moduleName.'->'.$componentToRun.'()'.'"');

    // run component
    $retval = $componentInstance->$componentToRun();

    if ($retval != sfView::NONE)
    {
      // get component vars
      $componentVars = $componentInstance->getVarHolder()->getAll();

      // include partial
      include_partial($moduleName.'/'.$componentName, $componentVars);
    }
  }
  else
  {
    // component failed to initialize
    $error = 'Component initialization failed for module "%s", component "%s"';
    $error = sprintf($error, $moduleName, $componentName);

    throw new sfInitializationException($error);
  }
}

function include_partial($name, $vars = array())
{
  // partial is in another module?
  $sep = strpos($name, '/');
  if ($sep)
  {
    $type = strtolower(substr($name, 0, $sep));
    $filename = '_'.substr($name, $sep + 1).'.php';
  }
  else
  {
    $type = '';
    $filename = '_'.$name.'.php';
  }

  $context = sfContext::getInstance();

  $lastActionEntry  = $context->getActionStack()->getLastEntry();<commit_msg>fixed a bug in partial helper (fixed #220)<commit_after><?php

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

/**
 * PartialHelper.
 *
 * @package    symfony
 * @subpackage helper
 * @author     <NAME> <<EMAIL>>
 * @version    SVN: $Id$
 */

function include_component_slot($name)
{
  $context = sfContext::getInstance();

  $actionStackEntry = $context->getController()->getActionStack()->getLastEntry();
  $viewInstance     = $actionStackEntry->getViewInstance();

  if (!$viewInstance->hasComponentSlot($name))
  {
    // cannot find component slot
    $error = 'The component slot "%s" is not set';
    $error = sprintf($error, $name);

    throw new sfConfigurationException($error);
  }

  $componentSlot = $viewInstance->getComponentSlot($name);

  include_component($componentSlot[0], $componentSlot[1]);
}

function include_component($moduleName, $componentName, $vars = array())
{
  $context    = sfContext::getInstance();
  $controller = $context->getController();

  if (!$controller->componentExists($moduleName, $componentName))
  {
    // cannot find component
    $error = 'The component does not exist: "%s", "%s"';
    $error = sprintf($error, $moduleName, $componentName);

    throw new sfConfigurationException($error);
  }

  // create an instance of the action
  $componentInstance = $controller->getComponent($moduleName, $componentName);

  // initialize the action
  if ($componentInstance->initialize($context))
  {
    $componentInstance->getVarHolder()->add($vars);

    // dispatch component
    $componentToRun = 'execute'.ucfirst($componentName);
    if (!method_exists($componentInstance, $componentToRun))
    {
      if (method_exists($componentInstance, 'execute'))
      {
        $componentToTun = 'execute';
      }
      else
      {
        // component not found
        $error = 'sfComponent initialization failed for module "%s", component "%s"';
        $error = sprintf($error, $moduleName, $componentName);
        throw new sfInitializationException($error);
      }
    }

    if (sfConfig::get('sf_logging_active')) $context->getLogger()->info('{sfComponent} call "'.$moduleName.'->'.$componentToRun.'()'.'"');

    // run component
    $retval = $componentInstance->$componentToRun();

    if ($retval != sfView::NONE)
    {
      // get component vars
      $componentVars = $componentInstance->getVarHolder()->getAll();

      // include partial
      include_partial($moduleName.'/'.$componentName, $componentVars);
    }
  }
  else
  {
    // component failed to initialize
    $error = 'Component initialization failed for module "%s", component "%s"';
    $error = sprintf($error, $moduleName, $componentName);

    throw new sfInitializationException($error);
  }
}

function include_partial($name, $vars = array())
{
  // partial is in another module?
  $sep = strpos($name, '/');
  if ($sep)
  {
    $type = substr($name, 0, $sep);
    $filename = '_'.substr($name, $sep + 1).'.php';
  }
  else
  {
    $type = '';
    $filename = '_'.$name.'.php';
  }

  $context = sfContext::getInstance();

  $lastActionEntry  = $context->getActionStack()->getLastEntry();
{'fraction_non_alphanumeric': 0.15866483767718337, 'fraction_numerical': 0.00411522633744856, 'mean_word_length': 3.6605113636363638, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 55, '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': '7363534', 'n_tokens_mistral': 1913, 'n_tokens_neox': 1883, 'n_words': 456}