{"id":17087412,"url":"https://github.com/dakujem/nette-wires","last_synced_at":"2026-05-02T23:43:45.400Z","repository":{"id":56961436,"uuid":"263078529","full_name":"dakujem/nette-wires","owner":"dakujem","description":"Metapackage for Nette framework.","archived":false,"fork":false,"pushed_at":"2020-11-22T10:48:04.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-14T03:05:29.240Z","etag":null,"topics":["nette","nette-di"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dakujem.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-11T15:14:05.000Z","updated_at":"2020-11-22T10:42:44.000Z","dependencies_parsed_at":"2022-08-21T09:20:49.176Z","dependency_job_id":null,"html_url":"https://github.com/dakujem/nette-wires","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/dakujem/nette-wires","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dakujem%2Fnette-wires","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dakujem%2Fnette-wires/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dakujem%2Fnette-wires/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dakujem%2Fnette-wires/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dakujem","download_url":"https://codeload.github.com/dakujem/nette-wires/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dakujem%2Fnette-wires/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274101209,"owners_count":25222444,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-07T02:00:09.463Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nette","nette-di"],"created_at":"2024-10-14T13:33:08.438Z","updated_at":"2026-05-02T23:43:45.350Z","avatar_url":"https://github.com/dakujem.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nette Wires\n\n\u003e 💿 `composer require dakujem/nette-wires`\n\n- [EN version](#en-)\n\n## SK ![sk_SK](https://www.countryflags.io/sk/flat/32.png) / CS ![cs_CZ](https://www.countryflags.io/cz/flat/24.png)\n\nWire Genie umoznuje redukovat \"boilerplate\" kod suvisiaci s drotovanim sluzieb\ncez prezentery (napriklad vytvaranie komponent\na niektorych jednorazovych sluzieb typu _builder_ alebo _factory_).\n\n\n\u003e Ale bacha! 🤚\n\u003e\n\u003e V zavislosti od konkretneho pouzitia moze dojst k poruseniu _IoC_ principov\n\u003e a degradacii _dependency injection_ principov na _service locator_.\n\u003e Pouzivajte na vlastnu zdpovednost, ak viete, co robite.\n\u003e\n\u003e Na druhej strane, ak vytiahujete sluzby z kontajneru,\n\u003e mozete uz radsej pouzit Wire Genie.\n\n\n#### Instalacia\n\n\u003e 💿 `composer require dakujem/nette-wires`\n\nTento metapackage instaluje [Wire Genie](https://github.com/dakujem/wire-genie)\na navod nizsie odporuca instalaciu\n[Contributte/PSR-11-kontajner](https://github.com/contributte/psr11-container-interface),\nale mozete pouzit lubovolny iny PSR-11 wrapper Nette DI kontajneru.\n\n\nPokial si nainstalujete `contributte/psr11-container-interface`,\nmozete vo svojom bazovom prezenteri pouzit\n[`WireGenieTrait`](src/WireGenieTrait.php),\nktory prida do prezenteru metodu `wire`.\n\u003e `composer require contributte/psr11-container-interface`\n\n```php\nnamespace App\\Presenters;\n\nuse Dakujem\\WireGenieTrait;\nuse Nette;\n\nabstract class BasePresenter extends Nette\\Application\\UI\\Presenter\n{\n    use WireGenieTrait;\n}\n```\n\u003e 💡 Nepouzivajte _traity_, pokial nerozumiete, co s nimi nie je v poriadku.\n\nImplementacia `wire` metody je inak vo vasich rukach.\\\nNamiesto nej mozete tiez priamo volat `$wireGenie-\u003eprovide( ... )-\u003einvoke( ... )`.\n\n\n#### Pouzitie\n\nMetodu `wire` je mozne pouzit napriklad v `createComponent*` metodach:\n```php\n    protected function createComponentFoobarForm()\n    {\n        $factory = function (InputFactory $inputs, TextRepository $textRepo) {\n            $form = new Form();\n            $form-\u003eaddComponent(\n                $inputs-\u003ecreate('stuff', $textRepo-\u003egetAllUnread()),\n                'unread_stuff'\n            );\n            // ...\n            return $form;\n        };\n\n        // explicitne vyziadanie zavislosti\n        return $this-\u003ewire(InputFactory::class, 'model.repository.text')-\u003einvoke($factory);\n        \n        // alebo automaticke nadrotovanie zavislosti (autowiring)\n        return $this-\u003ewire()-\u003einvoke($factory);\n    }\n```\n\nLepsie je zabalit kod do tovarne alebo populatoru (moznost testovat):\n```php\n    protected function createComponentFoobarForm()\n    {\n        return $this-\u003ewire(InputFactory::class, 'model.repository.text')\n            -\u003einvoke([new FoobarFormFactory, 'create']);\n    }\n```\n\nLokalne zavislosti z prezenteru je mozne pribalit cez anonymne funkcie:\n```php\n    protected function createComponentFoobarForm()\n    {\n        return $this-\u003ewire(InputFactory::class, 'model.repository.text')\n            -\u003einvoke(function (...$deps) {\n                return (new FoobarFormFactory)-\u003ecreate(\n                    $this-\u003elocalDependency,\n                    $this-\u003egetParameter('id'),\n                    ...$deps\n                );\n            });\n    }\n```\n\nTento postup umoznuje vyhnut sa injektovaniu mnozstva zavislosti do prezenterov,\npokial nie su vzdy pouzivane\n(prezetner moze mat viacero akcii, pouzije sa len jedna; komponenty detto).\n\nTaketo pouzitie Wire Genie riesi okrajovy pripad, kedy vznika boilerplate.\\\nPred pouzitim skuste pouvazovat, ci sa vas pripad neda vyriesit cistejsie.\\\nNette 3 podporuje injektovanie skupin sluzieb, `SearchExtension` umoznuje hromadne registrovat sluzby do kontajneru, atd.\n\nPorovnajte vyhody a nevyhody:\n- ❔ zachovanie IoC je otazne (zalezi na uhle pohladu)\n- ➕ vyhodou je mala pracnost riesenia\n- ➕ prehladne prepojenie zavislosti, jednoduche na pochopenie\n- ➕ autowiring, vid detaily [v balicku Wire Genie](https://github.com/dakujem/wire-genie#automatic-dependency-resolution)\n- ➕ moznost konfiguracie drotovania zavislosti existuje\n- ➕ testovatelnost je jednoduchsia ako v priapde tovarni vygenerovanych DI\n- ➕ prezenter neriesi, odkial zavislosti tecu, ale _deklaruje_, ake sluzby sa maju nadrotovat\n- ➕ lazy loading v momente realneho pouzitia\n- ➖ „maskovany“ service lokator (❔)\n- ➖ kontajner pri kompilacii nezisti problemy s chybajucimi alebo konfliktnymi sluzbami\n\n\n\u003e Alternativne mozete skusit iny kompromis, napr. [Kdyby/Autowired](https://github.com/Kdyby/Autowired).\n\nOsobne odporucam tieto techniky pouzivat len vo faze prototypovania.\n\n\n## EN ![en_GB](https://www.countryflags.io/gb/flat/32.png)\n\nAllows to fetch multiple dependencies from a DI container\nand provide them as arguments to a callable.\\\nMetapackage.\n\n\u003e Disclaimer 🤚\n\u003e\n\u003e Depending on actual use, this might be breaking _IoC_\n\u003e and degrade your _dependency injection_ container to a _service locator_,\n\u003e so use it with caution.\n\u003e\n\u003e But then again, if you can `get` a service from your container, you can use wire genie.\n\n\n#### Installation\n\n\u003e 💿 `composer require dakujem/nette-wires`\n\nThen either install [Contributte/PSR-11-kontajner](https://github.com/contributte/psr11-container-interface)\nor any other PSR-11 wrapper for Nette DI container.\n\nIf you install `contributte/psr11-container-interface`,\nyou can use\n[`WireGenieTrait`](src/WireGenieTrait.php),\nin your presenter(s), that will add `wire` method.\n\u003e `composer require contributte/psr11-container-interface`\n\n```php\nnamespace App\\Presenters;\n\nuse Dakujem\\WireGenieTrait;\nuse Nette;\n\nabstract class BasePresenter extends Nette\\Application\\UI\\Presenter\n{\n    use WireGenieTrait;\n}\n```\n\u003e 💡 Do not use _traits_ unless you understand what's wrong with them.\n\nOtherwise, implementation of `wire` method is in your hands.\\\nYou can of course call `$wireGenie-\u003eprovide( ... )-\u003einvoke( ... )` directly as well.\n\nThen you can wire dependencies without first labourously injecting them to your presenters,\ncreating factories and accessors in the meantime.\n\n```php\n    protected function createComponentFoobarForm()\n    {\n        $factory = function (InputFactory $inputs, TextRepository $textRepo) {\n            $form = new Form();\n            $form-\u003eaddComponent(\n                $inputs-\u003ecreate('stuff', $textRepo-\u003egetAllUnread()),\n                'unread_stuff'\n            );\n            // ...\n            return $form;\n        };\n\n        // with explicit dependencies\n        return $this-\u003ewire(InputFactory::class, 'model.repository.text')-\u003einvoke($factory);\n        \n        // with automatic dependency resolution (autowiring)\n        return $this-\u003ewire()-\u003einvoke($factory);\n    }\n```\n\nLocal dependencies can naturally be passed to the closures:\n```php\n    protected function createComponentFoobarForm()\n    {\n        return $this-\u003ewire(InputFactory::class, 'model.repository.text')\n            -\u003einvoke(function (...$deps) {\n                return (new FoobarFormFactory)-\u003ecreate(\n                    $this-\u003elocalDependency,\n                    $this-\u003egetParameter('id'),\n                    ...$deps\n                );\n            });\n    }\n```\n\nPlease understand that this approach has its advantages and disadvantages.\nIt might actually degrade your aplication if misused.\\\nFirst try to think if your case can not be solved in a cleaner way.\\\n\nI would recommend only using this and similar approaches during prototyping phase.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdakujem%2Fnette-wires","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdakujem%2Fnette-wires","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdakujem%2Fnette-wires/lists"}