Changeset 7524
- Timestamp:
- 02/17/08 05:24:14 (2 years ago)
- Files:
-
- branches/dwhittle/1.1/lib/config/config/factories.yml (modified) (2 diffs)
- branches/dwhittle/1.1/lib/config/sfFactoryConfigHandler.class.php (modified) (3 diffs)
- branches/dwhittle/1.1/lib/i18n/sfI18N.class.php (modified) (2 diffs)
- branches/dwhittle/1.1/lib/routing/sfPatternRouting.class.php (modified) (2 diffs)
- branches/dwhittle/1.1/lib/task/generator/skeleton/app/app/config/factories.yml (modified) (2 diffs)
- branches/dwhittle/1.1/test/unit/i18n/extract/sfI18nExtractTest.php (modified) (2 diffs)
- branches/dwhittle/1.1/test/unit/i18n/sfI18NTest.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/dwhittle/1.1/lib/config/config/factories.yml
r7523 r7524 22 22 23 23 cache: 24 class: sfAPCCache 24 class: sfAPCCache # cache class: sfAPCCache, sfXCacheCache, sfMemcacheCache, sfEAccelleratorCache 25 25 param: 26 26 lifetime: 86400 # default cache ttl … … 40 40 untranslated_prefix: "[T]" # prefix for untranslated strings 41 41 untranslated_suffix: "[/T]" # suffix for untranslated strings 42 cache:43 class: sfAPCCache44 param:45 lifetime: 86400 # default cache ttl46 prefix: %SF_APP_DIR% # prefix47 42 48 43 routing: 49 class: sfPatternRouting # routing class: sfPatternRouting, sfPathInfoRouting, sfNoRouting44 class: sfPatternRouting # routing class: sfPatternRouting, sfPathInfoRouting, sfNoRouting 50 45 param: 51 load_configuration: true# load routing.yml configuration52 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: default54 default_action: index46 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 55 50 56 51 logger: branches/dwhittle/1.1/lib/config/sfFactoryConfigHandler.class.php
r7522 r7524 48 48 49 49 // 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'); 51 51 52 52 // let's do our fancy work … … 125 125 case 'user': 126 126 $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)); 127 131 break; 128 132 … … 141 145 142 146 case 'i18n': 147 143 148 if (isset($parameters['cache'])) 144 149 { 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)); 146 151 unset($parameters['cache']); 147 152 } 148 153 else 149 154 { 150 $ cache = " \$cache = null;\n";155 $instances[] = " \$cache = \$this->factories['cache'];\n"; 151 156 } 152 157 153 158 $instances[] = sprintf("\n if (sfConfig::get('sf_i18n'))\n {\n". 154 159 " \$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". 157 161 " }\n" 158 , $class, $cache,var_export($parameters, true)162 , $class, var_export($parameters, true) 159 163 ); 160 164 break; 161 165 162 166 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)); 164 179 if (isset($parameters['load_configuration']) && $parameters['load_configuration']) 165 180 { branches/dwhittle/1.1/lib/i18n/sfI18N.class.php
r6865 r7524 32 32 * @see initialize() 33 33 */ 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); 37 37 } 38 38 … … 44 44 * @param array An array of options 45 45 */ 46 public function initialize(sfEventDispatcher $dispatcher, sfCache $cache = null,$options = array())46 public function initialize(sfEventDispatcher $dispatcher, $options = array()) 47 47 { 48 48 $this->dispatcher = $dispatcher; 49 $this->cache = $cache; 49 50 if(isset($options['cache']) && ($options['cache'] instanceof sfCache)) 51 { 52 $this->cache = $options['cache']; 53 } 50 54 51 55 if (isset($options['culture'])) branches/dwhittle/1.1/lib/routing/sfPatternRouting.class.php
r7522 r7524 24 24 { 25 25 protected 26 $cache = null, 26 27 $currentRouteName = null, 27 28 $currentInternalUri = array(), … … 36 37 { 37 38 parent::initialize($dispatcher, $options); 39 40 if(isset($options['cache']) && ($options['cache'] instanceof sfCache)) 41 { 42 $this->cache = $options['cache']; 43 } 38 44 39 45 $this->setDefaultSuffix(isset($options['suffix']) ? $options['suffix'] : ''); branches/dwhittle/1.1/lib/task/generator/skeleton/app/app/config/factories.yml
r7523 r7524 59 59 60 60 cache: 61 class: sfAPCCache 61 class: sfAPCCache # cache classes: sfAPCCache, sfXCacheCache, sfMemcacheCache, sfEAccelleratorCache 62 62 param: 63 63 lifetime: 86400 # default cache ttl … … 77 77 untranslated_prefix: "[T]" # prefix for untranslated strings 78 78 untranslated_suffix: "[/T]" # suffix for untranslated strings 79 cache:80 class: sfAPCCache81 param:82 lifetime: 86400 # default cache ttl83 prefix: %SF_APP_DIR% # prefix84 79 85 80 routing: 86 class: sfPatternRouting # routing class: sfPatternRouting, sfPathInfoRouting, sfNoRouting81 class: sfPatternRouting # routing classes: sfPatternRouting, sfPathInfoRouting, sfNoRouting 87 82 param: 88 load_configuration: true # load routing.yml configuration89 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: default91 default_action: index83 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 92 87 93 88 logger: branches/dwhittle/1.1/test/unit/i18n/extract/sfI18nExtractTest.php
r7454 r7524 4 4 * This file is part of the symfony package. 5 5 * (c) Fabien Potencier <fabien.potencier@symfony-project.com> 6 * 6 * 7 7 * For the full copyright and license information, please view the LICENSE 8 8 * file that was distributed with this source code. … … 23 23 $dispatcher = new sfEventDispatcher(); 24 24 $cache = new sfNoCache(); 25 $i18n = new sfI18N($dispatcher, $cache);25 $i18n = new sfI18N($dispatcher, array('cache' => $cache)); 26 26 27 27 class sfI18nExtractTest extends sfI18nExtract branches/dwhittle/1.1/test/unit/i18n/sfI18NTest.php
r6688 r7524 4 4 * This file is part of the symfony package. 5 5 * (c) Fabien Potencier <fabien.potencier@symfony-project.com> 6 * 6 * 7 7 * For the full copyright and license information, please view the LICENSE 8 8 * file that was distributed with this source code. … … 26 26 // ->initialize() 27 27 $t->diag('->initialize()'); 28 $i18n = new sfI18N($dispatcher, $cache);28 $i18n = new sfI18N($dispatcher, array('cache' => $cache)); 29 29 $dispatcher->notify(new sfEvent(null, 'user.change_culture', array('culture' => 'fr'))); 30 30 $t->is($i18n->getCulture(), 'fr', '->initialize() connects to the user.change_culture event'); … … 32 32 // ->getCulture() ->setCulture() 33 33 $t->diag('->getCulture() ->setCulture()'); 34 $i18n = new sfI18N($dispatcher, $cache);34 $i18n = new sfI18N($dispatcher, array('cache' => $cache)); 35 35 $t->is($i18n->getCulture(), 'en', '->getCulture() returns the current culture'); 36 36 $i18n->setCulture('fr'); … … 40 40 $t->diag('->__()'); 41 41 sfConfig::set('sf_charset', 'UTF-8'); 42 $i18n = new sfI18N($dispatcher, $cache, array('culture' => 'fr'));42 $i18n = new sfI18N($dispatcher, array('cache' => $cache, 'culture' => 'fr')); 43 43 $t->is($i18n->__('an english sentence'), 'une phrase en français', '->__() translates a string'); 44 44 $args = array('%timestamp%' => $timestamp = time()); … … 50 50 51 51 // debug 52 $i18n = new sfI18N($dispatcher, $cache, array('debug' => true));52 $i18n = new sfI18N($dispatcher, array('cache' => $cache, 'debug' => true)); 53 53 $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' => '#')); 55 55 $t->is($i18n->__('unknown'), '-unknown#', '->initialize() can change the default prefix and suffix dor untranslated strings'); 56 56 57 57 // ->getCountry() 58 58 $t->diag('->getCountry()'); 59 $i18n = new sfI18N($dispatcher, $cache, array('culture' => 'fr'));59 $i18n = new sfI18N($dispatcher, array('cache' => $cache, 'culture' => 'fr')); 60 60 $t->is($i18n->getCountry('FR'), 'France', '->getCountry() returns the name of a country for the current culture'); 61 61 $t->is($i18n->getCountry('FR', 'es'), 'Francia', '->getCountry() takes an optional culture as its second argument'); … … 63 63 // ->getNativeName() 64 64 $t->diag('->getNativeName()'); 65 $i18n = new sfI18N($dispatcher, $cache, array('culture' => 'fr'));65 $i18n = new sfI18N($dispatcher, array('cache' => $cache, 'culture' => 'fr')); 66 66 $t->is($i18n->getNativeName('fr'), 'français', '->getNativeName() returns the name of a culture'); 67 67 68 68 // ->getTimestampForCulture() 69 69 $t->diag('->getTimestampForCulture()'); 70 $i18n = new sfI18N($dispatcher, $cache, array('culture' => 'fr'));70 $i18n = new sfI18N($dispatcher, array('cache' => $cache, 'culture' => 'fr')); 71 71 $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'); 72 72 $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'); … … 75 75 // ->getDateForCulture() 76 76 $t->diag('->getDateForCulture()'); 77 $i18n = new sfI18N($dispatcher, $cache, array('culture' => 'fr'));77 $i18n = new sfI18N($dispatcher, array('cache' => $cache, 'culture' => 'fr')); 78 78 $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'); 79 79 $t->is($i18n->getDateForCulture('10/15/2005', 'en_US'), array('15', '10', '2005'), '->getDateForCulture() can take a culture as its second argument');

