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

registerAsApplication()

Sometimes, when testing your custom Laravel components and services, it can be useful to "trick" them in believing that the Container is the Application. This can be achieved via the registerAsApplication().

use \Aedart\Container\IoC;

$ioc = IoC::getInstance();
$ioc->registerAsApplication();

When invoked, the method will bind the IoC as the app (Laravel Application). It will also set the Facadeopen in new window's application instance to be the IoC. This will allow you to use other facades and ensure that they are able to resolve their bindings, provided your have bound them inside the service container.

Warning

DO NOT USE THIS METHOD inside your normal Laravel Application. It will highjack the app binding, causing all kinds of unexpected and undesirable behaviour. The intended purposes of this method is for testing only!

Why is this available?

Sometimes it's a bit faster to test certain components, without having a full Laravel Application up and running. This can for instance be Facadesopen in new window or a custom Service Provider's boot methodopen in new window. However, using this method when the IoC is not a superclass to a Laravel Applicationopen in new window, is considered to be hack!

Be careful how you choose to make use of this, if at all!