zenify/doctrine-methods-hydrator

Hydrates presenter methods from parameters to entities

Installs: 732

Dependents: 0

Stars: 12

Watchers: 5

Forks: 1

Language: PHP

v5.1.0 2015-06-11 09:45 UTC

README

Build Status Quality Score Code Coverage Downloads this Month Latest stable

Install

Via Composer

$ composer require zenify/doctrine-methods-hydrator

Register the extension in config.neon:

extensions:
    - Zenify\DoctrineMethodsHydrator\DI\MethodsHydratorExtension

The goal of this extension is to enhance native tryCall method of Control to hydrate parameters of called methods. All render*, action* and handle* methods are hydrated, if entity class typehint is present if args definition.

Usage

Use in presenter looks like this:

class Presenter extends Nette\Application\UI\Presenter
{

    /**
     * @inject
     * @var Zenify\DoctrineMethodsHydrator\Contract\MethodsHydratorInterface
     */
    public $methodsHydrator;


    /**
     * @param string $method
     * @param array $parameters
     * @return bool
     */
    protected function tryCall($method, array $parameters)
    {
        return $this->methodsHydrator->hydrate($method, $parameters, $this);
    }

}

For Control, you can use constructor or @inject with help of DecoratorExtension.

Use Case

In template

<a n:href="Product:detail, product => $product->getId()">Product detail</a>

In presenter

class SomePresenter extends Presenter
{

    public function actionDetail(App\Entities\Product $product)
    {
        dump($product); // entity object
    }

}