Syntax sugar for working with services in Nette Framework


Keywords
di, nette, kdyby, autowire
Licenses
BSD-3-Clause/GPL-2.0/GPL-3.0

Documentation

Autowired for component

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;
}