ublaboo / directory-register
Extension for Nette Framework: register all classes within configured directory (blacklist avalible)
Installs: 6 030
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 3
Forks: 2
Open Issues: 0
Requires
- nette/di: ^2.3
- nette/robot-loader: ^v2.3
This package is auto-updated.
Last update: 2024-11-21 00:31:24 UTC
README
DirectoryRegister
Register extension in config.neon:
extensions: autoRegister: Ublaboo\DirectoryRegister\DI\AutoRegisterExtension
With this extension, all classes within specified directories will be automatically registered in DIC. E.g.:
autoRegister: dirs: [ App\Forms: %appDir%/Forms, App\ORM\Repository: %appDir%/ORM/Repository ] interfaces: [ IFormFactory: %appDir%/Forms, ] skip: [App\Forms\ContactFormFactory]
Always you have to specify namespace for classes in partucular directory. Let's take following directorystructure as an example:
app/
Forms/
ContactFormFactory.php
ProductFormFactory.php
SignInFormFactory.php
FooFormFactory.php
BarFormFactory.php
BazFormFactory.php
See, now above configuration will be the same as writing all these lines in config.neon
:
services: - App\Forms\ProductFormFactory - App\Forms\SignInFormFactory - App\Forms\FooFormFactory - App\Forms\BarFormFactory - App\Forms\BazFormFactory
PSR
This extension is simple and fast, but only works with projects that stick to PSR-0 or PSR-4. So you have to have all automatically registered classes named same as the file is and neither of your files can contain other classes.