Skip to content

Commit

Permalink
Add class aliases for Carbon.
Browse files Browse the repository at this point in the history
This should help make switching libraries even easier.
  • Loading branch information
markstory committed Nov 14, 2015
1 parent ad1f04c commit 1fa9b67
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
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. However, 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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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\Carbon');
class_alias('Cake\Chronos\ChronosInterface', 'Carbon\CarbonInterface');

0 comments on commit 1fa9b67

Please sign in to comment.