Development

Changeset 8983

You must first sign up to be able to contribute.

Changeset 8983

Show
Ignore:
Timestamp:
05/15/08 18:46:55 (5 months ago)
Author:
fabien
Message:

added a view.cache.filter_content event to decouple the sfViewCacheManager and the sfWebDebug class (closes #3218)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/lib/config/config/factories.yml

    r8227 r8983  
    8282          class: sfWebDebugLogger 
    8383          param: 
    84             condition:      %SF_WEB_DEBUG% 
    85             xdebug_logging: true 
     84            condition:       %SF_WEB_DEBUG% 
     85            xdebug_logging:  true 
     86            web_debug_class: sfWebDebug 
    8687        sf_file_debug: 
    8788          class: sfFileLogger 
  • branches/1.1/lib/debug/sfWebDebug.class.php

    r8091 r8983  
    2020{ 
    2121  protected 
     22    $dispatcher  = null, 
    2223    $log         = array(), 
    2324    $maxPriority = 1000, 
    2425    $types       = array(), 
    2526    $lastTimeLog = -1; 
     27 
     28  public function __construct(sfEventDispatcher $dispatcher) 
     29  { 
     30    $this->dispatcher = $dispatcher; 
     31 
     32    $this->dispatcher->connect('view.cache.filter_content', array($this, 'decorateContentWithDebug')); 
     33  } 
    2634 
    2735  /** 
     
    354362 
    355363  /** 
    356    * Decorates a chunk of HTML with cache information. 
    357    * 
    358    * @param string  The internalUri representing the content 
     364   * Listens to the 'view.cache.filter_content' event to decorate a chunk of HTML with cache information. 
     365   * 
     366   * @param sfEvent A sfEvent instance 
    359367   * @param string  The HTML content 
    360    * @param boolean true if the content is new in the cache, false otherwise 
    361368   * 
    362369   * @return string The decorated HTML string 
    363370   */ 
    364   static public function decorateContentWithDebug($internalUri, $content, $new = false) 
    365   { 
    366     $context = sfContext::getInstance(); 
    367  
     371  public function decorateContentWithDebug(sfEvent $event, $content) 
     372  { 
    368373    // don't decorate if not html or if content is null 
    369     if (!sfConfig::get('sf_web_debug') || !$content || false === strpos($context->getResponse()->getContentType(), 'html')) 
     374    if (!sfConfig::get('sf_web_debug') || !$content || false === strpos($event['response']->getContentType(), 'html')) 
    370375    { 
    371376      return $content; 
    372377    } 
    373378 
    374     $cache = $context->getViewCacheManager(); 
     379    $viewCacheManager = $event->getSubject(); 
    375380    sfLoader::loadHelpers(array('Helper', 'Url', 'Asset', 'Tag')); 
    376381 
    377     $bgColor      = $new ? '#9ff' : '#ff9'; 
    378     $lastModified = $cache->getLastModified($internalUri); 
    379     $id           = md5($internalUri); 
     382    $bgColor      = $event['new'] ? '#9ff' : '#ff9'; 
     383    $lastModified = $viewCacheManager->getLastModified($event['uri']); 
     384    $id           = md5($event['uri']); 
    380385 
    381386    return ' 
     
    384389      <div style="height: 16px; padding: 2px"><a href="#" onclick="sfWebDebugToggle(\'sub_main_info_'.$id.'\'); return false;"><strong>cache information</strong></a>&nbsp;<a href="#" onclick="sfWebDebugToggle(\'sub_main_'.$id.'\'); document.getElementById(\'main_'.$id.'\').style.border = \'none\'; return false;">'.image_tag(sfConfig::get('sf_web_debug_web_dir').'/images/close.png').'</a>&nbsp;</div> 
    385390        <div style="padding: 2px; display: none" id="sub_main_info_'.$id.'"> 
    386         [uri]&nbsp;'.htmlspecialchars($internalUri, ENT_QUOTES, sfConfig::get('sf_charset')).'<br /> 
    387         [life&nbsp;time]&nbsp;'.$cache->getLifeTime($internalUri).'&nbsp;seconds<br /> 
     391        [uri]&nbsp;'.htmlspecialchars($event['uri'], ENT_QUOTES, sfConfig::get('sf_charset')).'<br /> 
     392        [life&nbsp;time]&nbsp;'.$viewCacheManager->getLifeTime($event['uri']).'&nbsp;seconds<br /> 
    388393        [last&nbsp;modified]&nbsp;'.(time() - $lastModified).'&nbsp;seconds<br /> 
    389394        &nbsp;<br />&nbsp; 
  • branches/1.1/lib/log/sfWebDebugLogger.class.php

    r8368 r8983  
    3838    $this->dispatcher = $dispatcher; 
    3939 
     40    $class = isset($options['web_debug_class']) ? $options['web_debug_class'] : 'sfWebDebug'; 
     41    $this->webDebug = new $class($dispatcher); 
     42 
    4043    $dispatcher->connect('response.filter_content', array($this, 'filterResponseContent')); 
    41  
    42     if(is_null($this->webDebug)) 
    43     { 
    44       $this->webDebug = $this->context->has('sf_web_debug') ? $this->context->get('sf_web_debug') : new sfWebDebug(); 
    45     } 
    46  
    47     $this->context->set('sf_web_debug', $this->webDebug); 
    4844 
    4945    if (isset($options['xdebug_logging'])) 
  • branches/1.1/lib/view/sfViewCacheManager.class.php

    r8138 r8983  
    669669    if (sfConfig::get('sf_web_debug')) 
    670670    { 
    671       $content = sfWebDebug::decorateContentWithDebug($uri, $content, false); 
     671      $content = $this->dispatcher->filter(new sfEvent($this, 'view.cache.filter_content', array('response' => $this->context->getResponse(), 'uri' => $uri, 'new' => false)), $content)->getReturnValue(); 
    672672    } 
    673673 
     
    697697    if ($saved && sfConfig::get('sf_web_debug')) 
    698698    { 
    699       $content = sfWebDebug::decorateContentWithDebug($uri, $content, true); 
     699      $content = $this->dispatcher->filter(new sfEvent($this, 'view.cache.filter_content', array('response' => $this->context->getResponse(), 'uri' => $uri, 'new' => true)), $content)->getReturnValue(); 
    700700    } 
    701701 
     
    744744    if (sfConfig::get('sf_web_debug')) 
    745745    { 
    746       $content = sfWebDebug::decorateContentWithDebug($uri, $content, false); 
     746      $content = $this->dispatcher->filter(new sfEvent($this, 'view.cache.filter_content', array('response' => $this->context->getResponse(), 'uri' => $uri, 'new' => false)), $content)->getReturnValue(); 
    747747    } 
    748748 
     
    770770    if ($saved && sfConfig::get('sf_web_debug')) 
    771771    { 
    772       $content = sfWebDebug::decorateContentWithDebug($uri, $content, true); 
     772      $content = $this->dispatcher->filter(new sfEvent($this, 'view.cache.filter_content', array('response' => $this->context->getResponse(), 'uri' => $uri, 'new' => true)), $content)->getReturnValue(); 
    773773    } 
    774774 
     
    793793    if ($saved && sfConfig::get('sf_web_debug')) 
    794794    { 
    795       $content = sfWebDebug::decorateContentWithDebug($uri, $this->context->getResponse()->getContent(), true); 
     795      $content = $this->dispatcher->filter(new sfEvent($this, 'view.cache.filter_content', array('response' => $this->context->getResponse(), 'uri' => $uri, 'new' => true)), $this->context->getResponse()->getContent())->getReturnValue(); 
     796 
    796797      $this->context->getResponse()->setContent($content); 
    797798    } 
     
    828829      if (sfConfig::get('sf_web_debug')) 
    829830      { 
    830         $content = sfWebDebug::decorateContentWithDebug($uri, $this->context->getResponse()->getContent(), false); 
     831        $content = $this->dispatcher->filter(new sfEvent($this, 'view.cache.filter_content', array('response' => $this->context->getResponse(), 'uri' => $uri, 'new' => false)), $this->context->getResponse()->getContent())->getReturnValue(); 
     832 
    831833        $this->context->getResponse()->setContent($content); 
    832834      }