geniv/nette-autowired

Autowired trait for Nette Framework

v1.6.3 2019-02-10 12:18 UTC

This package is auto-updated.

Last update: 2020-09-10 16:20:22 UTC


README

This trait allows self class use in parameters for createComponent*

inspired by: https://github.com/Kdyby/Autowired

Installation

$ composer require geniv/nette-autowired

or

"geniv/nette-autowired": "^1.6"

require:

"php": ">=7.0",
"nette/component-model": ">=2.3",
"nette/di": ">=2.4",
"nette/reflection": ">=2.4"

Include in application

base presenters:

class BasePresenter extends Presenter
{
    use AutowiredComponent;

usage:

protected function createComponentDatagrid(string $name, IDatagridFactory $factory): DatagridFactory
{
    return $factory->create();
}

or

protected function createComponentSomeone(Someone $someone): Someone
{
    return $someone;
}