You are viewing documentation for an outdated version. It is no longer supported!

Laravel Aware Of Helpers

Getters and Settersopen in new window helpers for some of Laravel'sopen in new window core packages.

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.

Usage

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.

use Aedart\Support\Helpers\Config\ConfigTrait;

class Box
{
    use ConfigTrait;
    
    // ... 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 = new Box();

$config = $box->getConfig();

You can also specify a custom Repository, should you wish it.

$box->setConfig($myCustomRepository);

Enforce Via Interface

For each available aware-of helper, there is a complementary interface, so that you can enforce your dependencies.

use Aedart\Support\Helpers\Config\ConfigTrait;
use Aedart\Contracts\Support\Helpers\Config\ConfigAware;

class Box implements ConfigAware 
{
    use ConfigTrait;
    
    // ... remaining not shown ... //
}

Custom Default

You can also easily overwrite the default instance provided, by overwriting the getDefault[Dependency] method, which exists inside each aware-of trait.

<?php
use Aedart\Support\Helpers\Config\ConfigTrait;
use Illuminate\Contracts\Config\Repository;
use Illuminate\Config\Repository as Config;

class Box
{
    use ConfigTrait;
    
    public function getDefaultConfig(): ?Repository
    {
        return new Config([
            'width'     => 25,
            'height'    => 25
        ]);
    }
    
    // ... remaining not shown ... //
}

Outside Laravel Usage

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.

Pros and Cons

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.

Available Aware Of Helpers

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.

Auth

TraitDefaults to binding
Aedart\Support\Helpers\Auth\Access\GateTraitIlluminate\Contracts\Auth\Access\Gate
Aedart\Support\Helpers\Auth\AuthFactoryTraitIlluminate\Contracts\Auth\Factory
Aedart\Support\Helpers\Auth\AuthTraitIlluminate\Contracts\Auth\Guard
Aedart\Support\Helpers\Auth\PasswordBrokerFactoryTraitIlluminate\Contracts\Auth\PasswordBrokerFactory
Aedart\Support\Helpers\Auth\PasswordTraitIlluminate\Contracts\Auth\PasswordBroker

Broadcasting

TraitDefaults to binding
Aedart\Support\Helpers\Broadcasting\BroadcastFactoryTraitIlluminate\Contracts\Broadcasting\Factory
Aedart\Support\Helpers\Broadcasting\BroadcastTraitIlluminate\Contracts\Broadcasting\Broadcaster

Bus

TraitDefaults to binding
Aedart\Support\Helpers\Bus\BusTraitIlluminate\Contracts\Bus\Dispatcher
Aedart\Support\Helpers\Bus\QueueingBusTraitIlluminate\Contracts\Bus\QueueingDispatcher

Cache

TraitDefaults to binding
Aedart\Support\Helpers\Cache\CacheFactoryTraitIlluminate\Contracts\Cache\Factory
Aedart\Support\Helpers\Cache\CacheStoreTraitIlluminate\Contracts\Cache\Store
Aedart\Support\Helpers\Cache\CacheTraitIlluminate\Contracts\Cache\Repository

Config

TraitDefaults to binding
Aedart\Support\Helpers\Config\ConfigTraitIlluminate\Contracts\Config\Repository

Console

TraitDefaults to binding
Aedart\Support\Helpers\Console\ArtisanTraitIlluminate\Contracts\Console\Kernel

Container

TraitDefaults to binding
Aedart\Support\Helpers\Container\ContainerTraitIlluminate\Contracts\Container\Container
TraitDefaults to binding
Aedart\Support\Helpers\Cookie\CookieTraitIlluminate\Contracts\Cookie\Factory
Aedart\Support\Helpers\Cookie\QueueingCookieTraitIlluminate\Contracts\Cookie\QueueingFactory

Database

TraitDefaults to binding
Aedart\Support\Helpers\Database\ConnectionResolverTraitIlluminate\Database\ConnectionResolverInterface
Aedart\Support\Helpers\Database\DbTraitIlluminate\Database\ConnectionInterface
Aedart\Support\Helpers\Database\SchemaTraitIlluminate\Database\Schema\Builder

Encryption

TraitDefaults to binding
Aedart\Support\Helpers\Encryption\CryptTraitIlluminate\Contracts\Encryption\Encrypter

Events

TraitDefaults to binding
Aedart\Support\Helpers\Events\EventTraitIlluminate\Contracts\Events\Dispatcher
Aedart\Support\Helpers\Events\DispatcherTraitIlluminate\Contracts\Events\Dispatcher

Filesystem

TraitDefaults to binding
Aedart\Support\Helpers\Filesystem\CloudStorageTraitIlluminate\Contracts\Filesystem\Cloud
Aedart\Support\Helpers\Filesystem\FileTraitIlluminate\Filesystem\Filesystem
Aedart\Support\Helpers\Filesystem\StorageFactoryTraitIlluminate\Contracts\Filesystem\Factory
Aedart\Support\Helpers\Filesystem\StorageTraitIlluminate\Contracts\Filesystem\Filesystem

Foundation

TraitDefaults to binding
Aedart\Support\Helpers\Foundation\AppTraitIlluminate\Contracts\Foundation\Application

Hashing

TraitDefaults to binding
Aedart\Support\Helpers\Hashing\HashTraitIlluminate\Contracts\Hashing\Hasher

Http

TraitDefaults to binding
Aedart\Support\Helpers\Http\RequestTraitIlluminate\Http\Request

Logging

TraitDefaults to binding
Aedart\Support\Helpers\Logging\LogManagerTraitIlluminate\Log\LogManager
Aedart\Support\Helpers\Logging\LogTrait\Psr\Log\LoggerInterface

Mail

TraitDefaults to binding
Aedart\Support\Helpers\Mail\MailerTraitIlluminate\Contracts\Mail\Mailer
Aedart\Support\Helpers\Mail\MailQueueTraitIlluminate\Contracts\Mail\MailQueue

Notifications

TraitDefaults to binding
Aedart\Support\Helpers\Notifications\NotificationDispatcherTraitIlluminate\Contracts\Notifications\Dispatcher
Aedart\Support\Helpers\Notifications\NotificationFactoryTraitIlluminate\Contracts\Notifications\Factory

Queue

TraitDefaults to binding
Aedart\Support\Helpers\Queue\QueueFactoryTraitIlluminate\Contracts\Queue\Factory
Aedart\Support\Helpers\Queue\QueueMonitorTraitIlluminate\Contracts\Queue\Monitor
Aedart\Support\Helpers\Queue\QueueTraitIlluminate\Contracts\Queue\Queue

Redis

TraitDefaults to binding
Aedart\Support\Helpers\Redis\RedisFactoryTraitIlluminate\Contracts\Redis\Factory
Aedart\Support\Helpers\Redis\RedisTraitIlluminate\Contracts\Redis\Connection

Routing

TraitDefaults to binding
Aedart\Support\Helpers\Routing\RedirectTraitIlluminate\Routing\Redirector
Aedart\Support\Helpers\Routing\ResponseFactoryTraitIlluminate\Contracts\Routing\ResponseFactory
Aedart\Support\Helpers\Routing\RouteRegistrarTraitIlluminate\Contracts\Routing\Registrar
Aedart\Support\Helpers\Routing\UrlGeneratorTraitIlluminate\Contracts\Routing\UrlGenerator

Session

TraitDefaults to binding
Aedart\Support\Helpers\Session\SessionManagerTraitIlluminate\Session\SessionManager
Aedart\Support\Helpers\Session\SessionTraitIlluminate\Contracts\Session\Session

Translation

TraitDefaults to binding
Aedart\Support\Helpers\Translation\TranslatorTraitIlluminate\Contracts\Translation\Translator

Validation

TraitDefaults to binding
Aedart\Support\Helpers\Validation\ValidatorFactoryTraitIlluminate\Contracts\Validation\Factory

View

TraitDefaults to binding
Aedart\Support\Helpers\View\BladeTraitIlluminate\View\Compilers\BladeCompiler
Aedart\Support\Helpers\View\ViewFactoryTraitIlluminate\Contracts\View\Factory