zenify / doctrine-methods-hydrator
Hydrates presenter methods from parameters to entities
Installs: 3 006
Dependents: 0
Suggesters: 0
Security: 0
Stars: 16
Watchers: 7
Forks: 1
Open Issues: 0
Requires
- php: >=5.6
- doctrine/orm: ~2.4
- nette/application: ~2.3
- nette/di: ~2.3
Requires (Dev)
- kdyby/doctrine: ~3.0
- latte/latte: ~2.3
- nette/bootstrap: ~2.3
- tracy/tracy: ~2.3
README
Install
$ composer require zenify/doctrine-methods-hydrator
Register the extension in config.neon
:
extensions: - Zenify\DoctrineMethodsHydrator\DI\MethodsHydratorExtension # Kdyby\Doctrine or another Doctrine to Nette implementation
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); // "App\Entities\Product" object } }