dkplus / action-arguments
Provides the ability to use variable action arguments.
1.0
2014-01-28 20:04 UTC
Requires
Requires (Dev)
- bjyoungblood/bjy-authorize: 1.4.*
- phpunit/phpunit: ~3.7
- satooshi/php-coveralls: ~0.6
- spiffy/spiffy-authorize: dev-master
- squizlabs/php_codesniffer: 1.5.*
- zendframework/zend-config: 2.2.*
- zendframework/zend-console: 2.2.*
- zendframework/zend-serializer: 2.2.*
- zendframework/zend-test: 2.2.*
- zf-commons/zfc-rbac: 2.0.*
- zf-commons/zfc-user: 0.*
This package is auto-updated.
Last update: 2024-12-08 22:40:57 UTC
README
Features
- Provides named arguments from route match. (Example 1)
- Can convert scalar arguments into classes.
- Has built in support for Doctrine ORM (Example 2, Example 3), but also usable with every other mapping solution by using callbacks (Example 4, Example 5).
- Supports optional arguments.
- When one argument could not be mapped into an entity, a 404 error page could be shown.
- If your assertions can be retrieved from the service locator, the arguments could be injected into your assertions; that way you could improve your controller-/route-guards with better assertions.
Examples
Named scalar arguments
use DkplusActionArguments\Controller\AbstractActionController; class IndexController extends AbstractActionController { /** * Route looks like /user/:id */ public function viewAction($id) { return array('user' => $this->mapper->find($id)); } }
Simplest converting by using Doctrine ObjectRepository::find
use DkplusActionArguments\Controller\AbstractActionController; class IndexController extends AbstractActionController { /** * Route looks like /user/:user */ public function viewAction(User $user) { return array('user' => $user); } }
Converting by using a custom Doctrine ObjectRepository method
use DkplusActionArguments\Annotation\MapParam; use DkplusActionArguments\Controller\AbstractActionController; class IndexController extends AbstractActionController { /** * Route looks like /user/:name * @MapParam(from="name", to="user", using="findOneByName") */ public function viewAction(User $user) { return array('user' => $user); } }
Converting by using a callback
use DkplusActionArguments\Annotation\MapParam; use DkplusActionArguments\Controller\AbstractActionController; class IndexController extends AbstractActionController { /** * Route looks like /user/:user * @MapParam(to="user", using={"sm_key", "method"}) */ public function viewAction(User $user) { return array('user' => $user); } }
Converting by using a custom converter
use DkplusActionArguments\Annotation\MapParam; use DkplusActionArguments\Controller\AbstractActionController; class IndexController extends AbstractActionController { /** * Route looks like /user/:user * @MapParam(to="user", using="my_converter_sm_key") */ public function viewAction(User $user) { return array('user' => $user); } }
Installation
Installation of this module uses composer. For composer documentation, please refer to getcomposer.org.
php composer.phar require dkplus/action-arguments
When asked for a version to install, type dev-master
. You can then enable it in your config/application.config.php
by adding DkplusActionArguments
to your modules.
After installing copy config/dkplus-action-arguments.global.php.dist
to
application/autoload/dkplus-action-arguments.global.php
.
ToDo
- Init named arguments
- Add Argument converter
- Support for BjyAuthorize, SpiffyAuthorize, ZfcRbac
- Better documentation
- Add tests for BjyAuthorize-, SpiffyAuthorize and ZfcRbac-Support
- Find proper class names
- Reduce code complexity
- Clear cache via console.