From a8b6afba674a2d636a3c583d99d352f570ca8881 Mon Sep 17 00:00:00 2001 From: mxc-commons Date: Wed, 13 Nov 2013 06:00:53 +0100 Subject: [PATCH] Support for content ViewModel added mca-Rule definition changed. See readme.md. --- README.md | 81 ++++--- .../Controller/Plugin/LayoutSchemePlugin.php | 53 +---- src/MxcLayoutScheme/Module.php | 8 +- .../Service/LayoutSchemeService.php | 214 ++++++++++-------- .../Service/LayoutSchemeServiceFactory.php | 16 ++ 5 files changed, 196 insertions(+), 176 deletions(-) create mode 100644 src/MxcLayoutScheme/Service/LayoutSchemeServiceFactory.php diff --git a/README.md b/README.md index be58395..6d9e7be 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ MxcLayoutScheme =============== -Version 0.4.0 created by Frank Hein and the mxc-commons team. +Version 0.5.0 created by Frank Hein and the mxc-commons team. MxcLayoutScheme is part of the [maxence openBeee initiative](http://www.maxence.de/mxcweb/index.php/themen/open-business/) by [maxence business consulting gmbh, Germany](http://www.maxence.de). @@ -61,6 +61,8 @@ view template as far as possible. We want to achieve that within the controller **9. Provide support for dispatch errors** +**10. Provide support for content view template** + In the current version you can either assign the layout variables within the controller action via `layoutScheme` controller plugin. Alternatively you may supply an event handler for pre- and postprocessing. We provide an example here. Installation @@ -198,13 +200,34 @@ the values specify the layout templates to apply. #### `` Keys for `` are like `[\[\]]`, -where `` is the name of the module, `` is the name of the controller (without 'Controller' suffix), `` is the name of the the controller action. +where `` is the name of the module, `` is the name of the controller as it is registered to the ControllerLoader, `` is the name of the the controller action. Examples - 'MyModule' //--- applies to all controllers in module - 'MyModule\MyController' //--- applies to all actions of a controller - 'MyModule\MyController\MyAction' //--- applies to a particular controller action + Generic + + 'MyModule' //--- applies to all controllers in module + 'MyModule\MyController' //--- applies to all actions of a controller + 'MyModule\MyController\MyAction' //--- applies to a particular controller action + + ZfcUser controller (registered as zfcuser) + + 'ZfcUser' //--- applies to all controllers of ZfcUser (there is only one ;) + 'ZfcUser\zfcuser' //--- applies to the controller registered with 'zfcuser' + //--- (ZfcUser\Controller\UserController) + 'ZfcUser\zfcuser\login' //--- login action + + MxcUserManagement controller (registered as 'MxcUserManagement\Controller\UserManagement') + + 'MxcUserManagement' //--- applies to all controllers of module MxcUserManagement + + 'MxcUserManagement\MxcUserManagement\Controller\UserManagement' + //--- applies to controller registered with 'MxcUserManagement\Controller\UserManagement' + //--- *** In this rule the first occurance of'MxcUserManagement' identifies the module. + //--- *** The second occurance is part of the controller registration string. + + 'MxcUserManagement\MxcUserManagement\Controller\UserManagement\index' //--- index action + Action rules are evaluated before controller rules. Controller rules are evaluated before Module rules. So if you apply an action rule and a module rule for the same module, the module rule applies for all controllers and actions but the one action which has an own @@ -278,9 +301,9 @@ Accessing the route `home` causes a match of the according rule. Defaults get ap How MxcLayoutScheme works ------------------------- -1. On Bootstrap MxcLayoutScheme hooks into the dispatch event of the application's EventManager with low priority (-1000). +1. On Bootstrap MxcLayoutScheme hooks into the route event of the application's EventManager with low priority (-2000). 2. On Bootstrap MxcLayoutScheme instantiates the controller plugin `'layoutScheme'` to inject a reference to the application's ServiceManager instance. -3. On dispatch MxcLayoutScheme evaluates the current route matched, the module name, the controller name and the action name. +3. On route MxcLayoutScheme evaluates the current route matched, the module name, the controller name and the action name. 4. Then MxcLayoutScheme triggers an `MxcLayoutSchemeService::HOOK_PRE_SELECT_SCHEME` event. If you registered an event handler for that event in the bootstrap somewhere you can set the active scheme with `$e->getTarget()->setActiveScheme($schemeName)` with a `$schemeName`of your choice. Alternatively, you can set the active scheme within the controller action using the controller plugin: `$this->layoutScheme()->setActiveScheme($schemeName)`. 5. Then, MxcLayoutScheme loads the currently active scheme. 6. MxcLayoutScheme checks the `route_layouts` for a key matching the matched route name. If the key exists the layout template registered to that match gets applied. If the rule defines child view models they get merged with the (optionally) defined default child view models and get applied to the layout. If match continue at 11. @@ -296,8 +319,22 @@ from within the controller action. How MxcLayoutScheme handles dispatch errors ------------------------------------------- +On Bootstrap MxcLayoutScheme hooks into the dispatch.error event with priority -1000. + When a dispatch error occurs, MxcLayoutScheme first checks for a rule applying to the error code from the `$event->getError()`. If no rule applies MxcLayoutScheme then checks for a rule applying to the status code from $event->getResponse()->getStatusCode(). +How MxcLayoutScheme handles content templates +--------------------------------------------- + +Content templates may be specified via rules like any other template. ` =>