Skip to content

Commit

Permalink
Merge pull request #56 from cakephp/carbon-shim
Browse files Browse the repository at this point in the history
Add class aliases for Carbon.
  • Loading branch information
lorenzo committed Nov 16, 2015
2 parents ad1f04c + ea50cac commit e1d13dc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
8 changes: 5 additions & 3 deletions README.md
Expand Up @@ -36,9 +36,11 @@ First add `cakephp/chronos` to your `composer.json`:
php composer.phar require cakephp/chronos
```

To update your code you will need to update imports and typehints. Assuming
`src` contains the files you want to migrate, we could use the following to
update files:
By default Chronos includes a compatiblity script that creates aliases for the
relevant Carbon classes. This will let most applications upgrade with very
little effort. If you'd like to permanently update your code, you will
need to update imports and typehints. Assuming `src` contains the files you
want to migrate, we could use the following to update files:

```
# Replace imports
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -31,7 +31,8 @@
"autoload": {
"psr-4": {
"Cake\\Chronos\\": "src"
}
},
"files": ["src/carbon_compat.php"]
},
"autoload-dev": {
"psr-4": {
Expand Down
17 changes: 17 additions & 0 deletions src/carbon_compat.php
@@ -0,0 +1,17 @@
<?php
/**
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Brian Nesbitt <brian@nesbot.com>
* @link http://cakephp.org CakePHP(tm) Project
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/

// Create class aliases for Carbon so applications
// can upgrade more easily.
class_alias('Cake\Chronos\Chronos', 'Carbon\MutableDateTime');
class_alias('Cake\Chronos\ChronosInterface', 'Carbon\CarbonInterface');

0 comments on commit e1d13dc

Please sign in to comment.