Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

Latest commit

 

History

History
26 lines (19 loc) · 1.15 KB

application.md

File metadata and controls

26 lines (19 loc) · 1.15 KB

Application

The *Application* functions as Pagekit's dependency container. The application makes Pagekit's functionality and services configurable, extendable, interchangeable and accessible throughout the [modules](modules.md).

All services you have available in Pagekit are set as dependency-injected properties on the Application instance. $app['db'] for example will give you access to the database service.

Accessing a Service

To access the Application instance, there are mainly two ways. Depending on the context you are in at the moment, you have either access to a $app variable or through a static call to the Pagekit\Application class.

// Getter
$app['cache']

use Pagekit\Application as App;
App::cache();

As you can see, the container implements \ArrayAccess as well as a magic __call method to access the container's services.

Defining a Service

Adding a service to the application can easily be achieved by setting an array key on the container to be a closure. This will not be evaluated until accessed for the first time.

$app['cache'] = function () {
    return new Cache();
};