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.

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.

  1. // Getter
  2. $app['cache']
  3.  
  4. use Pagekit\Application as App;
  5. 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.

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