Development

Changeset 7524

You must first sign up to be able to contribute.

Changeset 7524

Show
Ignore:
Timestamp:
02/17/08 05:24:14 (2 years ago)
Author:
dwhittle
Message:

dwhittle: tweaked i18n + routing to use generic cache factory

+ moved cache to options in sfI18N (as it is optional)

Files:

Legend:

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

    r7523 r7524  
    2222 
    2323  cache: 
    24     class: sfAPCCache 
     24    class: sfAPCCache          # cache class: sfAPCCache, sfXCacheCache, sfMemcacheCache, sfEAccelleratorCache 
    2525    param: 
    2626      lifetime:  86400         # default cache ttl 
     
    4040      untranslated_prefix:  "[T]"   # prefix for untranslated strings 
    4141      untranslated_suffix:  "[/T]"  # suffix for untranslated strings 
    42       cache: 
    43         class: sfAPCCache 
    44         param: 
    45           lifetime:  86400         # default cache ttl 
    46           prefix:    %SF_APP_DIR%  # prefix 
    4742 
    4843  routing: 
    49     class: sfPatternRouting        # routing class: sfPatternRouting, sfPathInfoRouting, sfNoRouting 
     44    class: sfPatternRouting        # routing class: sfPatternRouting, sfPathInfoRouting, sfNoRouting 
    5045    param: 
    51       load_configuration: true     # load routing.yml configuration 
    52       suffix:             .        # Default suffix for generated URLs. If set to a single dot (.), no suffix is added. Possible values: .html, .php, and so on. 
    53       default_module:     default 
    54       default_action:     index 
     46      load_configuration:   true    # load routing.yml configuration 
     47      suffix:               .       # Default suffix for generated URLs. If set to a single dot (.), no suffix is added. Possible values: .html, .php, and so on. 
     48      default_module:       default 
     49      default_action:       index 
    5550 
    5651  logger: 
  • branches/dwhittle/1.1/lib/config/sfFactoryConfigHandler.class.php

    r7522 r7524  
    4848 
    4949    // available list of factories 
    50     $factories = array('logger', 'routing', 'controller', 'request', 'response', 'storage', 'i18n', 'user', 'view_cache'); 
     50    $factories = array('logger', 'cache', 'routing', 'controller', 'request', 'response', 'storage', 'i18n', 'user', 'view_cache'); 
    5151 
    5252    // let's do our fancy work 
     
    125125        case 'user': 
    126126          $instances[] = sprintf("  \$class = sfConfig::get('sf_factory_user', '%s');\n  \$this->factories['user'] = new \$class(\$this->dispatcher, \$this->factories['storage'], array_merge(array('auto_shutdown' => false, 'culture' => \$this->factories['request']->getParameter('sf_culture'), 'default_culture' => sfConfig::get('sf_default_culture', 'en'), 'use_flash' => sfConfig::get('sf_use_flash'), 'logging' => sfConfig::get('sf_logging_enabled')), sfConfig::get('sf_factory_user_parameters', %s)));", $class, var_export(is_array($parameters) ? $parameters : array(), true)); 
     127          break; 
     128 
     129        case 'cache': 
     130          $instances[] = sprintf("  \$class = sfConfig::get('sf_factory_cache', '%s');\n  \$this->factories['cache'] = new \$class(sfConfig::get('sf_factory_cache_parameters', %s));", $class, var_export(is_array($parameters) ? $parameters : array(), true)); 
    127131          break; 
    128132 
     
    141145 
    142146        case 'i18n': 
     147 
    143148          if (isset($parameters['cache'])) 
    144149          { 
    145             $cache = sprintf("    \$cache = new %s(%s);\n", $parameters['cache']['class'], var_export($parameters['cache']['param'], true)); 
     150            $instances[] = sprintf("    \$cache = new %s(%s);\n", $parameters['cache']['class'], var_export($parameters['cache']['param'], true)); 
    146151            unset($parameters['cache']); 
    147152          } 
    148153          else 
    149154          { 
    150             $cache = "    \$cache = null;\n"; 
     155            $instances[] = "    \$cache = \$this->factories['cache'];\n"; 
    151156          } 
    152157 
    153158          $instances[] = sprintf("\n  if (sfConfig::get('sf_i18n'))\n  {\n". 
    154159                     "    \$class = sfConfig::get('sf_factory_i18n', '%s');\n". 
    155                      "%s". 
    156                      "    \$this->factories['i18n'] = new \$class(\$this->dispatcher, \$cache, %s);\n". 
     160                     "    \$this->factories['i18n'] = new \$class(\$this->dispatcher, array_merge(array('cache' => \$cache), %s));\n". 
    157161                     "  }\n" 
    158                      , $class, $cache, var_export($parameters, true) 
     162                     , $class, var_export($parameters, true) 
    159163                     ); 
    160164          break; 
    161165 
    162166        case 'routing': 
    163           $instances[] = sprintf("  \$class = sfConfig::get('sf_factory_routing', '%s');\n  \$this->factories['routing'] = new \$class(\$this->dispatcher, array_merge(array('auto_shutdown' => false, 'logging' => sfConfig::get('sf_logging_enabled')), sfConfig::get('sf_factory_routing_parameters', %s)));", $class, var_export(is_array($parameters) ? $parameters : array(), true)); 
     167 
     168          if (isset($parameters['cache'])) 
     169          { 
     170            $instances[] = sprintf("    \$cache = new %s(%s);\n", $parameters['cache']['class'], var_export($parameters['cache']['param'], true)); 
     171            unset($parameters['cache']); 
     172          } 
     173          else 
     174          { 
     175            $instances[] = "    \$cache = \$this->factories['cache'];\n"; 
     176          } 
     177 
     178          $instances[] = sprintf("  \$class = sfConfig::get('sf_factory_routing', '%s');\n  \$this->factories['routing'] = new \$class(\$this->dispatcher, array_merge(array('auto_shutdown' => false, 'logging' => sfConfig::get('sf_logging_enabled'), 'cache' => \$cache), sfConfig::get('sf_factory_routing_parameters', %s)));", $class, var_export(is_array($parameters) ? $parameters : array(), true)); 
    164179          if (isset($parameters['load_configuration']) && $parameters['load_configuration']) 
    165180          { 
  • branches/dwhittle/1.1/lib/i18n/sfI18N.class.php

    r6865 r7524  
    3232   * @see initialize() 
    3333   */ 
    34   public function __construct(sfEventDispatcher $dispatcher, sfCache $cache = null, $options = array()) 
    35   { 
    36     $this->initialize($dispatcher, $cache, $options); 
     34  public function __construct(sfEventDispatcher $dispatcher, $options = array()) 
     35  { 
     36    $this->initialize($dispatcher, $options); 
    3737  } 
    3838 
     
    4444   * @param array             An array of options 
    4545   */ 
    46   public function initialize(sfEventDispatcher $dispatcher, sfCache $cache = null, $options = array()) 
     46  public function initialize(sfEventDispatcher $dispatcher, $options = array()) 
    4747  { 
    4848    $this->dispatcher = $dispatcher; 
    49     $this->cache      = $cache; 
     49 
     50    if(isset($options['cache']) && ($options['cache'] instanceof sfCache)) 
     51    { 
     52      $this->cache = $options['cache']; 
     53    } 
    5054 
    5155    if (isset($options['culture'])) 
  • branches/dwhittle/1.1/lib/routing/sfPatternRouting.class.php

    r7522 r7524  
    2424{ 
    2525  protected 
     26    $cache                  = null, 
    2627    $currentRouteName       = null, 
    2728    $currentInternalUri     = array(), 
     
    3637  { 
    3738    parent::initialize($dispatcher, $options); 
     39 
     40    if(isset($options['cache']) && ($options['cache'] instanceof sfCache)) 
     41    { 
     42      $this->cache = $options['cache']; 
     43    } 
    3844 
    3945    $this->setDefaultSuffix(isset($options['suffix']) ? $options['suffix'] : ''); 
  • branches/dwhittle/1.1/lib/task/generator/skeleton/app/app/config/factories.yml

    r7523 r7524  
    5959 
    6060  cache: 
    61     class: sfAPCCache 
     61    class: sfAPCCache          # cache classes: sfAPCCache, sfXCacheCache, sfMemcacheCache, sfEAccelleratorCache 
    6262    param: 
    6363      lifetime:  86400         # default cache ttl 
     
    7777      untranslated_prefix:  "[T]"   # prefix for untranslated strings 
    7878      untranslated_suffix:  "[/T]"  # suffix for untranslated strings 
    79       cache: 
    80         class: sfAPCCache 
    81         param: 
    82           lifetime:  86400         # default cache ttl 
    83           prefix:    %SF_APP_DIR%  # prefix 
    8479 
    8580  routing: 
    86     class: sfPatternRouting     # routing class: sfPatternRouting, sfPathInfoRouting, sfNoRouting 
     81    class: sfPatternRouting          # routing classes: sfPatternRouting, sfPathInfoRouting, sfNoRouting 
    8782    param: 
    88       load_configuration: true     # load routing.yml configuration 
    89       suffix:             .        # Default suffix for generated URLs. If set to a single dot (.), no suffix is added. Possible values: .html, .php, and so on. 
    90       default_module:     default 
    91       default_action:     index 
     83      load_configuration:   true     # load routing.yml configuration 
     84      suffix:               .        # Default suffix for generated URLs. If set to a single dot (.), no suffix is added. Possible values: .html, .php, and so on. 
     85      default_module:       default 
     86      default_action:       index 
    9287 
    9388  logger: 
  • branches/dwhittle/1.1/test/unit/i18n/extract/sfI18nExtractTest.php

    r7454 r7524  
    44 * This file is part of the symfony package. 
    55 * (c) Fabien Potencier <fabien.potencier@symfony-project.com> 
    6  *  
     6 * 
    77 * For the full copyright and license information, please view the LICENSE 
    88 * file that was distributed with this source code. 
     
    2323$dispatcher = new sfEventDispatcher(); 
    2424$cache = new sfNoCache(); 
    25 $i18n = new sfI18N($dispatcher, $cache); 
     25$i18n = new sfI18N($dispatcher, array('cache' => $cache)); 
    2626 
    2727class sfI18nExtractTest extends sfI18nExtract 
  • branches/dwhittle/1.1/test/unit/i18n/sfI18NTest.php

    r6688 r7524  
    44 * This file is part of the symfony package. 
    55 * (c) Fabien Potencier <fabien.potencier@symfony-project.com> 
    6  *  
     6 * 
    77 * For the full copyright and license information, please view the LICENSE 
    88 * file that was distributed with this source code. 
     
    2626// ->initialize() 
    2727$t->diag('->initialize()'); 
    28 $i18n = new sfI18N($dispatcher, $cache); 
     28$i18n = new sfI18N($dispatcher, array('cache' => $cache)); 
    2929$dispatcher->notify(new sfEvent(null, 'user.change_culture', array('culture' => 'fr'))); 
    3030$t->is($i18n->getCulture(), 'fr', '->initialize() connects to the user.change_culture event'); 
     
    3232// ->getCulture() ->setCulture() 
    3333$t->diag('->getCulture() ->setCulture()'); 
    34 $i18n = new sfI18N($dispatcher, $cache); 
     34$i18n = new sfI18N($dispatcher, array('cache' => $cache)); 
    3535$t->is($i18n->getCulture(), 'en', '->getCulture() returns the current culture'); 
    3636$i18n->setCulture('fr'); 
     
    4040$t->diag('->__()'); 
    4141sfConfig::set('sf_charset', 'UTF-8'); 
    42 $i18n = new sfI18N($dispatcher, $cache, array('culture' => 'fr')); 
     42$i18n = new sfI18N($dispatcher, array('cache' => $cache, 'culture' => 'fr')); 
    4343$t->is($i18n->__('an english sentence'), 'une phrase en français', '->__() translates a string'); 
    4444$args = array('%timestamp%' => $timestamp = time()); 
     
    5050 
    5151// debug 
    52 $i18n = new sfI18N($dispatcher, $cache, array('debug' => true)); 
     52$i18n = new sfI18N($dispatcher, array('cache' => $cache, 'debug' => true)); 
    5353$t->is($i18n->__('unknown'), '[T]unknown[/T]', '->__() adds a prefix and a suffix on untranslated strings if debug is on'); 
    54 $i18n = new sfI18N($dispatcher, $cache, array('debug' => true, 'untranslated_prefix' => '-', 'untranslated_suffix' => '#')); 
     54$i18n = new sfI18N($dispatcher, array('cache' => $cache, 'debug' => true, 'untranslated_prefix' => '-', 'untranslated_suffix' => '#')); 
    5555$t->is($i18n->__('unknown'), '-unknown#', '->initialize() can change the default prefix and suffix dor untranslated strings'); 
    5656 
    5757// ->getCountry() 
    5858$t->diag('->getCountry()'); 
    59 $i18n = new sfI18N($dispatcher, $cache, array('culture' => 'fr')); 
     59$i18n = new sfI18N($dispatcher, array('cache' => $cache, 'culture' => 'fr')); 
    6060$t->is($i18n->getCountry('FR'), 'France', '->getCountry() returns the name of a country for the current culture'); 
    6161$t->is($i18n->getCountry('FR', 'es'), 'Francia', '->getCountry() takes an optional culture as its second argument'); 
     
    6363// ->getNativeName() 
    6464$t->diag('->getNativeName()'); 
    65 $i18n = new sfI18N($dispatcher, $cache, array('culture' => 'fr')); 
     65$i18n = new sfI18N($dispatcher, array('cache' => $cache, 'culture' => 'fr')); 
    6666$t->is($i18n->getNativeName('fr'), 'français', '->getNativeName() returns the name of a culture'); 
    6767 
    6868// ->getTimestampForCulture() 
    6969$t->diag('->getTimestampForCulture()'); 
    70 $i18n = new sfI18N($dispatcher, $cache, array('culture' => 'fr')); 
     70$i18n = new sfI18N($dispatcher, array('cache' => $cache, 'culture' => 'fr')); 
    7171$t->is($i18n->getTimestampForCulture('15/10/2005'), mktime(0, 0, 0, '10', '15', '2005'), '->getTimestampForCulture() returns the timestamp for a data formatted in the current culture'); 
    7272$t->is($i18n->getTimestampForCulture('10/15/2005', 'en_US'), mktime(0, 0, 0, '10', '15', '2005'), '->getTimestampForCulture() can take a culture as its second argument'); 
     
    7575// ->getDateForCulture() 
    7676$t->diag('->getDateForCulture()'); 
    77 $i18n = new sfI18N($dispatcher, $cache, array('culture' => 'fr')); 
     77$i18n = new sfI18N($dispatcher, array('cache' => $cache, 'culture' => 'fr')); 
    7878$t->is($i18n->getDateForCulture('15/10/2005'), array('15', '10', '2005'), '->getDateForCulture() returns the day, month and year for a data formatted in the current culture'); 
    7979$t->is($i18n->getDateForCulture('10/15/2005', 'en_US'), array('15', '10', '2005'), '->getDateForCulture() can take a culture as its second argument'); 

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting.
Sensio Labs also supports several large Open-Source projects.