Changeset 6779
- Timestamp:
- 12/28/07 15:12:05 (10 months ago)
- Files:
-
- trunk/UPGRADE (modified) (7 diffs)
- trunk/data/config/factories.yml (modified) (2 diffs)
- trunk/data/config/i18n.yml (modified) (1 diff)
- trunk/data/config/settings.yml (modified) (2 diffs)
- trunk/data/data/mime_types.dat (deleted)
- trunk/data/data/mime_types.php (deleted)
- trunk/data/skeleton/app/app/config/factories.yml (modified) (1 diff)
- trunk/data/skeleton/app/app/config/i18n.yml (modified) (1 diff)
- trunk/data/skeleton/app/app/config/settings.yml (modified) (1 diff)
- trunk/data/skeleton/module/module/actions/components.class.php (modified) (1 diff)
- trunk/data/skeleton/plugin (added)
- trunk/data/skeleton/plugin/LICENSE (added)
- trunk/lib/action/sfAction.class.php (modified) (5 diffs)
- trunk/lib/addon/sfPager.class.php (modified) (1 diff)
- trunk/lib/config/sfDatabaseConfigHandler.class.php (modified) (1 diff)
- trunk/lib/config/sfFactoryConfigHandler.class.php (modified) (3 diffs)
- trunk/lib/config/sfLoader.class.php (modified) (3 diffs)
- trunk/lib/config/sfPhpConfigHandler.class.php (modified) (1 diff)
- trunk/lib/controller/sfController.class.php (modified) (5 diffs)
- trunk/lib/database/sfDatabaseManager.class.php (modified) (1 diff)
- trunk/lib/exception/sfActionException.class.php (deleted)
- trunk/lib/exception/sfContextException.class.php (deleted)
- trunk/lib/form/sfForm.class.php (modified) (5 diffs)
- trunk/lib/i18n/sfI18N.class.php (modified) (12 diffs)
- trunk/lib/log/sfConsoleLogger.class.php (modified) (1 diff)
- trunk/lib/log/sfFileLogger.class.php (modified) (1 diff)
- trunk/lib/plugins/sfCompat10Plugin/config/config.php (modified) (2 diffs)
- trunk/lib/plugins/sfCompat10Plugin/data (added)
- trunk/lib/plugins/sfCompat10Plugin/data/mime_types.dat (added)
- trunk/lib/plugins/sfCompat10Plugin/data/mime_types.php (added)
- trunk/lib/plugins/sfCompat10Plugin/lib/exception/sfActionException.class.php (added)
- trunk/lib/plugins/sfCompat10Plugin/lib/helper/PartialHelper.php (modified) (1 diff)
- trunk/lib/plugins/sfCompat10Plugin/test/functional/fixtures/apps/frontend/config/settings.yml (modified) (1 diff)
- trunk/lib/plugins/sfPropelPlugin/lib/propel/builder/SfObjectBuilder.php (modified) (1 diff)
- trunk/lib/plugins/sfPropelPlugin/lib/propel/builder/SfPeerBuilder.php (modified) (1 diff)
- trunk/lib/plugins/sfPropelPlugin/lib/vendor/creole/drivers/pgsql/metadata/PgSQLDatabaseInfo.php (modified) (1 diff)
- trunk/lib/plugins/sfPropelPlugin/test/functional/fixtures/apps/backend/config/settings.yml (modified) (1 diff)
- trunk/lib/plugins/sfPropelPlugin/test/functional/fixtures/apps/crud/config/settings.yml (modified) (1 diff)
- trunk/lib/request/sfRequest.class.php (modified) (1 diff)
- trunk/lib/request/sfWebRequest.class.php (modified) (18 diffs)
- trunk/lib/response/sfResponse.class.php (modified) (1 diff)
- trunk/lib/response/sfWebResponse.class.php (modified) (9 diffs)
- trunk/lib/routing/sfNoRouting.class.php (modified) (1 diff)
- trunk/lib/routing/sfPathInfoRouting.class.php (modified) (1 diff)
- trunk/lib/routing/sfPatternRouting.class.php (modified) (7 diffs)
- trunk/lib/routing/sfRouting.class.php (modified) (4 diffs)
- trunk/lib/task/generator/sfGeneratePluginTask.class.php (added)
- trunk/lib/task/project/sfProjectFreezeTask.class.php (modified) (2 diffs)
- trunk/lib/task/project/sfProjectUnfreezeTask.class.php (modified) (1 diff)
- trunk/lib/user/sfBasicSecurityUser.class.php (modified) (5 diffs)
- trunk/lib/user/sfUser.class.php (modified) (5 diffs)
- trunk/lib/util/sfBrowser.class.php (modified) (6 diffs)
- trunk/lib/util/sfContext.class.php (modified) (1 diff)
- trunk/lib/validator/sfValidatorFile.class.php (added)
- trunk/lib/view/sfEscapedViewParameterHolder.class.php (modified) (1 diff)
- trunk/test/functional/escapingTest.php (added)
- trunk/test/functional/fixtures/project/apps/cache/config/settings.yml (modified) (1 diff)
- trunk/test/functional/fixtures/project/apps/frontend/config/settings.yml (modified) (1 diff)
- trunk/test/functional/fixtures/project/apps/frontend/modules/escaping (added)
- trunk/test/functional/fixtures/project/apps/frontend/modules/escaping/actions (added)
- trunk/test/functional/fixtures/project/apps/frontend/modules/escaping/actions/actions.class.php (added)
- trunk/test/functional/fixtures/project/apps/frontend/modules/escaping/templates (added)
- trunk/test/functional/fixtures/project/apps/frontend/modules/escaping/templates/indexSuccess.php (added)
- trunk/test/functional/fixtures/project/apps/i18n/config/i18n.yml (modified) (1 diff)
- trunk/test/functional/fixtures/project/apps/i18n/config/settings.yml (modified) (1 diff)
- trunk/test/unit/exception/sfExceptionsTest.php (modified) (1 diff)
- trunk/test/unit/form/sfFormTest.php (modified) (4 diffs)
- trunk/test/unit/i18n/fixtures/messages.fr.xml (modified) (1 diff)
- trunk/test/unit/i18n/fixtures/messages.fr_BE.xml (added)
- trunk/test/unit/i18n/sfI18NTest.php (added)
- trunk/test/unit/request/sfWebRequestTest.php (modified) (2 diffs)
- trunk/test/unit/response/sfWebResponseTest.php (modified) (3 diffs)
- trunk/test/unit/user/sfBasicSecurityUserTest.php (modified) (4 diffs)
- trunk/test/unit/user/sfUserTest.php (modified) (1 diff)
- trunk/test/unit/util/sfBrowserTest.php (modified) (5 diffs)
- trunk/test/unit/validator/sfValidatorFileTest.php (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/UPGRADE
r6623 r6779 85 85 not singletons. 86 86 87 If you want to get one of those objects in your code, they are still87 If you want to get one of those objects in your code, they are 88 88 available from `sfContext`: 89 89 … … 93 93 sfContext::getInstance()->getLogger() 94 94 95 Here is their default configuration in `factories.yml`: 96 97 i18n: 98 class: sfI18N 99 param: 100 cache: 101 class: sfFileCache 102 param: 103 automatic_cleaning_factor: 0 104 cache_dir: %SF_I18N_CACHE_DIR% 105 lifetime: 86400 106 prefix: %SF_APP_DIR% 95 Routing 96 ~~~~~~~ 97 98 Here is the default configuration for the routing in `factories.yml`: 107 99 108 100 routing: … … 110 102 param: 111 103 load_configuration: true 104 105 The `project:upgrade1.1` task makes all the changes for you. 106 107 Logging 108 ~~~~~~~ 109 110 Here is the default configuration for logging in `factories.yml`: 112 111 113 112 logger: … … 120 119 param: 121 120 condition: %SF_WEB_DEBUG% 121 xdebug_logging: true 122 122 sf_file_debug: 123 123 class: sfFileLogger … … 146 146 147 147 The `project:upgrade1.1` task makes all those changes for you. 148 149 i18n 150 ~~~~ 151 152 Here is the default configuration for i18n in `factories.yml`: 153 154 i18n: 155 class: sfI18N 156 param: 157 source: XLIFF 158 debug: off 159 untranslated_prefix: "[T]" 160 untranslated_suffix: "[/T]" 161 cache: 162 class: sfFileCache 163 param: 164 automatic_cleaning_factor: 0 165 cache_dir: %SF_I18N_CACHE_DIR% 166 lifetime: 86400 167 prefix: %SF_APP_DIR% 168 169 The `i18n.yml` configuration file is not used anymore. 170 Instead, you can configure i18n in `factories.yml`. 171 172 The only exception is the `default_culture` setting which is now configurable in `settings.yml` 173 and do not depend on the i18n framework anymore: 174 175 default_culture: en 176 177 If your project has some specific settings, you must move your current configuration from the `i18n.yml` to 178 the `factories.yml` and add the default culture in `settings.yml` as shown above. 148 179 149 180 Cache Framework … … 263 294 * `->setErrors()` 264 295 * `->removeError()` 296 297 Deprecated methods in sfWebRequest 298 ---------------------------------- 299 300 The following methods of `sfWebRequest` have been deprecated and throw 301 a `sfConfigurationException` if `sf_compat_10` is set to `false`: 302 303 * `->getFile()` 304 * `->getFileError()` 305 * `->getFileName()` 306 * `->getFileNames()` 307 * `->getFilePath()` 308 * `->getFileSize()` 309 * `->getFileType()` 310 * `->hasFile()` 311 * `->hasFileError()` 312 * `->hasFileErrors()` 313 * `->hasFiles()` 314 * `->getFileValue()` 315 * `->getFileValues()` 316 * `->getFileExtension()` 317 * `->moveFile()` 265 318 266 319 sfValidator class … … 327 380 --------------- 328 381 329 The `sf_timeout` setting is not used anymore. To change the session timeout, you now have to edit the `factories.yml` instead if the `settings.yml`, and change the parameters of the `user` factory: 382 The `sf_timeout` setting is not used anymore. To change the session timeout, you now have to edit the 383 `factories.yml` instead if the `settings.yml`, and change the parameters of the `user` factory: 330 384 331 385 all: trunk/data/config/factories.yml
r6497 r6779 11 11 user: 12 12 class: myUser 13 param: 14 timeout: 1800 13 15 14 16 storage: … … 28 30 class: sfI18N 29 31 param: 30 load_configuration: true 32 source: XLIFF 33 debug: off 34 untranslated_prefix: "[T]" 35 untranslated_suffix: "[/T]" 31 36 cache: 32 37 class: sfFileCache trunk/data/config/i18n.yml
r4579 r6779 1 default:2 default_culture: en3 source: XLIFF4 debug: off5 untranslated_prefix: "[T]"6 untranslated_suffix: "[/T]"trunk/data/config/settings.yml
r5144 r6779 66 66 # Miscellaneous 67 67 strip_comments: on # Remove comments in core framework classes as defined in the core_compile.yml 68 timeout: 1800 # Session timeout, in seconds69 68 max_forwards: 5 70 69 path_info_array: SERVER … … 78 77 logging_enabled: on 79 78 79 # i18n 80 default_culture: en # default culture for a user 81 80 82 # enable 1.0 compatibility 81 83 compat_10: off trunk/data/skeleton/app/app/config/factories.yml
r6365 r6779 49 49 # class: sfI18N 50 50 # param: 51 # source: XLIFF 52 # debug: off 53 # untranslated_prefix: "[T]" 54 # untranslated_suffix: "[/T]" 51 55 # cache: 52 56 # class: sfFileCache trunk/data/skeleton/app/app/config/i18n.yml
r4579 r6779 1 #all:2 # default_culture: en3 # source: XLIFF4 # debug: off5 # untranslated_prefix: "[T]"6 # untranslated_suffix: "[/T]"trunk/data/skeleton/app/app/config/settings.yml
r6128 r6779 87 87 # # Miscellaneous 88 88 # strip_comments: on # Remove comments in core framework classes as defined in the core_compile.yml 89 # timeout: 1800 # Session timeout, in seconds90 89 # max_forwards: 5 91 90 # path_info_array: SERVER trunk/data/skeleton/module/module/actions/components.class.php
r6221 r6779 1 <?php2 3 /**4 * ##MODULE_NAME## components.5 *6 * @package ##PROJECT_NAME##7 * @subpackage ##MODULE_NAME##8 * @author ##AUTHOR_NAME##9 * @version SVN: $Id: components.class.php 2823 2006-11-26 08:26:18Z dwhittle $10 */11 class ##MODULE_NAME##Components extends sfComponents12 {13 14 }trunk/lib/action/sfAction.class.php
r6522 r6779 5 5 * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com> 6 6 * (c) 2004-2006 Sean Kerr. 7 * 7 * 8 8 * For the full copyright and license information, please view the LICENSE 9 9 * file that was distributed with this source code. … … 36 36 37 37 // include security configuration 38 require(sfConfigCache::getInstance()->checkConfig(sfConfig::get('sf_app_module_dir_name').'/'.$this->getModuleName().'/'.sfConfig::get('sf_app_module_config_dir_name').'/security.yml', true)); 38 if($file = sfConfigCache::getInstance()->checkConfig(sfConfig::get('sf_app_module_dir_name').'/'.$this->getModuleName().'/'.sfConfig::get('sf_app_module_config_dir_name').'/security.yml', true)) 39 { 40 require($file); 41 } 39 42 } 40 43 … … 256 259 * and bypasses the built-in view system. 257 260 * 261 * If the vars parameter is omitted, the action's internal variables 262 * will be passed, just as it would to a normal template. 263 * 264 * If the vars parameter is set then only those values are 265 * available in the partial. 266 * 258 267 * This method must be called as with a return: 259 268 * … … 261 270 * 262 271 * @param string partial name 272 * @param array vars 263 273 * 264 274 * @return sfView::NONE 265 275 */ 266 public function renderPartial($templateName )276 public function renderPartial($templateName, $vars = null) 267 277 { 268 278 sfLoader::loadHelpers('Partial'); 269 279 270 return $this->renderText(get_partial($templateName, $this->varHolder->getAll())); 280 $vars = $vars ? $vars : $this->varHolder->getAll(); 281 282 return $this->renderText(get_partial($templateName, $vars)); 271 283 } 272 284 … … 332 344 | sfRequest::PUT 333 345 | sfRequest::DELETE 334 | sfRequest::HEAD 346 | sfRequest::HEAD 335 347 | sfRequest::NONE; 336 348 } trunk/lib/addon/sfPager.class.php
r5016 r6779 94 94 public function haveToPaginate() 95 95 { 96 return (($this->get Page() != 0) && ($this->getNbResults() > $this->getMaxPerPage()));96 return (($this->getMaxPerPage() != 0) && ($this->getNbResults() > $this->getMaxPerPage())); 97 97 } 98 98 trunk/lib/config/sfDatabaseConfigHandler.class.php
r4597 r6779 101 101 102 102 // append new data 103 $data[] = sprintf("\n\$database = new %s();\n". 104 "\$database->initialize(%s, '%s');\n". 103 $data[] = sprintf("\n\$database = new %s(%s, '%s');\n". 105 104 "\$this->databases['%s'] = \$database;", 106 105 $dbConfig['class'], $parameters, $key, $key); trunk/lib/config/sfFactoryConfigHandler.class.php
r6524 r6779 106 106 107 107 case 'response': 108 $parameters = array_merge(array('charset' => sfConfig::get('sf_charset'), 'logging' => sfConfig::get('sf_logging_enabled')), is_array($parameters) ? $parameters : array()); 108 109 $instances[] = sprintf(" \$class = sfConfig::get('sf_factory_response', '%s');\n \$this->factories['response'] = new \$class(\$this->dispatcher, sfConfig::get('sf_factory_response_parameters', %s));", $class, var_export($parameters, true)); 109 110 … … 124 125 125 126 case 'user': 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_ i18n_default_culture'), 'use_flash' => sfConfig::get('sf_use_flash')), sfConfig::get('sf_factory_user_parameters', %s)));", $class, var_export(is_array($parameters) ? $parameters : array(), true));127 $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 128 break; 128 129 … … 151 152 } 152 153 153 $configuration = '';154 if (isset($parameters['load_configuration']) && $parameters['load_configuration'])155 {156 $configuration = " \$this->factories['i18n']->loadConfiguration();\n";157 }158 154 $instances[] = sprintf("\n if (sfConfig::get('sf_i18n'))\n {\n". 159 155 " \$class = sfConfig::get('sf_factory_i18n', '%s');\n". 160 156 "%s". 161 " \$this->factories['i18n'] = new \$class(\$this, \$cache);\n". 162 $configuration. 157 " \$this->factories['i18n'] = new \$class(\$this->dispatcher, \$cache, %s);\n". 163 158 " }\n" 164 , $class, $cache 159 , $class, $cache, var_export($parameters, true) 165 160 ); 166 161 break; 167 162 168 163 case 'routing': 169 $instances[] = sprintf(" \$class = sfConfig::get('sf_factory_routing', '%s');\n \$this->factories['routing'] = new \$class(\$this->dispatcher, array_merge(array('auto_shutdown' => false, 'suffix' => sfConfig::get('sf_suffix'), 'default_module' => sfConfig::get('sf_default_module'), 'default_action' => sfConfig::get('sf_default_action') ), sfConfig::get('sf_factory_routing_parameters', %s)));", $class, var_export(is_array($parameters) ? $parameters : array(), true));164 $instances[] = sprintf(" \$class = sfConfig::get('sf_factory_routing', '%s');\n \$this->factories['routing'] = new \$class(\$this->dispatcher, array_merge(array('auto_shutdown' => false, 'suffix' => sfConfig::get('sf_suffix'), 'default_module' => sfConfig::get('sf_default_module'), 'default_action' => sfConfig::get('sf_default_action'), 'logging' => sfConfig::get('sf_logging_enabled')), sfConfig::get('sf_factory_routing_parameters', %s)));", $class, var_export(is_array($parameters) ? $parameters : array(), true)); 170 165 if (isset($parameters['load_configuration']) && $parameters['load_configuration']) 171 166 { trunk/lib/config/sfLoader.class.php
r6509 r6779 134 134 * Gets the i18n directories to use globally. 135 135 * 136 * Returns null if the current i18n source is not a file based i18n backend (XLIFF or gettext).137 *138 136 * @return array An array of i18n directories 139 137 */ 140 138 static public function getI18NGlobalDirs() 141 139 { 142 if (!in_array(sfConfig::get('sf_i18n_source'), array('XLIFF', 'gettext')))143 {144 return null;145 }146 147 140 $dirs = array(); 148 141 … … 166 159 * Gets the i18n directories to use for a given module. 167 160 * 168 * Returns null if the current i18n source is not a file based i18n backend (XLIFF or gettext).169 *170 161 * @param string The module name 171 162 * … … 174 165 static public function getI18NDirs($moduleName) 175 166 { 176 if (!in_array(sfConfig::get('sf_i18n_source'), array('XLIFF', 'gettext')))177 {178 return null;179 }180 181 167 $dirs = array(); 182 168 trunk/lib/config/sfPhpConfigHandler.class.php
r4938 r6779 102 102 } 103 103 104 $warning = sprintf('{sfPhpConfigHandler} php.ini "%s" key is better set to "%s" (current value is "%s" - %s)', $key, var_export($value, true), var_export(ini_get($key), true), $this->get_ini_path());104 // $warning = sprintf('{sfPhpConfigHandler} php.ini "%s" key is better set to "%s" (current value is "%s" - %s)', $key, var_export($value, true), var_export(ini_get($key), true), $this->get_ini_path()); 105 105 // FIXME: sfContext is not yet initialized, so the logger is a sfNoLogger instance. 106 106 // $data[] = sprintf("if (ini_get('%s') != %s)\n{\n sfContext::getInstance()->getLogger()->warning('%s');\n}\n", $key, var_export($value, true), str_replace("'", "\\'", $warning)); trunk/lib/controller/sfController.class.php
r6499 r6779 165 165 } 166 166 167 throw new sfControllerException(sprintf(' {sfController} controller "%s/%s" does not exist in: %s.', $moduleName, $controllerName, implode(', ', $dirs)));167 throw new sfControllerException(sprintf('Controller "%s/%s" does not exist in: %s.', $moduleName, $controllerName, implode(', ', $dirs))); 168 168 } 169 169 … … 202 202 if (sfConfig::get('sf_logging_enabled')) 203 203 { 204 $this->dispatcher->notify(new sfEvent($this, 'application.log', array( 'Action does not exist')));204 $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Action "%s/%s" does not exist', $moduleName, $actionName)))); 205 205 } 206 206 … … 251 251 $this->context->getEventDispatcher()->notify(new sfEvent($this, 'controller.change_action', array('module' => $moduleName, 'action' => $actionName))); 252 252 253 if ($moduleName == sfConfig::get('sf_error_404_module') && $actionName == sfConfig::get('sf_error_404_action')) 254 { 255 $this->context->getResponse()->setStatusCode(404); 256 $this->context->getResponse()->setHttpHeader('Status', '404 Not Found'); 257 258 $this->dispatcher->notify(new sfEvent($this, 'controller.page_not_found', array('module' => $moduleName, 'action' => $actionName))); 259 } 260 253 261 // process the filter chain 254 262 $filterChain->execute(); … … 403 411 if (sfConfig::get('sf_logging_enabled')) 404 412 { 405 $this->dispatcher->notify(new sfEvent($this, 'application.log', array('sendEmail method is deprecated', 'priority' => 'err')));413 $this->dispatcher->notify(new sfEvent($this, 'application.log', array('sendEmail method is deprecated', 'priority' => sfLogger::ERR))); 406 414 } 407 415 … … 464 472 if ($actionEntry->getModuleName() == sfConfig::get('sf_login_module') && $actionEntry->getActionName() == sfConfig::get('sf_login_action')) 465 473 { 466 throw new sfException('Your mailaction is secured but the user is not authenticated.');474 throw new sfException('Your action is secured but the user is not authenticated.'); 467 475 } 468 476 else if ($actionEntry->getModuleName() == sfConfig::get('sf_secure_module') && $actionEntry->getActionName() == sfConfig::get('sf_secure_action')) 469 477 { 470 throw new sfException('Your mailaction is secured but the user does not have access.');478 throw new sfException('Your action is secured but the user does not have access.'); 471 479 } 472 480 } trunk/lib/database/sfDatabaseManager.class.php
r6497 r6779 82 82 83 83 /** 84 * Returns the names of all database connections. 85 * 86 * @return array An array containing all database connection names 87 */ 88 public function getNames() 89 { 90 return array_keys($this->databases); 91 } 92 93 /** 84 94 * Executes the shutdown procedure 85 95 * trunk/lib/form/sfForm.class.php
r6590 r6779 36 36 $isBound = false, 37 37 $taintedValues = array(), 38 $taintedFiles = array(), 38 39 $values = null, 39 40 $defaults = array(), … … 111 112 * 112 113 * @param array An array of input values 113 */ 114 public function bind($taintedValues) 114 * @param array An array of uploaded files (in the $_FILES or $_GET format) 115 */ 116 public function bind($taintedValues, $taintedFiles = array()) 115 117 { 116 118 $this->taintedValues = $taintedValues; 119 $this->taintedFiles = $taintedFiles; 117 120 $this->isBound = true; 118 121 $this->resetFormFields(); … … 120 123 try 121 124 { 122 $this->values = $this->validatorSchema->clean( $this->taintedValues);125 $this->values = $this->validatorSchema->clean(array_merge($this->taintedValues, self::convertFileInformation($this->taintedFiles))); 123 126 $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema); 124 127 … … 170 173 { 171 174 return $this->isBound ? $this->values : array(); 175 } 176 177 /** 178 * Returns a cleaned value by field name. 179 * 180 * If the form is not bound, it will return null. 181 * 182 * @param string The name of the value required 183 * @return string The cleaned value 184 */ 185 public function getValue($field) 186 { 187 return ($this->isBound && isset($this->values[$field])) ? $this->values[$field] : null; 172 188 } 173 189 … … 604 620 } 605 621 } 622 623 /** 624 * Converts uploaded file array to a format following the $_GET and $POST naming convention. 625 * 626 * It's safe to pass an already converted array, in which case this method just returns the original array unmodified. 627 * 628 * @param array An array representing uploaded file information 629 * 630 * @return array An array of re-ordered uploaded file information 631 */ 632 static public function convertFileInformation($taintedFiles) 633 { 634 return self::pathsToArray(preg_replace('#^(/[^/]+)?(/name|/type|/tmp_name|/error|/size)([^\s]*)( = [^\n]*)#m', '$1$3$2$4', self::arrayToPaths($taintedFiles))); 635 } 636 637 /** 638 * Converts a string of paths separated by newlines into an array. 639 * 640 * Code adapted from http://www.shauninman.com/archive/2006/11/30/fixing_the_files_superglobal 641 * @author Shaun Inman (www.shauninman.com) 642 * 643 * @param string A string representing an array 644 * 645 * @return Array An array 646 */ 647 static public function pathsToArray($str) 648 { 649 $array = array(); 650 $lines = explode("\n", trim($str)); 651 652 if (!empty($lines[0])) 653 { 654 foreach ($lines as $line) 655 { 656 list($path, $value) = explode(' = ', $line); 657 658 $steps = explode('/', $path); 659 array_shift($steps); 660 661 $insertion =& $array; 662 663 foreach ($steps as $step) 664 { 665 if (!isset($insertion[$step])) 666 { 667 $insertion[$step] = array(); 668 } 669 $insertion =& $insertion[$step]; 670 } 671 $insertion = ctype_digit($value) ? (int) $value : $value; 672 } 673 } 674 675 return $array; 676 } 677 678 /** 679 * Converts an array into a string containing the path to each of its values separated by a newline. 680 * 681 * Code adapted from http://www.shauninman.com/archive/2006/11/30/fixing_the_files_superglobal 682 * @author Shaun Inman (www.shauninman.com) 683 * 684 * @param Array An array 685 * 686 * @return string A string representing the array 687 */ 688 static public function arrayToPaths($array = array(), $prefix = '') 689 { 690 $str = ''; 691 $freshPrefix = $prefix; 692 693 foreach ($array as $key => $value) 694 { 695 $freshPrefix .= "/{$key}"; 696 697 if (is_array($value)) 698 { 699 $str .= self::arrayToPaths($value, $freshPrefix); 700 $freshPrefix = $prefix; 701 } 702 else 703 { 704 $str .= "{$prefix}/{$key} = {$value}\n"; 705 } 706 } 707 708 return $str; 709 } 606 710 } trunk/lib/i18n/sfI18N.class.php
r6497 r6779 20 20 { 21 21 protected 22 $ context= null,22 $dispatcher = null, 23 23 $cache = null, 24 $culture = null, 24 $options = array(), 25 $culture = 'en', 25 26 $messageSource = null, 26 27 $messageFormat = null; … … 31 32 * @see initialize() 32 33 */ 33 public function __construct( $context, sfCache $cache = null)34 { 35 $this->initialize($ context, $cache);34 public function __construct(sfEventDispatcher $dispatcher, sfCache $cache = null, $options = array()) 35 { 36 $this->initialize($dispatcher, $cache, $options); 36 37 } 37 38 … … 39 40 * Initializes this class. 40 41 * 41 * @param sfContext A sfContext implementation instance 42 */ 43 public function initialize($context, sfCache $cache = null) 44 { 45 $this->context = $context; 46 $this->cache = $cache; 47 48 $context->getEventDispatcher()->connect('user.change_culture', array($this, 'listenToChangeCultureEvent')); 49 $context->getEventDispatcher()->connect('controller.change_action', array($this, 'listenToChangeActionEvent')); 50 } 51 52 /** 53 * Loads i18n configuration. 54 */ 55 public function loadConfiguration() 56 { 57 include(sfConfigCache::getInstance()->checkConfig(sfConfig::get('sf_app_config_dir_name').'/i18n.yml')); 42 * @param sfEventDispatcher A sfEventDispatcher implementation instance 43 * @param sfCache A sfCache instance 44 * @param array An array of options 45 */ 46 public function initialize(sfEventDispatcher $dispatcher, sfCache $cache = null, $options = array()) 47 { 48 $this->dispatcher = $dispatcher; 49 $this->cache = $cache; 50 51 if (isset($options['culture'])) 52 { 53 $this->culture = $options['culture']; 54 unset($options['culture']); 55 } 56 57 $this->options = array_merge(array( 58 'source' => 'XLIFF', 59 'debug' => false, 60 'database' => 'default', 61 'untranslated_prefix' => '[T]', 62 'untranslated_suffix' => '[/T]', 63 ), $options); 64 65 $dispatcher->connect('user.change_culture', array($this, 'listenToChangeCultureEvent')); 66 $dispatcher->connect('controller.change_action', array($this, 'listenToChangeActionEvent')); 58 67 } 59 68 … … 61 70 * Sets the message source. 62 71 * 63 * @param mixed An array of i18n directories if message source is XLIFF or gettext, null otherwise72 * @param mixed An array of i18n directories if message source is a sfMessageSource_File subclass, null otherwise 64 73 * @param string The culture 65 74 */ … … 101 110 public function createMessageSource($dir = null) 102 111 { 103 if (in_array(sfConfig::get('sf_i18n_source'), array('Creole', 'MySQL', 'SQLite'))) 104 { 105 return sfMessageSource::factory(sfConfig::get('sf_i18n_source'), sfConfig::get('sf_i18n_database', 'default')); 106 } 107 else 108 { 109 return sfMessageSource::factory(sfConfig::get('sf_i18n_source'), $dir); 110 } 112 return sfMessageSource::factory($this->options['source'], self::isMessageSourceFileBased($this->options['source']) ? $dir : $this->options['database']); 113 } 114 115 /** 116 * Gets the current culture for i18n format objects. 117 * 118 * @return string The culture 119 */ 120 public function getCulture() 121 { 122 return $this->culture; 111 123 } 112 124 … … 123 135 { 124 136 $this->messageSource->setCulture($culture); 137 $this->messageFormat = null; 125 138 } 126 139 } … … 135 148 if (!isset($this->messageSource)) 136 149 { 137 $this->setMessageSource(sfLoader::getI18NGlobalDirs(), $this->c ontext->getUser()->getCulture());150 $this->setMessageSource(sfLoader::getI18NGlobalDirs(), $this->culture); 138 151 } 139 152 … … 152 165 $this->messageFormat = new sfMessageFormat($this->getMessageSource(), sfConfig::get('sf_charset')); 153 166 154 if ( sfConfig::get('sf_debug') && sfConfig::get('sf_i18n_debug'))167 if ($this->options['debug']) 155 168 { 156 $this->messageFormat->setUntranslatedPS(array( sfConfig::get('sf_i18n_untranslated_prefix'), sfConfig::get('sf_i18n_untranslated_suffix')));169 $this->messageFormat->setUntranslatedPS(array($this->options['untranslated_prefix'], $this->options['untranslated_suffix'])); 157 170 } 158 171 } … … 179 192 * 180 193 * @param string The ISO code 181 * @param string The culture 194 * @param string The culture for the translation 182 195 * 183 196 * @return string The country name 184 197 */ 185 public function getCountry($iso, $culture )186 { 187 $c = new sfCultureInfo( $culture);198 public function getCountry($iso, $culture = null) 199 { 200 $c = new sfCultureInfo(is_null($culture) ? $this->culture : $culture); 188 201 $countries = $c->getCountries(); 189 202 … … 213 226 * @return integer The timestamp 214 227 */ 215 public function getTimestampForCulture($date, $culture )216 { 217 list($d, $m, $y) = $this->getDateForCulture($date, $culture);218 219 return mktime(0, 0, 0, $m, $d, $y);228 public function getTimestampForCulture($date, $culture = null) 229 { 230 list($d, $m, $y) = $this->getDateForCulture($date, is_null($culture) ? $this->culture : $culture); 231 232 return is_null($d) ? null : mktime(0, 0, 0, $m, $d, $y); 220 233 } 221 234 … … 228 241 * @return array An array with the day, month and year 229 242 */ 230 public function getDateForCulture($date, $culture) 231 { 232 if (!$date) return 0; 233 234 $dateFormatInfo = @sfDateTimeFormatInfo::getInstance($culture); 243 public function getDateForCulture($date, $culture = null) 244 { 245 if (!$date) 246 { 247 return null; 248 } 249 250 $dateFormatInfo = @sfDateTimeFormatInfo::getInstance(is_null($culture) ? $this->culture : $culture); 235 251 $dateFormat = $dateFormatInfo->getShortDatePattern(); 236 252 … … 264 280 265 281 /** 282 * Returns true if messages are stored in a file. 283 * 284 * @param string The source name 285 * 286 * @return Boolean true if messages are stored in a file, false otherwise 287 */ 288 static public function isMessageSourceFileBased($source)