<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.
 */

/**
 * sfWebDebug creates debug information for easy debugging in the browser.
 *
 * @package    symfony
 * @subpackage debug
 * @author     <NAME> <<EMAIL>>
 * @version    SVN: $Id$
 */
class sfWebDebug
{
  protected
    $dispatcher = null,
    $logger     = null,
    $options    = array(),
    $panels     = array();

  /**
   * Constructor.
   *
   * Available options:
   *
   *  * image_root_path:    The image root path
   *  * request_parameters: The current request parameters
   *
   * @param sfEventDispatcher $dispatcher The event dispatcher
   * @param sfVarLogger       $logger     The logger
   * @param array             $options    An array of options
   */
  public function __construct(sfEventDispatcher $dispatcher, sfVarLogger $logger, array $options = array())
  {
    $this->dispatcher = $dispatcher;
    $this->logger     = $logger;
    $this->options    = $options;

    if (!isset($this->options['image_root_path']))
    {
      $this->options['image_root_path'] = '';
    }

    if (!isset($this->options['request_parameters']))
    {
      $this->options['request_parameters'] = array();
    }

    $this->configure();

    $this->dispatcher->notify(new sfEvent($this, 'debug.web.load_panels'));
  }

  /**
   * Configures the web debug toolbar.
   */
  public function configure()
  {
    $this->setPanel('symfony_version', new sfWebDebugPanelSymfonyVersion($this));
    if (sfConfig::get('sf_debug') && sfConfig::get('sf_cache'))
    {
      $this->setPanel('cache', new sfWebDebugPanelCache($this));
    }
    if (sfConfig::get('sf_logging_enabled'))
    {
      $this->setPanel('config', new sfWebDebugPanelConfig($this));
      $this->setPanel('view', new sfWebDebugPanelView($this));
    }
    $this->setPanel('logs', new sfWebDebugPanelLogs($this));
    $this->setPanel('memory', new sfWebDebugPanelMemory($this));
    if (sfConfig::get('sf_debug'))
    {
      $this->setPanel('time', new sfWebDebugPanelTimer($this));
    }

    $this->setPanel('mailer', new sfWebDebugPanelMailer($this));
  }

  /**
   * Gets the logger.
   *
   * @return sfVarLogger The logger instance
   */
  public function getLogger()
  {
    return $this->logger;
  }

  /**
   * Gets the event dispatcher.
   *
   * @return sfEventDispatcher The event dispatcher
   */
  public function getEventDispatcher()
  {
    return $this->dispatcher;
  }

  /**
   * Gets the registered panels.
   *
   * @return array The panels
   */
  public function getPanels()
  {
    return $this->panels;
  }

  /**
   * Sets a panel by name.
   *
   * @param string          $name  The panel name
   * @param sfWebDebugPanel $panel The panel
   */
  public function setPanel($name, sfWebDebugPanel $panel)
  {
    $this->panels[$name] = $panel;
  }

  /**
   * Removes a panel by name.
   *
   * @param string $name The panel name
   */
  public function removePanel($name)
  {
    unset($this->panels[$name]);
  }

  /**
   * Gets an option value by name.
   *
   * @param string $name The option name
   *
   * @return mixed The option value
   */
  public function getOption($name, $default = null)
  {
    return isset($this->options[$name]) ? $this->options[$name] : $default;
  }

  /**
   * Injects the web debug toolbar into a given HTML string.
   *
   * @param string $content The HTML content
   *
   * @return string The content with the web debug toolbar injected
   */
  public function injectToolbar($content)
  {
    if (false !== $pos = function_exists('mb_stripos') ? mb_stripos($content, '</head>') : stripos($content, '</head>'))
    {
      $styles = '<style type="text/css">'.str_replace(array("\r", "\n"), ' ', $this->getStylesheet()).'</style>';
      $content = substr($content, 0, $pos).$styles.substr($content, $pos);
    }

    $debug = $this->asHtml();
    if (false === $pos = function_exists('mb_strripos') ? mb_strripos($content, '</body>') : strripos($content, '</body>'))
    {
      $content .= $debug;
    }
    else
    {
      $content = substr($content, 0, $pos).'<script type="text/javascript">'.$this->getJavascript().'</script>'.$debug.substr($content, $pos);
    }

    return $content;
  }

  /**<commit_msg>[1.3, 1.4] fixed WDT injection (closes #9107)<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.
 */

/**
 * sfWebDebug creates debug information for easy debugging in the browser.
 *
 * @package    symfony
 * @subpackage debug
 * @author     <NAME> <<EMAIL>>
 * @version    SVN: $Id$
 */
class sfWebDebug
{
  protected
    $dispatcher = null,
    $logger     = null,
    $options    = array(),
    $panels     = array();

  /**
   * Constructor.
   *
   * Available options:
   *
   *  * image_root_path:    The image root path
   *  * request_parameters: The current request parameters
   *
   * @param sfEventDispatcher $dispatcher The event dispatcher
   * @param sfVarLogger       $logger     The logger
   * @param array             $options    An array of options
   */
  public function __construct(sfEventDispatcher $dispatcher, sfVarLogger $logger, array $options = array())
  {
    $this->dispatcher = $dispatcher;
    $this->logger     = $logger;
    $this->options    = $options;

    if (!isset($this->options['image_root_path']))
    {
      $this->options['image_root_path'] = '';
    }

    if (!isset($this->options['request_parameters']))
    {
      $this->options['request_parameters'] = array();
    }

    $this->configure();

    $this->dispatcher->notify(new sfEvent($this, 'debug.web.load_panels'));
  }

  /**
   * Configures the web debug toolbar.
   */
  public function configure()
  {
    $this->setPanel('symfony_version', new sfWebDebugPanelSymfonyVersion($this));
    if (sfConfig::get('sf_debug') && sfConfig::get('sf_cache'))
    {
      $this->setPanel('cache', new sfWebDebugPanelCache($this));
    }
    if (sfConfig::get('sf_logging_enabled'))
    {
      $this->setPanel('config', new sfWebDebugPanelConfig($this));
      $this->setPanel('view', new sfWebDebugPanelView($this));
    }
    $this->setPanel('logs', new sfWebDebugPanelLogs($this));
    $this->setPanel('memory', new sfWebDebugPanelMemory($this));
    if (sfConfig::get('sf_debug'))
    {
      $this->setPanel('time', new sfWebDebugPanelTimer($this));
    }

    $this->setPanel('mailer', new sfWebDebugPanelMailer($this));
  }

  /**
   * Gets the logger.
   *
   * @return sfVarLogger The logger instance
   */
  public function getLogger()
  {
    return $this->logger;
  }

  /**
   * Gets the event dispatcher.
   *
   * @return sfEventDispatcher The event dispatcher
   */
  public function getEventDispatcher()
  {
    return $this->dispatcher;
  }

  /**
   * Gets the registered panels.
   *
   * @return array The panels
   */
  public function getPanels()
  {
    return $this->panels;
  }

  /**
   * Sets a panel by name.
   *
   * @param string          $name  The panel name
   * @param sfWebDebugPanel $panel The panel
   */
  public function setPanel($name, sfWebDebugPanel $panel)
  {
    $this->panels[$name] = $panel;
  }

  /**
   * Removes a panel by name.
   *
   * @param string $name The panel name
   */
  public function removePanel($name)
  {
    unset($this->panels[$name]);
  }

  /**
   * Gets an option value by name.
   *
   * @param string $name The option name
   *
   * @return mixed The option value
   */
  public function getOption($name, $default = null)
  {
    return isset($this->options[$name]) ? $this->options[$name] : $default;
  }

  /**
   * Injects the web debug toolbar into a given HTML string.
   *
   * @param string $content The HTML content
   *
   * @return string The content with the web debug toolbar injected
   */
  public function injectToolbar($content)
  {
    if (function_exists('mb_stripos'))
    {
      $posFunction = 'mb_stripos';
      $posrFunction = 'mb_strripos';
      $substrFunction = 'mb_substr';
    }
    else
    {
      $posFunction = 'stripos';
      $posrFunction = 'strripos';
      $substrFunction = 'substr';
    }

    if (false !== $pos = $posFunction($content, '</head>'))
    {
      $styles = '<style type="text/css">'.str_replace(array("\r", "\n"), ' ', $this->getStylesheet()).'</style>';
      $content = $substrFunction($content, 0, $pos).$styles.$substrFunction($content, $pos);
    }

    $debug = $this->asHtml();
    if (false === $pos = $posrFunction($content, '</body>'))
    {
      $content .= $debug;
    }
    else
    {
      $content = $substrFunction($content, 0, $pos).'<script type="text/javascript">'.$this->getJavascript().'</script>'.$debug.$substrFunction($content, $pos);
    }

    return $content;
  }

  /**
{'fraction_non_alphanumeric': 0.15577777777777777, 'fraction_numerical': 0.003111111111111111, 'mean_word_length': 2.9117774880486746, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 85, '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': '1660331', 'n_tokens_mistral': 2896, 'n_tokens_neox': 2829, 'n_words': 677}