Migration
Instructions on how to migrate your existing Cherrycake application from earlier versions of the Cherrycake engine.
Migrating from 0.x to 1.x
Update your
composer.jsonfile to require Cherrycake version 1.x instead of version 0.x:composer updateCreate the
srcdirectory in your project and move your modules there. Remember modules still have their own subdirectory undersrc. You can remove the now emptyModulesdirectory.Move all your classes to the
srcdirectory. Remember classes do not have their own subdirectory, so they reside on the root ofsrc. You can remove the now emptyClassesdirectory.Rename all your modules and class files so they end with
.phpinstead of.class.php. For example:MyModule.phpinstead ofMyModule.class.php.Assign all your modules to their own namespace by modifying or adding a
namespacedirective at the top of the file. For example, if your module is calledMyModule, you should add this at the top ofsrc/MyModule/MyModule.php:namespace \CherrycakeApp\MyModule;Remember also to correctly namespace the class your modules extend from. For example, instead of your module being declared like this:
class MyModule extends Module {declare it like this instead:
class MyModule extends \Cherrycake\Module {Assign all your classes the right namespace. If they're classes related to a module, move them to the related module's directory and add the matching namespace. For example, if your class is called
ClassForMyModuleand is related to a module calledMyModule, move it tosrc/MyModuleand add this at the top ofsrc/MyModule/ClassForMyModule.php:namespace \CherrycakeApp\MyModule;You'll need to change how you reference Cherrycake's core modules and classes throughout your code. For example, the following code:
$e->Actions->mapAction( "homePage", new \Cherrycake\Action([ "moduleType" => ACTION_MODULE_TYPE_APP, "moduleName" => "Home", "methodName" => "homePage", "request" => new \Cherrycake\Request([ "pathComponents" => false, "parameters" => false ]) ]) );Should be changed to this:
$e->Actions->mapAction( "homePage", new \Cherrycake\Actions\Action([ "moduleType" => \Cherrycake\ACTION_MODULE_TYPE_APP, "moduleName" => "Home", "methodName" => "homePage", "request" => new \Cherrycake\Actions\Request([ "pathComponents" => false, "parameters" => false ]) ]) );Autoloading of classes is now handled via composer, so you need to add this to your
composer.jsonfile:"autoload": { "psr-4": { "CherrycakeApp\\": "src/" } }Update composer's autoload by running the command:
composer dump-autoloadSee the documentation at cherrycake.io and the examples at documentation-examples.cherrycake.io/ to see examples using this new namespacing.
Last updated
Was this helpful?