| 1 |
Upgrade from 1.0 to 1.1 |
|---|
| 2 |
======================= |
|---|
| 3 |
|
|---|
| 4 |
This document describes the changes made in symfony 1.1 and what need |
|---|
| 5 |
to be done to upgrade your symfony 1.0 projects. |
|---|
| 6 |
|
|---|
| 7 |
WARNING: symfony 1.1 is only compatible with PHP > 5.1. |
|---|
| 8 |
|
|---|
| 9 |
How to upgrade? |
|---|
| 10 |
--------------- |
|---|
| 11 |
|
|---|
| 12 |
To upgrade a project: |
|---|
| 13 |
|
|---|
| 14 |
* Upgrade symfony via PEAR or change your `config/config.php` |
|---|
| 15 |
to update the symfony directory. |
|---|
| 16 |
|
|---|
| 17 |
* Update the `symfony` file located in the project root directory |
|---|
| 18 |
by changing the line: |
|---|
| 19 |
|
|---|
| 20 |
include($sf_symfony_data_dir.'/bin/symfony.php'); |
|---|
| 21 |
|
|---|
| 22 |
to |
|---|
| 23 |
|
|---|
| 24 |
include($sf_symfony_lib_dir.'/command/cli.php'); |
|---|
| 25 |
|
|---|
| 26 |
* Launch the `project:upgrade1.1` task from your project directory |
|---|
| 27 |
to perform an automatic upgrade: |
|---|
| 28 |
|
|---|
| 29 |
$ ./symfony project:upgrade1.1 |
|---|
| 30 |
|
|---|
| 31 |
This task can be launched several times without any side effect. Each time |
|---|
| 32 |
you upgrade to a new symfony 1.1 beta / RC or the final symfony 1.1, you |
|---|
| 33 |
need to launch this task. |
|---|
| 34 |
|
|---|
| 35 |
* If you don't plan to upgrade the validation system or all your helpers to |
|---|
| 36 |
the new system, you must enable the compatibility mode in `settings.yml`: |
|---|
| 37 |
|
|---|
| 38 |
[yml] |
|---|
| 39 |
all: |
|---|
| 40 |
.settings: |
|---|
| 41 |
compat_10: on |
|---|
| 42 |
|
|---|
| 43 |
Here is a list of the things that will be enabled when switching to the |
|---|
| 44 |
compatibility mode (see the bundled `sfCompat10Plugin` plugin for |
|---|
| 45 |
more information): |
|---|
| 46 |
|
|---|
| 47 |
* Zend Framework and ezComponents bridges |
|---|
| 48 |
* sfProcessCache |
|---|
| 49 |
* validation system (validate.yml, validator classes, ...) |
|---|
| 50 |
* fill in filter |
|---|
| 51 |
* helpers |
|---|
| 52 |
* sfMail with phpmailer |
|---|
| 53 |
|
|---|
| 54 |
The remaining sections explains backward incompatible changes. |
|---|
| 55 |
|
|---|
| 56 |
Flash attributes |
|---|
| 57 |
---------------- |
|---|
| 58 |
|
|---|
| 59 |
Flash attributes are now managed directly by `sfUser`. New usage: |
|---|
| 60 |
|
|---|
| 61 |
[php] |
|---|
| 62 |
// action |
|---|
| 63 |
$this->getUser()->setFlash('notice', 'foo'); |
|---|
| 64 |
$notice = $this->getUser()->getFlash('notice'); |
|---|
| 65 |
|
|---|
| 66 |
// template |
|---|
| 67 |
<?php $sf_user->hasFlash('notice'): ?> |
|---|
| 68 |
<?php echo $sf_user->getFlash('notice') ?> |
|---|
| 69 |
<?php endif; ?> |
|---|
| 70 |
|
|---|
| 71 |
The `flash` entry in `filters.yml` must be removed too as the `sfFlashFilter` |
|---|
| 72 |
was removed. |
|---|
| 73 |
|
|---|
| 74 |
The `project:upgrade1.1` task makes all those changes for you. |
|---|
| 75 |
|
|---|
| 76 |
Deprecated methods in sfComponent |
|---|
| 77 |
--------------------------------- |
|---|
| 78 |
|
|---|
| 79 |
The following methods of `sfComponent` have been removed: |
|---|
| 80 |
|
|---|
| 81 |
* `->getPresentationFor()` |
|---|
| 82 |
* `->sendEmail()` |
|---|
| 83 |
|
|---|
| 84 |
They are accessible from `sfController`: |
|---|
| 85 |
|
|---|
| 86 |
[php] |
|---|
| 87 |
// action |
|---|
| 88 |
$this->getController()->getPresentationFor(...); |
|---|
| 89 |
|
|---|
| 90 |
The `project:upgrade1.1` task makes all those changes for you. |
|---|
| 91 |
|
|---|
| 92 |
Singletons |
|---|
| 93 |
---------- |
|---|
| 94 |
|
|---|
| 95 |
The sfI18N, sfRouting, and sfLogger objects are now factories and |
|---|
| 96 |
not singletons. |
|---|
| 97 |
|
|---|
| 98 |
If you want to get one of those objects in your code, they are |
|---|
| 99 |
available from `sfContext`: |
|---|
| 100 |
|
|---|
| 101 |
[php] |
|---|
| 102 |
sfContext::getInstance()->getI18N() |
|---|
| 103 |
sfContext::getInstance()->getRouting() |
|---|
| 104 |
sfContext::getInstance()->getLogger() |
|---|
| 105 |
|
|---|
| 106 |
Routing |
|---|
| 107 |
~~~~~~~ |
|---|
| 108 |
|
|---|
| 109 |
Here is the default configuration for the routing in `factories.yml`: |
|---|
| 110 |
|
|---|
| 111 |
[yml] |
|---|
| 112 |
routing: |
|---|
| 113 |
class: sfPatternRouting |
|---|
| 114 |
param: |
|---|
| 115 |
load_configuration: true |
|---|
| 116 |
|
|---|
| 117 |
The `project:upgrade1.1` task makes all the changes for you. |
|---|
| 118 |
|
|---|
| 119 |
Logging |
|---|
| 120 |
~~~~~~~ |
|---|
| 121 |
|
|---|
| 122 |
Here is the default configuration for logging in `factories.yml`: |
|---|
| 123 |
|
|---|
| 124 |
[yml] |
|---|
| 125 |
logger: |
|---|
| 126 |
class: sfAggregateLogger |
|---|
| 127 |
param: |
|---|
| 128 |
level: debug |
|---|
| 129 |
loggers: |
|---|
| 130 |
sf_web_debug: |
|---|
| 131 |
class: sfWebDebugLogger |
|---|
| 132 |
param: |
|---|
| 133 |
condition: %SF_WEB_DEBUG% |
|---|
| 134 |
xdebug_logging: true |
|---|
| 135 |
sf_file_debug: |
|---|
| 136 |
class: sfFileLogger |
|---|
| 137 |
param: |
|---|
| 138 |
file: %SF_LOG_DIR%/%SF_APP%_%SF_ENVIRONMENT%.log |
|---|
| 139 |
|
|---|
| 140 |
The `logging.yml` configuration file is not used anymore. |
|---|
| 141 |
Instead, you can configure logging in `factories.yml`. |
|---|
| 142 |
|
|---|
| 143 |
To disable logging in the production environment, you will have to change |
|---|
| 144 |
your application `factories.yml`: |
|---|
| 145 |
|
|---|
| 146 |
[yml] |
|---|
| 147 |
prod: |
|---|
| 148 |
logger: |
|---|
| 149 |
class: sfNoLogger |
|---|
| 150 |
param: |
|---|
| 151 |
level: err |
|---|
| 152 |
loggers: ~ |
|---|
| 153 |
|
|---|
| 154 |
There is also a new `logging_enabled` setting in `settings.yml`. |
|---|
| 155 |
This can be used to prevent logging in the production environment altogether: |
|---|
| 156 |
|
|---|
| 157 |
[yml] |
|---|
| 158 |
prod: |
|---|
| 159 |
.settings: |
|---|
| 160 |
logging_enabled: off |
|---|
| 161 |
|
|---|
| 162 |
The `project:upgrade1.1` task makes all those changes for you. |
|---|
| 163 |
|
|---|
| 164 |
i18n |
|---|
| 165 |
~~~~ |
|---|
| 166 |
|
|---|
| 167 |
Here is the default configuration for i18n in `factories.yml`: |
|---|
| 168 |
|
|---|
| 169 |
[yml] |
|---|
| 170 |
i18n: |
|---|
| 171 |
class: sfI18N |
|---|
| 172 |
param: |
|---|
| 173 |
source: XLIFF |
|---|
| 174 |
debug: off |
|---|
| 175 |
untranslated_prefix: "[T]" |
|---|
| 176 |
untranslated_suffix: "[/T]" |
|---|
| 177 |
cache: |
|---|
| 178 |
class: sfFileCache |
|---|
| 179 |
param: |
|---|
| 180 |
automatic_cleaning_factor: 0 |
|---|
| 181 |
cache_dir: %SF_I18N_CACHE_DIR% |
|---|
| 182 |
lifetime: 86400 |
|---|
| 183 |
prefix: %SF_APP_DIR% |
|---|
| 184 |
|
|---|
| 185 |
The `i18n.yml` configuration file is not used anymore. |
|---|
| 186 |
Instead, you can configure i18n in `factories.yml`. |
|---|
| 187 |
|
|---|
| 188 |
The only exception is the `default_culture` setting which is now configurable |
|---|
| 189 |
in `settings.yml` and do not depend on the i18n framework anymore: |
|---|
| 190 |
|
|---|
| 191 |
default_culture: en |
|---|
| 192 |
|
|---|
| 193 |
If your project has some specific settings, you must move your current |
|---|
| 194 |
configuration from the `i18n.yml` to the `factories.yml` and add the default |
|---|
| 195 |
culture in `settings.yml` as shown above. |
|---|
| 196 |
|
|---|
| 197 |
Cache Framework |
|---|
| 198 |
--------------- |
|---|
| 199 |
|
|---|
| 200 |
The `sfFunctionCache` class does not extend `sfFileCache` anymore. |
|---|
| 201 |
You must now pass a cache object to the constructor. |
|---|
| 202 |
The first argument to ->call() must now be a PHP callable. |
|---|
| 203 |
|
|---|
| 204 |
Some `sfCache` configuration parameter have changed their named to underscore names: |
|---|
| 205 |
|
|---|
| 206 |
* automaticCleaningFactor -> automatic_cleaning_factor |
|---|
| 207 |
* cacheDir -> cache_dir |
|---|
| 208 |
|
|---|
| 209 |
The `project:upgrade1.1` task makes all those changes for you. |
|---|
| 210 |
|
|---|
| 211 |
Autoloading |
|---|
| 212 |
----------- |
|---|
| 213 |
|
|---|
| 214 |
The `autoloading_function` setting in `settings.yml` is not used anymore. |
|---|
| 215 |
You can register autoloading callables in the application `config.php`. |
|---|
| 216 |
Here is the new default `config.php`: |
|---|
| 217 |
|
|---|
| 218 |
[php] |
|---|
| 219 |
<?php |
|---|
| 220 |
|
|---|
| 221 |
// include project configuration |
|---|
| 222 |
include(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php'); |
|---|
| 223 |
|
|---|
| 224 |
// symfony bootstraping |
|---|
| 225 |
require_once($sf_symfony_lib_dir.'/util/sfCore.class.php'); |
|---|
| 226 |
sfCore::bootstrap($sf_symfony_lib_dir, $sf_symfony_data_dir); |
|---|
| 227 |
|
|---|
| 228 |
// insert your own autoloading callables here |
|---|
| 229 |
|
|---|
| 230 |
if (sfConfig::get('sf_debug')) |
|---|
| 231 |
{ |
|---|
| 232 |
spl_autoload_register(array('sfAutoload', 'autoloadAgain')); |
|---|
| 233 |
} |
|---|
| 234 |
|
|---|
| 235 |
Thanks to the new `sfAutoload::autoloadAgain()` method, you won't need to clear |
|---|
| 236 |
the cache when you add or move classes in your project. This method will |
|---|
| 237 |
automatically find the changes and flush the autoloading cache. |
|---|
| 238 |
|
|---|
| 239 |
The `project:upgrade1.1` task makes all those changes for you. |
|---|
| 240 |
|
|---|
| 241 |
VERSION |
|---|
| 242 |
------- |
|---|
| 243 |
|
|---|
| 244 |
The lib/VERSION file has been removed. If you want to get the current symfony |
|---|
| 245 |
version, you can use the `SYMFONY_VERSION` constant. This constant is defined |
|---|
| 246 |
in `autoload/sfCoreAutoload.class.php` |
|---|
| 247 |
|
|---|
| 248 |
Routing |
|---|
| 249 |
------- |
|---|
| 250 |
|
|---|
| 251 |
To inject default route parameters, you can now use the `->setDefaultParameter()` |
|---|
| 252 |
method instead of using the `sf_routing_defaults` setting: |
|---|
| 253 |
|
|---|
| 254 |
[php] |
|---|
| 255 |
$this->context->getRouting()->setDefaultParameter($key, $value); |
|---|
| 256 |
|
|---|
| 257 |
I18N |
|---|
| 258 |
---- |
|---|
| 259 |
|
|---|
| 260 |
symfony core classes don't return internationalized strings anymore: |
|---|
| 261 |
|
|---|
| 262 |
[php] |
|---|
| 263 |
<?php echo __($sf_request->getError('foo')) ?> |
|---|
| 264 |
|
|---|
| 265 |
This behavior has changed for the following methods and functions: |
|---|
| 266 |
|
|---|
| 267 |
[php] |
|---|
| 268 |
sfWebRequest::getError() |
|---|
| 269 |
sfWebResponse::addMeta() |
|---|
| 270 |
|
|---|
| 271 |
The following helpers (in sfCompat10Plugin) still return internationalized data: |
|---|
| 272 |
|
|---|
| 273 |
[php] |
|---|
| 274 |
form_error() |
|---|
| 275 |
include_metas() |
|---|
| 276 |
|
|---|
| 277 |
The `getGlobalMessageSource()` and `getGlobalMessageFormat()` methods has been |
|---|
| 278 |
removed from the sfI18N class. They are now equivalent to `getMessageSource()` |
|---|
| 279 |
and `getMessageFormat()`. |
|---|
| 280 |
|
|---|
| 281 |
Logger |
|---|
| 282 |
------ |
|---|
| 283 |
|
|---|
| 284 |
Logger priorities are now constants: |
|---|
| 285 |
|
|---|
| 286 |
[php] |
|---|
| 287 |
sfLogger::INFO |
|---|
| 288 |
|
|---|
| 289 |
The `project:upgrade1.1` task makes all those changes for you. |
|---|
| 290 |
|
|---|
| 291 |
Deprecated methods in sfAction |
|---|
| 292 |
------------------------------ |
|---|
| 293 |
|
|---|
| 294 |
The following methods of `sfAction` have been deprecated and throw |
|---|
| 295 |
a `sfConfigurationException` if `sf_compat_10` is set to `false`: |
|---|
| 296 |
|
|---|
| 297 |
* `->validate()` |
|---|
| 298 |
* `->handleError()` |
|---|
| 299 |
|
|---|
| 300 |
Deprecated methods in sfRequest |
|---|
| 301 |
------------------------------- |
|---|
| 302 |
|
|---|
| 303 |
The following methods of `sfRequest` have been deprecated and throw |
|---|
| 304 |
a `sfConfigurationException` if `sf_compat_10` is set to `false`: |
|---|
| 305 |
|
|---|
| 306 |
* `->getError()` |
|---|
| 307 |
* `->getErrors()` |
|---|
| 308 |
* `->getErrorNames()` |
|---|
| 309 |
* `->hasError()` |
|---|
| 310 |
* `->hasErrors()` |
|---|
| 311 |
* `->setError()` |
|---|
| 312 |
* `->setErrors()` |
|---|
| 313 |
* `->removeError()` |
|---|
| 314 |
|
|---|
| 315 |
Deprecated methods in sfWebRequest |
|---|
| 316 |
---------------------------------- |
|---|
| 317 |
|
|---|
| 318 |
The following methods of `sfWebRequest` have been deprecated and throw |
|---|
| 319 |
a `sfConfigurationException` if `sf_compat_10` is set to `false`: |
|---|
| 320 |
|
|---|
| 321 |
* `->getFile()` |
|---|
| 322 |
* `->getFileError()` |
|---|
| 323 |
* `->getFileName()` |
|---|
| 324 |
* `->getFileNames()` |
|---|
| 325 |
* `->getFilePath()` |
|---|
| 326 |
* `->getFileSize()` |
|---|
| 327 |
* `->getFileType()` |
|---|
| 328 |
* `->hasFile()` |
|---|
| 329 |
* `->hasFileError()` |
|---|
| 330 |
* `->hasFileErrors()` |
|---|
| 331 |
* `->hasFiles()` |
|---|
| 332 |
* `->getFileValue()` |
|---|
| 333 |
* `->getFileValues()` |
|---|
| 334 |
* `->getFileExtension()` |
|---|
| 335 |
* `->moveFile()` |
|---|
| 336 |
|
|---|
| 337 |
sfValidator class |
|---|
| 338 |
----------------- |
|---|
| 339 |
|
|---|
| 340 |
If you use the symfony 1.0 interface for validation, your custom validators must |
|---|
| 341 |
now extend the `sfValidatorBase` class. |
|---|
| 342 |
|
|---|
| 343 |
`->initialize()` methods |
|---|
| 344 |
------------------------ |
|---|
| 345 |
|
|---|
| 346 |
Most symfony core classes are initialized thanks to a `->initialize()` method. |
|---|
| 347 |
As of symfony 1.1, this method is automatically called by `__construct()`, |
|---|
| 348 |
so, there is no need to call it by yourself. |
|---|
| 349 |
|
|---|
| 350 |
Configuration files loading |
|---|
| 351 |
--------------------------- |
|---|
| 352 |
|
|---|
| 353 |
Some core classes can be configured with a `.yml` file: |
|---|
| 354 |
|
|---|
| 355 |
*Class* | *Configuration file* |
|---|
| 356 |
-------------------- | -------------------------------- |
|---|
| 357 |
`sfAction` | `security.yml` |
|---|
| 358 |
`sfAutoload` | `autoload.yml` |
|---|
| 359 |
`sfConfigCache` | `config_handlers.yml` |
|---|
| 360 |
`sfContext` | `factories.yml` |
|---|
| 361 |
`sfController` | `generator.yml` and `module.yml` |
|---|
| 362 |
`sfDatabaseManager` | `databases.yml` |
|---|
| 363 |
`sfFilterChain` | `filters.yml` |
|---|
| 364 |
`sfI18N` | `i18n.yml` |
|---|
| 365 |
`sfPatternRouting` | `routing.yml` |
|---|
| 366 |
`sfPHPView` | `view.yml` |
|---|
| 367 |
`sfViewCacheManager` | `cache.yml` |
|---|
| 368 |
|
|---|
| 369 |
In symfony 1.1, the loading of the configuration file for ''independant'' |
|---|
| 370 |
sub-frameworks has been moved to a `loadConfiguration()` method to ease |
|---|
| 371 |
decoupling and reuse them without needing the whole framework: |
|---|
| 372 |
|
|---|
| 373 |
* `sfDatabaseManager` |
|---|
| 374 |
* `sfI18N` |
|---|
| 375 |
* `sfPatternRouting` |
|---|
| 376 |
|
|---|
| 377 |
So, for example, if you need a database manager in your batch script, |
|---|
| 378 |
you will have to change from: |
|---|
| 379 |
|
|---|
| 380 |
[php] |
|---|
| 381 |
$databaseManager = new sfDatabaseManager(); |
|---|
| 382 |
$databaseManager->initialize(); |
|---|
| 383 |
|
|---|
| 384 |
to: |
|---|
| 385 |
|
|---|
| 386 |
[php] |
|---|
| 387 |
$databaseManager = new sfDatabaseManager(); |
|---|
| 388 |
$databaseManager->loadConfiguration(); |
|---|
| 389 |
|
|---|
| 390 |
The `initialize()` call is not needed anymore (see the point above). |
|---|
| 391 |
|
|---|
| 392 |
Web Debug |
|---|
| 393 |
--------- |
|---|
| 394 |
|
|---|
| 395 |
The `web_debug` entry in `filters.yml` must be removed as the `sfWebDebugFilter` |
|---|
| 396 |
has been removed. The web debug toolbar is now injected in the response thanks |
|---|
| 397 |
to a listener. |
|---|
| 398 |
|
|---|
| 399 |
The `project:upgrade1.1` task makes all those changes for you. |
|---|
| 400 |
|
|---|
| 401 |
Session timeout |
|---|
| 402 |
--------------- |
|---|
| 403 |
|
|---|
| 404 |
The `sf_timeout` setting is not used anymore. To change the session timeout, |
|---|
| 405 |
you now have to edit `factories.yml` instead of the `settings.yml`, |
|---|
| 406 |
and change the parameters of the `user` factory: |
|---|
| 407 |
|
|---|
| 408 |
[yml] |
|---|
| 409 |
all: |
|---|
| 410 |
user: |
|---|
| 411 |
class: myUser |
|---|
| 412 |
param: |
|---|
| 413 |
timeout: 1800 # session timeout in seconds |
|---|
| 414 |
|
|---|
| 415 |
Routing configuration |
|---|
| 416 |
--------------------- |
|---|
| 417 |
|
|---|
| 418 |
The `sf_suffix`, `sf_default_module`, and `sf_default_action` settings are not |
|---|
| 419 |
used anymore. To change the default suffix, module, or action, you now have |
|---|
| 420 |
to edit `factories.yml` instead of `settings.yml`, and change the parameters |
|---|
| 421 |
of the `routing` factory: |
|---|
| 422 |
|
|---|
| 423 |
[yml] |
|---|
| 424 |
all: |
|---|
| 425 |
routing: |
|---|
| 426 |
class: sfPatternRouting |
|---|
| 427 |
param: |
|---|
| 428 |
load_configuration: true |
|---|
| 429 |
suffix: . # Default suffix for generated URLs. If set to a single dot (.), no suffix is added. Possible values: .html, .php, and so on. |
|---|
| 430 |
default_module: default # Default module and action to be called when |
|---|
| 431 |
default_action: index # A routing rule doesn't set it |
|---|
| 432 |
|
|---|
| 433 |
`php.yml` configuration file |
|---|
| 434 |
---------------------------- |
|---|
| 435 |
|
|---|
| 436 |
The `php.yml` configuration file has been removed. |
|---|
| 437 |
|
|---|
| 438 |
The only setting you will have to check by hand is `log_errors`, which was set |
|---|
| 439 |
to `on` by `php.yml`. |
|---|
| 440 |
|
|---|
| 441 |
`php.yml` is replaced by the `check_configuration.php` utility you can find |
|---|
| 442 |
in `data/bin`. It checks your environment against symfony requirements. |
|---|
| 443 |
You can launch it from anywhere: |
|---|
| 444 |
|
|---|
| 445 |
$ php /path/to/symfony/data/bin/check_configuration.php |
|---|
| 446 |
|
|---|
| 447 |
Even if you can use this utility from the command line, it's strongly recommended |
|---|
| 448 |
to launch it from the web by copying it under your web root directory as PHP can |
|---|
| 449 |
use different php.ini configuration files for the CLI and the web. |
|---|
| 450 |
|
|---|
| 451 |
`$sf_symfony_data_dir` removal |
|---|
| 452 |
------------------------------ |
|---|
| 453 |
|
|---|
| 454 |
In symfony 1.1, `$sf_symfony_data_dir` has been removed. All relevant files and |
|---|
| 455 |
directories from the symfony `data` directory have been moved to the `lib` |
|---|
| 456 |
directory: |
|---|
| 457 |
|
|---|
| 458 |
*Old Location* | *New Location* |
|---|
| 459 |
---------------------- | ----------------------------- |
|---|
| 460 |
`data/config` | `lib/config/config` |
|---|
| 461 |
`data/i18n` | `lib/i18n/data` |
|---|
| 462 |
`data/skeleton` | `lib/task/generator/skeleton` |
|---|
| 463 |
`data/modules/default` | `lib/controller/default` |
|---|
| 464 |
`data/web/errors` | `lib/exception/data` |
|---|
| 465 |
`data/exception.*` | `lib/exception/data` |
|---|
| 466 |
|
|---|
| 467 |
The symfony core has been upgraded to take these changes into account. |
|---|