Download the PHP package jeroen-g/autowire without Composer
On this page you can find all versions of the php package jeroen-g/autowire. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jeroen-g/autowire
More information about jeroen-g/autowire
Files in jeroen-g/autowire
Package autowire
Short Description Autowire and configure using PHP 8 Attributes in Laravel.
License MIT
Homepage https://github.com/jeroen-g/autowire
Informations about the package autowire
🔌 Autowire for Laravel
Autowire and configure using PHP 8 Attributes in Laravel.
Installation
Via Composer
You will need the configuration file to change where it should look:
Usage
Autowiring
Are you tired of binding abstract interfaces to concrete classes all the time?
Use the PHP 8 attribute of this package to autowire any of your interfaces:
The class that implements that interface does not need any changes:
The Autowire package will crawl through the classes and bind the abstract interface to the concrete class. If there already is a binding in the container it will skip the autowiring.
Tagging
If you quickly want to tag all implementations of an interface, simply add the Tag
attribute to the interface:
All implementations will now be available under the 'myTag' tag:
If no tag value is specified in the attribute, the fully-namespaced name of the class will be used as the tag:
Configure
Personally I like injection of dependencies over resolving them using make()
helpers.
However, that means writing binding definitions such as:
Not anymore with the Configure attribute! Here is the WorldClass example again:
In this example message is a simple string. However, it can be a reference to a configuration value or other class too! The notations of config and service definitions is the same as used in Symfony.
Listen to events
If you use a lot of events, the EventServiceProvider
will very likely become long and messy:
With the PHP 8 attribute of this package you can define the events for a listener alongside each other:
The package will crawl through the classes and bind the listeners to the event classes.
Caching
The autowiring, configuration and listeners can be cached with the command php artisan autowire:cache
.
In a similar fashion it can be cleared with php artisan autowire:clear
.
Keep in mind that caching means that it won't crawl all the classes and changes to the annotations will not be loaded.
Configuration
The package's configuration can be found in config/autowire.php
.
It should contain the list of directories where Autowire should look for both interfaces and implementations.
Custom attributes
It is possible to use custom Attribute classes for either or both the autowiring or configuration functionality:
- Create a custom attribute class, making sure to implement either
JeroenG\Autowire\Attribute\AutowireInterface
orJeroenG\Autowire\Attribute\ConfigureInterface
, depending on the attribute you want to replace. - Add a
autowire_attribute
,configure_attribute
,tag_attribute
orlisten_attribute
setting to theconfig/autowire.php
file, containing the fully-namespaced name of your custom attribute class. - Use your custom attribute to mark the interface or class you want to autowire or configure.
Changelog
Please see the changelog for more information on what has changed recently.
Credits
- Jeroen
- All Contributors
License
MIT. Please see the license file for more information.
All versions of autowire with dependencies
ergebnis/classy Version ^1.3
illuminate/support Version ~8.0||~9.0||~10.0||~11.0||~12.0
illuminate/console Version ~8.0||~9.0||~10.0||~11.0||~12.0
webmozart/assert Version ^1.10