Changeset 6509
- Timestamp:
- 12/15/07 17:13:54 (2 years ago)
- Files:
-
- trunk/UPGRADE (modified) (2 diffs)
- trunk/data/config/filters.yml (modified) (1 diff)
- trunk/data/skeleton/app/app/config/filters.yml (modified) (1 diff)
- trunk/lib/action/sfComponent.class.php (modified) (1 diff)
- trunk/lib/config/sfLoader.class.php (modified) (2 diffs)
- trunk/lib/debug/sfWebDebug.class.php (modified) (4 diffs)
- trunk/lib/filter/sfRenderingFilter.class.php (modified) (1 diff)
- trunk/lib/filter/sfWebDebugFilter.class.php (deleted)
- trunk/lib/log/sfWebDebugLogger.class.php (modified) (7 diffs)
- trunk/lib/plugins/sfCompat10Plugin/lib/helper/DebugHelper.php (modified) (1 diff)
- trunk/lib/plugins/sfCompat10Plugin/lib/helper/PartialHelper.php (modified) (2 diffs)
- trunk/lib/plugins/sfCompat10Plugin/test/functional/fixtures/apps/frontend/config/filters.yml (modified) (1 diff)
- trunk/lib/plugins/sfCompat10Plugin/test/functional/fixtures/data/environment.migrated (added)
- trunk/lib/plugins/sfPropelPlugin/test/functional/fixtures/apps/backend/config/filters.yml (modified) (1 diff)
- trunk/lib/plugins/sfPropelPlugin/test/functional/fixtures/apps/crud/config/filters.yml (modified) (1 diff)
- trunk/lib/response/sfResponse.class.php (modified) (1 diff)
- trunk/lib/task/project/upgrade1.1/sfWebDebugUpgrade.class.php (added)
- trunk/lib/view/sfViewCacheManager.class.php (modified) (4 diffs)
- trunk/test/functional/fixtures/project/apps/cache/config/filters.yml (modified) (1 diff)
- trunk/test/functional/fixtures/project/apps/frontend/config/filters.yml (modified) (1 diff)
- trunk/test/functional/fixtures/project/apps/frontend/modules/configFiltersSimpleFilter/config/filters.yml (modified) (1 diff)
- trunk/test/functional/fixtures/project/apps/i18n/config/filters.yml (modified) (1 diff)
- trunk/test/functional/fixtures/project/config/filters.yml (modified) (1 diff)
- trunk/test/functional/fixtures/project/plugins/sfConfigPlugin/config/filters.yml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/UPGRADE
r6501 r6509 58 58 <?php endif; ?> 59 59 60 The flashentry in `filters.yml` must be removed too as the `sfFlashFilter`60 The `flash` entry in `filters.yml` must be removed too as the `sfFlashFilter` 61 61 was removed. 62 62 … … 315 315 316 316 The `initialize()` call is not needed anymore (see the point above). 317 318 Web Debug 319 --------- 320 321 The `web_debug` entry in `filters.yml` must be removed as the `sfWebDebugFilter` 322 has been removed. The web debug toolbar is now injected in the response thanks to a listener. 323 324 The `project:upgrade1.1` task makes all those changes for you. trunk/data/config/filters.yml
r5384 r6509 4 4 param: 5 5 type: rendering 6 7 web_debug:8 class: sfWebDebugFilter9 param:10 condition: %SF_WEB_DEBUG%11 6 12 7 # security filter must have a type of security trunk/data/skeleton/app/app/config/filters.yml
r6157 r6509 1 1 rendering: ~ 2 3 web_debug: ~4 2 security: ~ 5 3 trunk/lib/action/sfComponent.class.php
r5814 r6509 141 141 public function debugMessage($message) 142 142 { 143 if (sfConfig::get('sf_web_debug') )143 if (sfConfig::get('sf_web_debug') && sfConfig::get('sf_logging_enabled')) 144 144 { 145 $this->context->get('sf_web_debug')->logShortMessage($message);145 sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent(null, 'application.log', array('This feature is deprecated in favor of the log_message helper.', 'priority' => sfLogger::ERR))); 146 146 } 147 147 } trunk/lib/config/sfLoader.class.php
r5260 r6509 401 401 if (is_readable($dir.'/'.$fileName)) 402 402 { 403 include ($dir.'/'.$fileName);403 include_once($dir.'/'.$fileName); 404 404 $included = true; 405 405 break; … … 410 410 { 411 411 // search in the include path 412 if ((@include ('helper/'.$fileName)) != 1)412 if ((@include_once('helper/'.$fileName)) != 1) 413 413 { 414 414 $dirs = array_merge($dirs, explode(PATH_SEPARATOR, get_include_path())); trunk/lib/debug/sfWebDebug.class.php
r4850 r6509 21 21 protected 22 22 $log = array(), 23 $shortLog = array(),24 23 $maxPriority = 1000, 25 24 $types = array(), 26 25 $lastTimeLog = -1; 27 28 /**29 * Registers javascripts and stylesheets needed for the web debug toolbar.30 */31 public function registerAssets()32 {33 $response = sfContext::getInstance()->getResponse();34 35 // register our css and js36 $response->addJavascript(sfConfig::get('sf_web_debug_web_dir').'/js/main');37 $response->addStylesheet(sfConfig::get('sf_web_debug_web_dir').'/css/main');38 }39 40 /**41 * Logs a short message to be displayed in the web debug toolbar.42 *43 * @param string The message string44 */45 public function logShortMessage($message)46 {47 $this->shortLog[] = $message;48 }49 26 50 27 /** … … 274 251 $timeInfoDetails .= '</table>'; 275 252 276 // short log messages277 $shortMessages = '';278 if ($this->shortLog)279 {280 $shortMessages = '<ul id="sfWebDebugShortMessages"><li>» '.implode('</li><li>» ', $this->shortLog).'</li></ul>';281 }282 283 253 // logs 284 254 $logInfo = ''; 285 255 if (sfConfig::get('sf_logging_enabled')) 286 256 { 287 $logInfo .= $shortMessages.'257 $logInfo .= ' 288 258 <ul id="sfWebDebugLogMenu"> 289 259 <li><a href="#" onclick="sfWebDebugToggleAllLogLines(true, \'sfWebDebugLogLine\'); return false;">[all]</a></li> … … 389 359 * @return string The decorated HTML string 390 360 */ 391 public function decorateContentWithDebug($internalUri, $content, $new = false)361 static public function decorateContentWithDebug($internalUri, $content, $new = false) 392 362 { 393 363 $context = sfContext::getInstance(); … … 400 370 401 371 $cache = $context->getViewCacheManager(); 402 $this->loadHelpers();372 sfLoader::loadHelpers(array('Helper', 'Url', 'Asset', 'Tag')); 403 373 404 374 $bgColor = $new ? '#9ff' : '#ff9'; trunk/lib/filter/sfRenderingFilter.class.php
r5021 r6509 43 43 // send headers + content 44 44 $response->send(); 45 46 // log timers information47 if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled'))48 {49 $messages = array();50 foreach (sfTimerManager::getTimers() as $name => $timer)51 {52 $messages[] = sprintf('%s %.2f ms (%d)', $name, $timer->getElapsedTime() * 1000, $timer->getCalls());53 }54 55 $this->context->getEventDispatcher()->notify(new sfEvent($this, 'application.log', $messages));56 }57 45 } 58 46 } trunk/lib/log/sfWebDebugLogger.class.php
r5844 r6509 21 21 protected 22 22 $context = null, 23 $ buffer = array(),23 $dispatcher = null, 24 24 $webDebug = null, 25 25 $xdebugLogging = false; … … 35 35 public function initialize(sfEventDispatcher $dispatcher, $options = array()) 36 36 { 37 if (!sfConfig::get('sf_web_debug')) 38 { 39 return; 40 } 37 $this->webDebug = new sfWebDebug(); 38 $this->context = sfContext::getInstance(); 39 $this->dispatcher = $dispatcher; 41 40 42 $this->buffer = array(); 43 $this->context = sfContext::getInstance(); 41 $dispatcher->connect('response.filter_content', array($this, 'filterResponseContent')); 44 42 45 43 if (isset($options['xdebug_logging'])) … … 52 50 53 51 /** 52 * Listens to the response.filter_content event. 53 * 54 * @param sfEvent The sfEvent instance 55 * @param string The response content 56 * 57 * @return string The filtered response content 58 */ 59 public function filterResponseContent(sfEvent $event, $content) 60 { 61 if (!sfConfig::get('sf_web_debug')) 62 { 63 return $content; 64 } 65 66 // log timers information 67 $messages = array(); 68 foreach (sfTimerManager::getTimers() as $name => $timer) 69 { 70 $messages[] = sprintf('%s %.2f ms (%d)', $name, $timer->getElapsedTime() * 1000, $timer->getCalls()); 71 } 72 $this->dispatcher->notify(new sfEvent($this, 'application.log', $messages)); 73 74 // don't add debug toolbar: 75 // * for XHR requests 76 // * if 304 77 // * if not rendering to the client 78 // * if HTTP headers only 79 $response = $event->getSubject(); 80 if ( 81 $this->context->getRequest()->isXmlHttpRequest() || 82 strpos($response->getContentType(), 'html') === false || 83 $response->getStatusCode() == 304 || 84 $this->context->getController()->getRenderMode() != sfView::RENDER_CLIENT || 85 $response->isHeaderOnly() 86 ) 87 { 88 return $content; 89 } 90 91 // add needed assets for the web debug toolbar 92 $assets = sprintf(' 93 <script type="text/javascript" src="%s"></script> 94 <link rel="stylesheet" type="text/css" media="screen" href="%s" />', 95 sfConfig::get('sf_web_debug_web_dir').'/js/main.js', 96 sfConfig::get('sf_web_debug_web_dir').'/css/main.css' 97 ); 98 $content = str_ireplace('</head>', $assets.'</head>', $content); 99 100 // add web debug information to response content 101 $webDebugContent = $this->webDebug->getResults(); 102 $count = 0; 103 $content = str_ireplace('</body>', $webDebugContent.'</body>', $content, $count); 104 if (!$count) 105 { 106 $content .= $webDebugContent; 107 } 108 109 return $content; 110 } 111 112 /** 54 113 * Logs a message. 55 114 * … … 59 118 protected function doLog($message, $priority) 60 119 { 61 if (!sfConfig::get('sf_web_debug'))62 {63 return;64 }65 66 120 // if we have xdebug and dev has not disabled the feature, add some stack information 67 121 $debugStack = array(); … … 78 132 if (isset($stack['function'])) 79 133 { 80 $tmp .= 'in "'.$stack['function'].'" ';134 $tmp .= sprintf('in "%s" ', $stack['function']); 81 135 } 82 $tmp .= 'from "'.$stack['file'].'" line '.$stack['line'];136 $tmp .= sprintf('from "%s" line %s', $stack['file'], $stack['line']); 83 137 $debugStack[] = $tmp; 84 138 } … … 94 148 } 95 149 96 // build theobject containing the complete log information97 $ logEntry =array(150 // send the log object containing the complete log information 151 $this->webDebug->log(array( 98 152 'priority' => $priority, 99 153 'time' => time(), … … 101 155 'type' => $type, 102 156 'debugStack' => $debugStack, 103 ); 104 105 // send the log object 106 if (is_null($this->webDebug)) 107 { 108 $this->buffer[] = $logEntry; 109 110 if ($this->context->has('sf_web_debug')) 111 { 112 $this->webDebug = $this->context->get('sf_web_debug'); 113 while ($buffer = array_shift($this->buffer)) 114 { 115 $this->webDebug->log($buffer); 116 } 117 } 118 } 119 else 120 { 121 $this->webDebug->log($logEntry); 122 } 157 )); 123 158 } 124 159 } trunk/lib/plugins/sfCompat10Plugin/lib/helper/DebugHelper.php
r4951 r6509 3 3 function debug_message($message) 4 4 { 5 if (sfConfig::get('sf_web_debug') )5 if (sfConfig::get('sf_web_debug') && sfConfig::get('sf_logging_enabled')) 6 6 { 7 sfContext::getInstance()->get ('sf_web_debug')->logShortMessage($message);7 sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent(null, 'application.log', array('This feature is deprecated in favor of the log_message helper.', 'priority' => sfLogger::ERR))); 8 8 } 9 9 } trunk/lib/plugins/sfCompat10Plugin/lib/helper/PartialHelper.php
r5092 r6509 268 268 if (sfConfig::get('sf_web_debug')) 269 269 { 270 $retval = sf Context::getInstance()->get('sf_web_debug')->decorateContentWithDebug($uri, $retval, false);270 $retval = sfWebDebug::decorateContentWithDebug($uri, $retval, false); 271 271 } 272 272 … … 280 280 if ($saved && sfConfig::get('sf_web_debug')) 281 281 { 282 $retval = sf Context::getInstance()->get('sf_web_debug')->decorateContentWithDebug($uri, $retval, true);282 $retval = sfWebDebug::decorateContentWithDebug($uri, $retval, true); 283 283 } 284 284 trunk/lib/plugins/sfCompat10Plugin/test/functional/fixtures/apps/frontend/config/filters.yml
r5320 r6509 1 1 rendering: ~ 2 web_debug: ~3 2 security: ~ 4 3 trunk/lib/plugins/sfPropelPlugin/test/functional/fixtures/apps/backend/config/filters.yml
r4934 r6509 1 1 rendering: ~ 2 web_debug: ~3 2 security: ~ 4 3 trunk/lib/plugins/sfPropelPlugin/test/functional/fixtures/apps/crud/config/filters.yml
r4934 r6509 1 1 rendering: ~ 2 web_debug: ~3 2 security: ~ 4 3 trunk/lib/response/sfResponse.class.php
r5156 r6509 78 78 public function sendContent() 79 79 { 80 $event = $this->dispatcher->filter(new sfEvent($this, 'response.filter_content'), $this->getContent()); 81 $content = $event->getReturnValue(); 82 80 83 if (sfConfig::get('sf_logging_enabled')) 81 84 { 82 $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Send content (%s o)', strlen($ this->getContent())))));85 $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Send content (%s o)', strlen($content))))); 83 86 } 84 87 85 echo $ this->getContent();88 echo $content; 86 89 } 87 90 trunk/lib/view/sfViewCacheManager.class.php
r5025 r6509 560 560 if (sfConfig::get('sf_web_debug')) 561 561 { 562 $content = $this->context->get('sf_web_debug')->decorateContentWithDebug($uri, $content, false);562 $content = sfWebDebug::decorateContentWithDebug($uri, $content, false); 563 563 } 564 564 … … 586 586 if ($saved && sfConfig::get('sf_web_debug')) 587 587 { 588 $content = $this->context->get('sf_web_debug')->decorateContentWithDebug($uri, $content, true);588 $content = sfWebDebug::decorateContentWithDebug($uri, $content, true); 589 589 } 590 590 … … 609 609 if ($saved && sfConfig::get('sf_web_debug')) 610 610 { 611 $content = $this->context->get('sf_web_debug')->decorateContentWithDebug($uri, $this->context->getResponse()->getContent(), true);611 $content = sfWebDebug::decorateContentWithDebug($uri, $this->context->getResponse()->getContent(), true); 612 612 $this->context->getResponse()->setContent($content); 613 613 } … … 643 643 if (sfConfig::get('sf_web_debug')) 644 644 { 645 $content = $this->context->get('sf_web_debug')->decorateContentWithDebug($uri, $this->context->getResponse()->getContent(), false);645 $content = sfWebDebug::decorateContentWithDebug($uri, $this->context->getResponse()->getContent(), false); 646 646 $this->context->getResponse()->setContent($content); 647 647 } trunk/test/functional/fixtures/project/apps/cache/config/filters.yml
r4934 r6509 1 1 rendering: ~ 2 web_debug: ~3 2 security: ~ 4 3 trunk/test/functional/fixtures/project/apps/frontend/config/filters.yml
r4934 r6509 1 1 rendering: ~ 2 web_debug: ~3 2 security: ~ 4 3 trunk/test/functional/fixtures/project/apps/frontend/modules/configFiltersSimpleFilter/config/filters.yml
r4934 r6509 1 1 rendering: ~ 2 web_debug: ~3 2 security: ~ 4 3 trunk/test/functional/fixtures/project/apps/i18n/config/filters.yml
r4934 r6509 1 1 rendering: ~ 2 web_debug: ~3 2 security: ~ 4 3 trunk/test/functional/fixtures/project/config/filters.yml
r4934 r6509 1 1 rendering: ~ 2 web_debug: ~3 2 security: ~ 4 3 trunk/test/functional/fixtures/project/plugins/sfConfigPlugin/config/filters.yml
r4934 r6509 1 1 rendering: ~ 2 web_debug: ~3 2 security: ~ 4 3

