dkplus/action-arguments

Provides the ability to use variable action arguments.

Installs: 33

Dependents: 0

Stars: 3

Watchers: 1

Language: PHP


README

Build Status Scrutinizer Quality Score Coverage Status Total Downloads Latest Stable Version Latest Unstable Version Dependency Status

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.