{"shas":[["df267c72e46f9360b377421233f309a4b82b1256","d4f8dcd89cfe40276c0fbf336903f4a05ab082c9@gmail.com","replaced the current way to create reusable applications\n\nThe main idea is the move of all controller-related code from Application to\nControllerCollection. Reusable applications are now instances of\nControllerCollection instead of Application instances. That way, there is only\none \"true\" Application instance, and thus only one Pimple container.\n\nReusable applications can now be packaged as classes, like Extensions. It\nallows to package services and controllers into one extension.\n\nBenefits:\n\n * less hackish (proper wrapping in a class, no need to add a temporary route, no need for the LazyApplication anymore)\n * less code\n * simple and straightforward code (no magic anymore)\n * less side-effects\n * fix most severe/annoying limitations of the current implementation (from what I've read in the mailing-list and the Github issues)\n * better encapsulation of \"reusable\" applications\n * better separation of concerns\n * simple usage is exactly the same as before (as Application proxies the ControllerCollection methods for the \"default\" app)\n\nUpgrading is as simple as replacing Application with ControllerCollection for\nreusable apps (note that a reusable app is not \"standalone\" anymore):\n\n    $mounted = new ControllerCollection();\n    $mounted->get('/bar', function() { return 'foo'; });\n\n    $app->mount('/foo', $mounted);\n\nA better way now is to create a class:\n\n    use Silex\\ApplicationExtensionInterface;\n\n    class FooApplication implements ApplicationExtensionInterface\n    {\n        public function connect(Application $app)\n        {\n            $controllers = new ControllerCollection();\n            $controllers->get('/bar', function() { return 'foo'; });\n\n            return $controllers;\n        }\n    }\n\n    $app->mount('/foo', new FooApplication());\n\nNote that you get the \"master\" application, so that you have access to the\nservices defined here.\n\nIf you want to register services, you can do so in the same extension:\n\n    use Silex\\ApplicationExtensionInterface;\n    use Silex\\ExtensionInterface;\n\n    class FooApplication implements ApplicationExtensionInterface, ExtensionInterface\n    {\n        public function register(Application $app)\n        {\n            $app['some_service'] = ...;\n        }\n\n        public function connect(Application $app)\n        {\n            $controllers = new ControllerCollection();\n            $controllers->get('/bar', function(Application $app) {\n                $app['some_service']->...;\n\n                return 'foo';\n            });\n\n            return $controllers;\n        }\n    }\n\n    $ext = new FooApplication();\n    $app->register($ext);\n    $app->mount('/foo', $ext);","Fabien Potencier"]],"ref":"refs/heads/refactoring","size":1,"head":"df267c72e46f9360b377421233f309a4b82b1256","push_id":40750568}