These components allow you to manually set and retrieve a Laravel component, e.g. a configuration Repository. Additionally, when no component instance has been specified, it will automatically default to whatever Laravel has bound in the IoCopen in new window.
You can think of these helpers as alternatives, or supplements to Laravel's native Facadesopen in new window.
Imagine that you have a component that depends on Laravel's configuration Repository. To ensure that your component is able to gain access to it, use the ConfigTrait.
useAedart\Support\Helpers\Config\ConfigTrait;classBox{useConfigTrait;// ... remaining not shown ... //}
When you use your component, you will automatically have the configuration Repository available, when your are working inside a typical Laravel Application.
$box=newBox();$config=$box->getConfig();
You can also specify a custom Repository, should you wish it.
You can also easily overwrite the default instance provided, by overwriting the getDefault[Dependency] method, which exists inside each aware-of trait.
<?phpuseAedart\Support\Helpers\Config\ConfigTrait;useIlluminate\Contracts\Config\Repository;useIlluminate\Config\Repositoryas Config;classBox{useConfigTrait;publicfunctiongetDefaultConfig():?Repository{returnnewConfig(['width'=>25,'height'=>25]);}// ... remaining not shown ... //}
If you wish to use these helpers outside a typical Laravel Application, then you must ensure that the required services have been registered in the IoCopen in new window.
If you are a regular Laravel user, then you most likely have your own desired way to obtain dependencies. Most likely, you either resolve these via the Service Container or rely on Facadesopen in new window. There is absolutely nothing wrong with that and you should continue to do so, if it feels right.
As previously mentioned, these components are alternatives or supplementary - either they make sense for you to use or they do not. In other words, you have to decide for yourself when and how to use these, if at all. Should you do, then remember that they do add a bit of additional complexity to your components.
These are the available aware-of helpers for Laravel components. The Defaults to binding column illustrates what Service Container binding a given trait defaults to, if no custom has been set or overwritten. See Facade Class Referenceopen in new window for additional information.
Note
Corresponding aware-of interfaces can be found inside the Aedart\Contracts\Support\Helpers\* namespace.