Development

Changeset 12138

You must first sign up to be able to contribute.

Changeset 12138

Show
Ignore:
Timestamp:
10/11/08 07:38:49 (6 years ago)
Author:
fabien
Message:

[1.2] enhanced error templates

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.2/UPGRADE_TO_1_2

    r12085 r12138  
    4949 `sfCreoleSessionStorage` | `sfPDOSessionStorage` 
    5050  
    51 The `propel:build-db` task has been removed as this functionality is provided by 
    52 `propel:insert-sql`
     51The `propel:build-db` task has been removed as this functionality is not yet 
     52provided by Propel 1.3
    5353 
    5454The first step to upgrading is changing from Creole to PDO syntax in the 
     
    533533with form defaults. 
    534534 
     535All widgets have a new `label` option. This option sets the label for the widget 
     536when used in a widget schema context: 
     537 
     538    [php] 
     539    $widget = new sfWidgetFormInput(array('label' => 'Enter your name here')); 
     540    $widget->setLabel('Enter your name here'); 
     541    echo $widget->getLabel(); 
     542 
    535543Response 
    536544-------- 
     
    11031111Before symfony 1.2, the `propel:insert-sql` task was the only task to read its 
    11041112database configuration information from `propel.ini`. As of symfony 1.2, it 
    1105 reads it information from `databases.yml`. So, if you use several different 
     1113reads its information from `databases.yml`. So, if you use several different 
    11061114connections in your model, the task will take those into account. 
    1107 Thanks to this new feature, you can now use the [--connection|INFO] option 
     1115Thanks to this new feature, you can now use the `--connection` option 
    11081116if you want to only load SQL statements for a given connection: 
    11091117 
     
    16541662For example, an uncaught exception during an XML request could render 
    16551663`config/error/exception.xml.php` when your application is in debug mode, or 
    1656 `config/error/error500.xml.php` when your application is not in debug mode. 
    1657  
    1658 Your symfony 1.1 project's `config/error500.php` file will also render, but 
    1659 your symfony 1.0 project's `web/errors/error500.php` file must be moved. This 
    1660 is done for you by the upgrade task. 
     1664`config/error/error.xml.php` when your application is not in debug mode. 
     1665 
     1666If you had customized the 500 error template in your project, you will 
     1667need to manually move it to the new directory: 
     1668 
     1669  * For symfony 1.1: from `config/error500.php` to `config/error/error.html.php` 
     1670  * For symfony 1.0: from `web/errors/error500.php` to `config/error/error.html.php` 
  • branches/1.2/lib/autoload/sfCoreAutoload.class.php

    r12069 r12138  
    361361  'sfViewCacheManagerUpgrade' => 'task/project/upgrade1.1', 
    362362  'sfWebDebugUpgrade' => 'task/project/upgrade1.1', 
    363   'sfExceptionTemplatesUpgrade' => 'task/project/upgrade1.2', 
    364363  'sfFactories12Upgrade' => 'task/project/upgrade1.2', 
    365364  'sfPropel13Upgrade' => 'task/project/upgrade1.2', 
  • branches/1.2/lib/exception/data/error.atom.php

    r11805 r12138  
    1 <?php include dirname(__FILE__).'/error_500.xml.php' ?> 
     1<?php include sfException::getTemplatePathForError('xml', false) ?> 
  • branches/1.2/lib/exception/data/error.css.php

    r11805 r12138  
    11/* 
    2   500 Internal Server Error 
     2  <?php echo $code ?> <?php echo $text ?> 
    33*/ 
  • branches/1.2/lib/exception/data/error.html.php

    r11805 r12138  
    2828    <div class="sfTMessageWrap"> 
    2929      <h1>Oops! An Error Occurred</h1> 
    30       <h5>The server returned a "500 Internal Server Error".</h5> 
     30      <h5>The server returned a "<?php echo $code ?> <?php echo $text ?>".</h5> 
    3131    </div> 
    3232  </div> 
  • branches/1.2/lib/exception/data/error.js.php

    r11805 r12138  
    11/* 
    2   500 Internal Server Error 
     2  <?php echo $code ?> <?php echo $text ?> 
    33*/ 
  • branches/1.2/lib/exception/data/error.json.php

    r11805 r12138  
    11{ 
    2   'error'
     2  "error"
    33  { 
    4     'code':    500
    5     'message': 'Internal Server Error' 
     4    "code":    <?php echo $code ?>
     5    "message": "<?php echo $text ?>" 
    66  } 
    77} 
  • branches/1.2/lib/exception/data/error.rdf.php

    r11805 r12138  
    1 <?php include dirname(__FILE__).'/error_500.xml.php' ?> 
     1<?php include sfException::getTemplatePathForError('xml', false) ?> 
  • branches/1.2/lib/exception/data/error.txt.php

    r11805 r12138  
    22======================= 
    33 
    4 The server returned a "500 Internal Server Error". 
     4The server returned a "<?php echo $code ?> <?php echo $text ?>". 
    55 
    66Please e-mail us at [email] and let us know what you were doing when this 
  • branches/1.2/lib/exception/data/error.xml.php

    r11805 r12138  
    11<?xml version="1.0" encoding="<?php echo sfConfig::get('sf_charset', 'UTF-8') ?>"?> 
    2 <error code="500" message="Internal Server Error" /> 
     2<error code="<?php echo $code ?>" message="<?php echo $text ?>" /> 
  • branches/1.2/lib/exception/data/exception.atom.php

    r11805 r12138  
    1 <?php include dirname(__FILE__).'/exception.xml.php' ?> 
     1<?php include sfException::getTemplatePathForError('xml', true) ?> 
  • branches/1.2/lib/exception/data/exception.css.php

    r11805 r12138  
    11/* 
    2   500 Internal Server Error 
     2  <?php echo $code ?> <?php echo $text ?> 
    33 
    4   <?php echo $name."\n".$message."\n" ?> 
     4  <?php echo $name ?> 
     5  <?php echo $message ?> 
     6 
     7  <?php foreach ($traces as $trace): ?> 
     8    <?php echo $trace ?> 
     9 
     10  <?php endforeach; ?> 
    511*/ 
  • branches/1.2/lib/exception/data/exception.html.php

    r11805 r12138  
    3333  <center><div id="main"> 
    3434  <div style="float: right"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAAAZCAYAAAAiwE4nAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAEfklEQVRIx7VUa0wUVxT+Znd2FxZk0YKACAtaGwEDUhUTBTEIItmKYk3UNqalD7StMSQ1JKatP5omTYyx0VRrjPERX7XWAG2t9GVi3drU2h+gi4BCWV67lOe6O/uYmXtPf0BRrMBK6UlObmbON9935p6HQEQI1o7uXeSy1dsjHn2Xlpr0oKzililoEiIKymvOr9q+pzyZZN894moHcbWDZN892lOeTN9fKHgrWB5NsInZ7joOrtv4JgR2F4r0AxTpRwisEes2bsNtW+eBYHmCEqw8kVsp6oy6jMUFYIoTxFUQqWBqNzIWr4aoC9NVnlxZNSWC1mqLsa6ubd36zbug+m3gXBlypoCYAuavx4Ytu1Fbay+2VluME/GJEwHsnT3WpLlzhbi4Z6D46gBosP/gVQDA669kIzJSRWxcApLnPie0dw3cALBw0k1z5dyKr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+2d80or7Ra0ZtxAAAAABJRU5ErkJggg==" /></div> 
    35   <h1>[<?php echo $name ?>]</h1> 
     35  <h1><?php echo $code ?> | <?php echo $text ?> | <?php echo $name ?></h1> 
    3636  <h2 id="message"><?php echo str_replace("\n", '<br />', htmlspecialchars($message, ENT_QUOTES, sfConfig::get('sf_charset', 'UTF-8'))) ?></h2> 
    3737  <h2>stack trace</h2> 
  • branches/1.2/lib/exception/data/exception.js.php

    r11805 r12138  
    11/* 
    2   500 Internal Server Error 
     2  <?php echo $code ?> <?php echo $text ?> 
    33 
    44  <?php echo $name ?> 
    55  <?php echo $message ?> 
     6 
     7  <?php foreach ($traces as $trace): ?> 
     8    <?php echo $trace ?> 
     9 
     10  <?php endforeach; ?> 
    611*/ 
  • branches/1.2/lib/exception/data/exception.json.php

    r11805 r12138  
    11{ 
    2   'error'
     2  "error"
    33  { 
    4     'code':    500
    5     'message': 'Internal Server Error'
    6     'debug'
     4    "code":    <?php echo $code ?>
     5    "message": "<?php echo addcslashes($text, "\0..\37\\'\"\177..\377\/") ?>"
     6    "debug"
    77    { 
    8       'name':   '<?php echo $name ?>', 
    9       'message':'<?php echo addcslashes($message, "\0..\37\\'\"\177..\377\/") ?>' 
     8      "name":    "<?php echo $name ?>", 
     9      "message": "<?php echo addcslashes($message, "\0..\37\\'\"\177..\377\/") ?>" 
     10      "traces": 
     11      [ 
     12<?php foreach ($traces as $trace): ?> 
     13        "<?php echo addcslashes($trace, "\0..\37\\'\"\177..\377\/") ?>" 
     14 
     15<?php endoreach; ?> 
     16      ] 
    1017    } 
    1118  } 
  • branches/1.2/lib/exception/data/exception.rdf.php

    r11805 r12138  
    1 <?php include dirname(__FILE__).'/exception.xml.php' ?> 
     1<?php include sfException::getTemplatePathForError('xml', true) ?> 
  • branches/1.2/lib/exception/data/exception.txt

    r10633 r12138  
    1 [exception]   <?php echo $name ?>  
    2 [message]     <?php echo $message ?>  
     1[exception]   <?php echo $code.' | '.$text.' | '.$name ?> 
     2[message]     <?php echo $message ?> 
    33<?php if (count($traces) > 0): ?> 
    44[stack trace] 
     
    99<?php endif; ?> 
    1010[symfony]     v. <?php echo SYMFONY_VERSION ?> (symfony-project.org) 
    11 [PHP]         v. <?php echo PHP_VERSION ?>  
     11[PHP]         v. <?php echo PHP_VERSION ?> 
  • branches/1.2/lib/exception/data/exception.xml.php

    r11805 r12138  
    11<?xml version="1.0" encoding="<?php echo sfConfig::get('sf_charset', 'UTF-8') ?>"?> 
    2 <error code="500" message="Internal Server Error"> 
     2<error code="<?php echo $code ?>" message="<?php echo $text ?>"> 
    33  <debug> 
    44    <name><?php echo $name ?></name> 
    55    <message><?php echo htmlspecialchars($message, ENT_QUOTES, sfConfig::get('sf_charset', 'UTF-8')) ?></message> 
     6    <traces> 
     7<?php foreach ($traces as $trace): ?> 
     8        <trace><?php echo $trace ?></trace> 
     9<?php endforeach; ?> 
     10    </traces> 
    611  </debug> 
    712</error> 
  • branches/1.2/lib/exception/sfException.class.php

    r11837 r12138  
    137137        } 
    138138      } 
     139 
     140      $code = $response->getStatusCode(); 
     141      $text = $response->getStatusText(); 
    139142    } 
    140143    else 
     
    147150        header('Content-Type: text/html; charset='.sfConfig::get('sf_charset', 'utf-8')); 
    148151      } 
    149     } 
    150  
    151     $templatePaths = array( 
    152       sfConfig::get('sf_app_config_dir').'/error', 
    153       sfConfig::get('sf_config_dir').'/error', 
    154       dirname(__FILE__).'/data', 
    155     ); 
     152 
     153      $code = '500'; 
     154      $text = 'Internal Server Error'; 
     155    } 
    156156 
    157157    // send an error 500 if not in debug mode 
    158158    if (!sfConfig::get('sf_debug')) 
    159159    { 
    160       $template = sprintf('error500.%s.php', $format); 
    161       foreach ($templatePaths as $path) 
    162       { 
    163         if (is_null($path)) 
    164         { 
    165           continue; 
    166         } 
    167  
    168         if (is_readable($file = $path.'/'.$template)) 
    169         { 
    170           include $file; 
    171           return; 
    172         } 
    173  
    174         // for backward compatibility with symfony 1.1 
    175         if ('html' == $format && is_readable($file = $path.'/../error500.php')) 
    176         { 
    177           include $file; 
    178           return; 
    179         } 
     160      if ($template = self::getTemplatePathForError($format, false)) 
     161      { 
     162        include $template; 
     163        return; 
    180164      } 
    181165    } 
     
    183167    $message = is_null($exception->getMessage()) ? 'n/a' : $exception->getMessage(); 
    184168    $name    = get_class($exception); 
    185     $traces  = self::getTraces($exception, 0 == strncasecmp(PHP_SAPI, 'cli', 3) ? 'plain' : 'html'); 
     169    $traces  = self::getTraces($exception, 'html' != $format || 0 == strncasecmp(PHP_SAPI, 'cli', 3) ? 'plain' : 'html'); 
    186170 
    187171    // dump main objects values 
     
    198182    } 
    199183 
    200     $template = sprintf('exception.%s.php', $format); 
     184    if ($template = self::getTemplatePathForError($format, true)) 
     185    { 
     186      include $template; 
     187      return; 
     188    } 
     189  } 
     190 
     191  /** 
     192   * Returns the path for the template error message. 
     193   * 
     194   * @param  string  $format The request format 
     195   * @param  Boolean $debug  Whether to return a template for the debug mode or not 
     196   * 
     197   * @return string|Boolean  false if the template cannot be found for the given format, 
     198   *                         the absolute path to the template otherwise 
     199   */ 
     200  static public function getTemplatePathForError($format, $debug) 
     201  { 
     202    $templatePaths = array( 
     203      sfConfig::get('sf_app_config_dir').'/error', 
     204      sfConfig::get('sf_config_dir').'/error', 
     205      dirname(__FILE__).'/data', 
     206    ); 
     207 
     208    $template = sprintf('%s.%s.php', $debug ? 'exception' : 'error', $format); 
    201209    foreach ($templatePaths as $path) 
    202210    { 
    203211      if (!is_null($path) && is_readable($file = $path.'/'.$template)) 
    204212      { 
    205         include $file; 
    206         return; 
    207       } 
    208     } 
     213        return $file; 
     214      } 
     215    } 
     216 
     217    return false; 
    209218  } 
    210219 
     
    322331      else if ($value === null) 
    323332      { 
    324         $result[] = '<em>null</em>'; 
     333        $result[] = $format == 'html' ? '<em>null</em>' : 'null'; 
    325334      } 
    326335      else if (!is_int($key)) 
    327336      { 
    328         $result[] = "'$key' =&gt; '$value'"; 
     337        $result[] = $format == 'html' ? "'$key' =&gt; '$value'" : "'$key' => '$value'"; 
    329338      } 
    330339      else 
  • branches/1.2/lib/view/sfView.class.php

    r11286 r12138  
    356356    if (!is_readable($this->directory.'/'.$this->template)) 
    357357    { 
    358       throw new sfRenderException(sprintf('The template "%s" does not exist or is unreadable in "%s".', $this->template, $this->directory)); 
     358      // 404? 
     359      if ('404' == $this->context->getResponse()->getStatusCode()) 
     360      { 
     361        // use default exception templates 
     362        $this->directory = null; 
     363        $this->template = sfException::getTemplatePathForError($this->context->getRequest()->getRequestFormat(), $this->context->getConfiguration()->isDebug()); 
     364        $this->setAttribute('code', '404'); 
     365        $this->setAttribute('text', 'Not Found'); 
     366      } 
     367      else 
     368      { 
     369        throw new sfRenderException(sprintf('The template "%s" does not exist or is unreadable in "%s".', $this->template, $this->directory)); 
     370      } 
    359371    } 
    360372