PHPackages                             dakujem/nette-wires - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. dakujem/nette-wires

ActiveLibrary

dakujem/nette-wires
===================

Wire in Nette with genie powers.

1.1(5y ago)02UnlicensePHPPHP &gt;=7.2

Since May 19Pushed 5y ago1 watchersCompare

[ Source](https://github.com/dakujem/nette-wires)[ Packagist](https://packagist.org/packages/dakujem/nette-wires)[ RSS](/packages/dakujem-nette-wires/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (2)Versions (4)Used By (0)

Nette Wires
===========

[](#nette-wires)

> 💿 `composer require dakujem/nette-wires`

- [EN version](#en-)

SK [![sk_SK](https://camo.githubusercontent.com/cc65269d919a06698e354cff2c03f57c8fd4ba4c6bdfc1ee23f5b3849a65b543/68747470733a2f2f7777772e636f756e747279666c6167732e696f2f736b2f666c61742f33322e706e67)](https://camo.githubusercontent.com/cc65269d919a06698e354cff2c03f57c8fd4ba4c6bdfc1ee23f5b3849a65b543/68747470733a2f2f7777772e636f756e747279666c6167732e696f2f736b2f666c61742f33322e706e67) / CS [![cs_CZ](https://camo.githubusercontent.com/77e95bcb2be35a2f810f6cd852fdbb5ee508fa16022f9c518c9361c658d81b69/68747470733a2f2f7777772e636f756e747279666c6167732e696f2f637a2f666c61742f32342e706e67)](https://camo.githubusercontent.com/77e95bcb2be35a2f810f6cd852fdbb5ee508fa16022f9c518c9361c658d81b69/68747470733a2f2f7777772e636f756e747279666c6167732e696f2f637a2f666c61742f32342e706e67)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#sk---cs-)

Wire Genie umoznuje redukovat "boilerplate" kod suvisiaci s drotovanim sluzieb cez prezentery (napriklad vytvaranie komponent a niektorych jednorazovych sluzieb typu *builder* alebo *factory*).

> Ale bacha! 🤚
>
> V zavislosti od konkretneho pouzitia moze dojst k poruseniu *IoC* principov a degradacii *dependency injection* principov na *service locator*. Pouzivajte na vlastnu zdpovednost, ak viete, co robite.
>
> Na druhej strane, ak vytiahujete sluzby z kontajneru, mozete uz radsej pouzit Wire Genie.

#### Instalacia

[](#instalacia)

> 💿 `composer require dakujem/nette-wires`

Tento metapackage instaluje [Wire Genie](https://github.com/dakujem/wire-genie)a navod nizsie odporuca instalaciu [Contributte/PSR-11-kontajner](https://github.com/contributte/psr11-container-interface), ale mozete pouzit lubovolny iny PSR-11 wrapper Nette DI kontajneru.

Pokial si nainstalujete `contributte/psr11-container-interface`, mozete vo svojom bazovom prezenteri pouzit [`WireGenieTrait`](src/WireGenieTrait.php), ktory prida do prezenteru metodu `wire`.

> `composer require contributte/psr11-container-interface`

```
namespace App\Presenters;

use Dakujem\WireGenieTrait;
use Nette;

abstract class BasePresenter extends Nette\Application\UI\Presenter
{
    use WireGenieTrait;
}
```

> 💡 Nepouzivajte *traity*, pokial nerozumiete, co s nimi nie je v poriadku.

Implementacia `wire` metody je inak vo vasich rukach.
Namiesto nej mozete tiez priamo volat `$wireGenie->provide( ... )->invoke( ... )`.

#### Pouzitie

[](#pouzitie)

Metodu `wire` je mozne pouzit napriklad v `createComponent*` metodach:

```
    protected function createComponentFoobarForm()
    {
        $factory = function (InputFactory $inputs, TextRepository $textRepo) {
            $form = new Form();
            $form->addComponent(
                $inputs->create('stuff', $textRepo->getAllUnread()),
                'unread_stuff'
            );
            // ...
            return $form;
        };

        // explicitne vyziadanie zavislosti
        return $this->wire(InputFactory::class, 'model.repository.text')->invoke($factory);

        // alebo automaticke nadrotovanie zavislosti (autowiring)
        return $this->wire()->invoke($factory);
    }
```

Lepsie je zabalit kod do tovarne alebo populatoru (moznost testovat):

```
    protected function createComponentFoobarForm()
    {
        return $this->wire(InputFactory::class, 'model.repository.text')
            ->invoke([new FoobarFormFactory, 'create']);
    }
```

Lokalne zavislosti z prezenteru je mozne pribalit cez anonymne funkcie:

```
    protected function createComponentFoobarForm()
    {
        return $this->wire(InputFactory::class, 'model.repository.text')
            ->invoke(function (...$deps) {
                return (new FoobarFormFactory)->create(
                    $this->localDependency,
                    $this->getParameter('id'),
                    ...$deps
                );
            });
    }
```

Tento postup umoznuje vyhnut sa injektovaniu mnozstva zavislosti do prezenterov, pokial nie su vzdy pouzivane (prezetner moze mat viacero akcii, pouzije sa len jedna; komponenty detto).

Taketo pouzitie Wire Genie riesi okrajovy pripad, kedy vznika boilerplate.
Pred pouzitim skuste pouvazovat, ci sa vas pripad neda vyriesit cistejsie.
Nette 3 podporuje injektovanie skupin sluzieb, `SearchExtension` umoznuje hromadne registrovat sluzby do kontajneru, atd.

Porovnajte vyhody a nevyhody:

- ❔ zachovanie IoC je otazne (zalezi na uhle pohladu)
- ➕ vyhodou je mala pracnost riesenia
- ➕ prehladne prepojenie zavislosti, jednoduche na pochopenie
- ➕ autowiring, vid detaily [v balicku Wire Genie](https://github.com/dakujem/wire-genie#automatic-dependency-resolution)
- ➕ moznost konfiguracie drotovania zavislosti existuje
- ➕ testovatelnost je jednoduchsia ako v priapde tovarni vygenerovanych DI
- ➕ prezenter neriesi, odkial zavislosti tecu, ale *deklaruje*, ake sluzby sa maju nadrotovat
- ➕ lazy loading v momente realneho pouzitia
- ➖ „maskovany“ service lokator (❔)
- ➖ kontajner pri kompilacii nezisti problemy s chybajucimi alebo konfliktnymi sluzbami

> Alternativne mozete skusit iny kompromis, napr. [Kdyby/Autowired](https://github.com/Kdyby/Autowired).

Osobne odporucam tieto techniky pouzivat len vo faze prototypovania.

EN [![en_GB](https://camo.githubusercontent.com/ed0abf759c536f445634adf8253677697cca5ffa593f2667e9c1a0016b15e28b/68747470733a2f2f7777772e636f756e747279666c6167732e696f2f67622f666c61742f33322e706e67)](https://camo.githubusercontent.com/ed0abf759c536f445634adf8253677697cca5ffa593f2667e9c1a0016b15e28b/68747470733a2f2f7777772e636f756e747279666c6167732e696f2f67622f666c61742f33322e706e67)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#en-)

Allows to fetch multiple dependencies from a DI container and provide them as arguments to a callable.
Metapackage.

> Disclaimer 🤚
>
> Depending on actual use, this might be breaking *IoC*and degrade your *dependency injection* container to a *service locator*, so use it with caution.
>
> But then again, if you can `get` a service from your container, you can use wire genie.

#### Installation

[](#installation)

> 💿 `composer require dakujem/nette-wires`

Then either install [Contributte/PSR-11-kontajner](https://github.com/contributte/psr11-container-interface)or any other PSR-11 wrapper for Nette DI container.

If you install `contributte/psr11-container-interface`, you can use [`WireGenieTrait`](src/WireGenieTrait.php), in your presenter(s), that will add `wire` method.

> `composer require contributte/psr11-container-interface`

```
namespace App\Presenters;

use Dakujem\WireGenieTrait;
use Nette;

abstract class BasePresenter extends Nette\Application\UI\Presenter
{
    use WireGenieTrait;
}
```

> 💡 Do not use *traits* unless you understand what's wrong with them.

Otherwise, implementation of `wire` method is in your hands.
You can of course call `$wireGenie->provide( ... )->invoke( ... )` directly as well.

Then you can wire dependencies without first labourously injecting them to your presenters, creating factories and accessors in the meantime.

```
    protected function createComponentFoobarForm()
    {
        $factory = function (InputFactory $inputs, TextRepository $textRepo) {
            $form = new Form();
            $form->addComponent(
                $inputs->create('stuff', $textRepo->getAllUnread()),
                'unread_stuff'
            );
            // ...
            return $form;
        };

        // with explicit dependencies
        return $this->wire(InputFactory::class, 'model.repository.text')->invoke($factory);

        // with automatic dependency resolution (autowiring)
        return $this->wire()->invoke($factory);
    }
```

Local dependencies can naturally be passed to the closures:

```
    protected function createComponentFoobarForm()
    {
        return $this->wire(InputFactory::class, 'model.repository.text')
            ->invoke(function (...$deps) {
                return (new FoobarFormFactory)->create(
                    $this->localDependency,
                    $this->getParameter('id'),
                    ...$deps
                );
            });
    }
```

Please understand that this approach has its advantages and disadvantages. It might actually degrade your aplication if misused.
First try to think if your case can not be solved in a cleaner way.\\

I would recommend only using this and similar approaches during prototyping phase.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~186 days

Total

2

Last Release

1994d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0bd7fa945013e9c0dcd65693575276bf5fcb9b9de13e1123e9f2c4a0a4c0fb6b?d=identicon)[dakujem](/maintainers/dakujem)

---

Top Contributors

[![dakujem](https://avatars.githubusercontent.com/u/443067?v=4)](https://github.com/dakujem "dakujem (5 commits)")

---

Tags

nettenette-di

### Embed Badge

![Health badge](/badges/dakujem-nette-wires/health.svg)

```
[![Health](https://phpackages.com/badges/dakujem-nette-wires/health.svg)](https://phpackages.com/packages/dakujem-nette-wires)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
