예제 #1
0
 /**
  * Executes this filter.
  *
  * @param sfFilterChain A sfFilterChain instance
  */
 public function execute($filterChain)
 {
     // execute this filter only once
     if ($this->isFirstCall()) {
         // register sfWebDebug assets
         sfWebDebug::getInstance()->registerAssets();
     }
     // execute next filter
     $filterChain->execute();
     $context = $this->getContext();
     $response = $context->getResponse();
     $controller = $context->getController();
     // don't add debug toolbar:
     // * for XHR requests
     // * if 304
     // * if not rendering to the client
     // * if HTTP headers only
     if ($this->getContext()->getRequest()->isXmlHttpRequest() || strpos($response->getContentType(), 'html') === false || $response->getStatusCode() == 304 || $controller->getRenderMode() != sfView::RENDER_CLIENT || $response->isHeaderOnly()) {
         return;
     }
     $content = $response->getContent();
     $webDebug = sfWebDebug::getInstance()->getResults();
     // add web debug information to response content
     $newContent = str_ireplace('</body>', $webDebug . '</body>', $content);
     if ($content == $newContent) {
         $newContent .= $webDebug;
     }
     $response->setContent($newContent);
 }
 /**
  * Initializes the web debug logger.
  *
  * @param array Logger options
  */
 public function initialize($options = array())
 {
     if (!sfConfig::get('sf_web_debug')) {
         return;
     }
     $this->webDebug = sfWebDebug::getInstance();
 }
예제 #3
0
 /**
  * Retrieves the singleton instance of this class.
  *
  * @return sfWebDebug A sfWebDebug implementation instance
  */
 public static function getInstance()
 {
     if (!isset(self::$instance)) {
         $class = __CLASS__;
         self::$instance = new $class();
         self::$instance->initialize();
     }
     return self::$instance;
 }
function _set_cache($cacheManager, $uri, $retval)
{
    $saved = $cacheManager->set($retval, $uri);
    if ($saved && sfConfig::get('sf_web_debug')) {
        $retval = sfWebDebug::getInstance()->decorateContentWithDebug($uri, $retval, true);
    }
    return $retval;
}
예제 #5
0
 public function render($templateVars = null)
 {
     $context = $this->getContext();
     $mode = $context->getController()->getRenderMode();
     if ($mode == sfView::RENDER_NONE) {
         return null;
     }
     $retval = null;
     $response = $context->getResponse();
     if (sfConfig::get('sf_cache')) {
         $key = $response->getParameterHolder()->remove('current_key', 'symfony/cache/current');
         $cache = $response->getParameter($key, null, 'symfony/cache');
         if ($cache !== null) {
             $cache = unserialize($cache);
             $retval = $cache['content'];
             $vars = $cache['vars'];
             $response->mergeProperties($cache['response']);
         }
     }
     $layout = $response->getParameter($this->moduleName . '_' . $this->actionName . '_layout', null, 'symfony/action/view');
     if (false === $layout) {
         $this->setDecorator(false);
     } else {
         if (null !== $layout) {
             $this->setDecoratorTemplate($layout . $this->getExtension());
         }
     }
     if ($templateVars === null) {
         $actionInstance = $context->getActionStack()->getLastEntry()->getActionInstance();
         $templateVars = $actionInstance->getVarHolder()->getAll();
     }
     $this->attributeHolder->add($this->getGlobalVars());
     $this->attributeHolder->add($retval !== null ? $vars : $templateVars);
     if ($retval === null) {
         $this->preRenderCheck();
         $template = $this->getDirectory() . '/' . $this->getTemplate();
         if (!is_readable($template)) {
             $template = sfConfig::get('sf_lib_dir') . '/modules/' . $this->moduleName . '/templates/' . $this->template;
             if (!is_readable($template)) {
                 throw new sfRenderException(sprintf('The template "%s" does not exist in: %s', $template, $this->directory));
             }
         }
         $retval = $this->renderFile($template);
         if (sfConfig::get('sf_cache') && $key !== null) {
             $cache = array('content' => $retval, 'vars' => $templateVars, 'view_name' => $this->viewName, 'response' => $context->getResponse());
             $response->setParameter($key, serialize($cache), 'symfony/cache');
             if (sfConfig::get('sf_web_debug')) {
                 $retval = sfWebDebug::getInstance()->decorateContentWithDebug($key, $retval, true);
             }
         }
     }
     if ($this->isDecorator()) {
         $retval = $this->decorate($retval);
     }
     if ($mode == sfView::RENDER_CLIENT) {
         $context->getResponse()->setContent($retval);
     }
     return $retval;
 }
function debug_message($message)
{
    if (sfConfig::get('sf_web_debug')) {
        sfWebDebug::getInstance()->logShortMessage($message);
    }
}
 /**
  * Gets an action template from the cache.
  *
  * @param string The internal URI
  */
 protected function getActionCache($uri)
 {
     // retrieve content from cache
     $retval = $this->cacheManager->get($uri);
     if ($retval && sfConfig::get('sf_web_debug')) {
         $cache = unserialize($retval);
         $this->response->mergeProperties($cache['response']);
         $cache['content'] = sfWebDebug::getInstance()->decorateContentWithDebug($uri, $cache['content'], false);
         $retval = serialize($cache);
     }
     $this->response->setParameter('current_key', $uri . '_action', 'symfony/cache/current');
     $this->response->setParameter($uri . '_action', $retval, 'symfony/cache');
     return $retval ? true : false;
 }
예제 #8
0
 /**
  * Renders the presentation.
  *
  * When the controller render mode is sfView::RENDER_CLIENT, this method will
  * render the presentation directly to the client and null will be returned.
  *
  * @return string A string representing the rendered presentation, if
  *                the controller render mode is sfView::RENDER_VAR, otherwise null
  */
 public function render($templateVars = null)
 {
     $context = $this->getContext();
     // get the render mode
     $mode = $context->getController()->getRenderMode();
     if ($mode == sfView::RENDER_NONE) {
         return null;
     }
     $retval = null;
     $response = $context->getResponse();
     if (sfConfig::get('sf_cache')) {
         $key = $response->getParameterHolder()->remove('current_key', 'symfony/cache/current');
         $cache = $response->getParameter($key, null, 'symfony/cache');
         if ($cache !== null) {
             $cache = unserialize($cache);
             $retval = $cache['content'];
             $vars = $cache['vars'];
             $response->mergeProperties($cache['response']);
         }
     }
     // decorator
     $layout = $response->getParameter($this->moduleName . '_' . $this->actionName . '_layout', null, 'symfony/action/view');
     if (false === $layout) {
         $this->setDecorator(false);
     } else {
         if (null !== $layout) {
             $this->setDecoratorTemplate($layout . $this->getExtension());
         }
     }
     // template variables
     if ($templateVars === null) {
         $actionInstance = $context->getActionStack()->getLastEntry()->getActionInstance();
         $templateVars = $actionInstance->getVarHolder()->getAll();
     }
     // assigns some variables to the template
     $this->attributeHolder->add($this->getGlobalVars());
     $this->attributeHolder->add($retval !== null ? $vars : $templateVars);
     // render template if no cache
     if ($retval === null) {
         // execute pre-render check
         $this->preRenderCheck();
         // render template file
         $template = $this->getDirectory() . '/' . $this->getTemplate();
         $retval = $this->renderFile($template);
         if (sfConfig::get('sf_cache') && $key !== null) {
             $cache = array('content' => $retval, 'vars' => $templateVars, 'view_name' => $this->viewName, 'response' => $context->getResponse());
             $response->setParameter($key, serialize($cache), 'symfony/cache');
             if (sfConfig::get('sf_web_debug')) {
                 $retval = sfWebDebug::getInstance()->decorateContentWithDebug($key, $retval, true);
             }
         }
     }
     // now render decorator template, if one exists
     if ($this->isDecorator()) {
         $retval = $this->decorate($retval);
     }
     // render to client
     if ($mode == sfView::RENDER_CLIENT) {
         $context->getResponse()->setContent($retval);
     }
     return $retval;
 }
예제 #9
0
파일: dmDebug.php 프로젝트: theolymp/diem
 protected static function debugger($var, $level = 1, $opt = array())
 {
     $CR = "\n";
     $die = $level > 2;
     $opt = dmString::toArray($opt);
     if (!sfConfig::get('sf_debug') && !dmArray::get($opt, "force")) {
         return;
     }
     $tag = dmArray::get($opt, "tag", "pre");
     if (dmArray::get($opt, "to_string", false) && is_array($var)) {
         array_walk_recursive($var, create_function('&$val', 'if(is_object($val)) {
       if (method_exists($val, "toString")) {
         $val = get_class($val)." : ".$val->toString();
       }
       elseif (method_exists($val, "__toString")) {
         $val = get_class($val)." : ".$val->__toString();
       }
     }'));
     } elseif (is_array($var)) {
         array_walk_recursive($var, create_function('&$val', 'if(is_object($val)) {
       if (method_exists($val, "toDebug")) {
         $val = get_class($val)." : ".print_r($val->toDebug(), true);
       }
       elseif (method_exists($val, "toArray")) {
         $val = get_class($val)." : ".print_r($val->toArray(), true);
       }
     }'));
     }
     if (dmConfig::isCli()) {
         $debugString = print_r($var, true);
         $debugString = substr($debugString, 0, self::MAX_DEBUG_LENGTH);
         echo $debugString;
         if (strlen($debugString) > self::MAX_DEBUG_LENGTH) {
             echo "\n---TRUNCATED---\n";
         }
         if ($die) {
             die;
         }
     } else {
         array_walk_recursive($var, create_function('&$val', 'if(is_string($val)) { $val = htmlspecialchars($val); }'));
         if (count($var) == 1) {
             $var = dmArray::first($var);
         }
         if (dmContext::hasInstance() && ($request = dm::getRequest())) {
             if ($request->isXmlHttpRequest()) {
                 echo "\n<{$tag}>";
                 $debugString = print_r($var, true);
                 echo substr($debugString, 0, self::MAX_DEBUG_LENGTH);
                 if (strlen($debugString) > self::MAX_DEBUG_LENGTH) {
                     echo "\n---TRUNCATED---\n";
                 }
                 echo "</{$tag}>\n";
                 if ($die) {
                     die;
                 }
                 return;
             }
         }
         ob_start();
         if ($level > 1) {
             print '<br /><' . $tag . ' style="text-align: left; border: 1px solid #aaa; border-left-width: 10px; background-color: #f4F4F4; color: #000; margin: 3px; padding: 3px; font-size: 11px;">';
             $debugString = print_r($var, true);
             echo substr($debugString, 0, self::MAX_DEBUG_LENGTH);
             if (strlen($debugString) > self::MAX_DEBUG_LENGTH) {
                 echo "\n---TRUNCATED---\n";
             }
             print "</{$tag}>";
         }
         $buffer = ob_get_clean();
         if ($level == 4) {
             ob_start();
             echo '<pre>';
             debug_print_backtrace();
             echo '</pre>';
             $dieMsg = ob_get_clean();
         } else {
             $backtrace = debug_backtrace();
             $dieMsg = str_replace(sfConfig::get("sf_root_dir"), "", dmArray::get($backtrace[1], 'file')) . " l." . dmArray::get($backtrace[1], 'line');
             //      $dieMsg  = '<pre>';
             //      $dieMsg .= isset($backtrace[0]['file']) ?     '> file     : <b>'.
             //      $backtrace[1]['file'] .'</b>'. $CR : '';
             //      $dieMsg .= isset($backtrace[0]['line']) ?     '> line     : <b>'.
             //      $backtrace[1]['line'] .'</b>'. $CR : '';
             //      $dieMsg .= isset($backtrace[1]['class']) ?    '> class    : <b>'.
             //      dmArray::get(dmArray::get($backtrace, 2, array()), 'class') .'</b>'. $CR : '';
             //      $dieMsg .= isset($backtrace[1]['function']) ? '> function : <b>'.
             //      dmArray::get(dmArray::get($backtrace, 2, array()), 'function') .'</b>'. $CR : '';
             //      $dieMsg .= '</pre>';
         }
         if ($level > 1) {
             print $buffer;
             if ($die) {
                 die($dieMsg);
             } else {
                 print $dieMsg;
             }
         } else {
             sfWebDebug::getInstance()->logShortMessage($buffer . $dieMsg);
         }
     }
 }