Download the PHP package php-di/kernel without Composer
On this page you can find all versions of the php package php-di/kernel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download php-di/kernel
More information about php-di/kernel
Files in php-di/kernel
Package kernel
Short Description Kernel for PHP-DI applications
License MIT
Homepage http://php-di.org
Informations about the package kernel
PHP-DI application kernel
Kernel for building modules with PHP-DI.
Introduction
The Kernel let's you build an application based on PHP-DI modules.
Installation
Usage
The kernel's role is to create the container. It does so by registering all the configuration files of the modules we ask it to load:
If you want to register configuration on the container, you can:
- create a module - this is the recommended solution, read the next sections to learn more
- or set the configuration directly - this is useful in micro-frameworks or micro-applications:
Installing a module
To install a 3rd party module:
- install the package using Composer
- add it to the list of modules your kernel will load, for example:
Creating a module
- the Composer package name is the module name
- create a resource directory in your package, usually
res/
- create as many PHP-DI configuration files as needed in
res/config/
That's it. Here is what your package should look like:
When the module is registered in the kernel like this:
all the files in vendor/foo/bar/res/config/*.php
will be loaded.
Your main application will probably contain configuration files too: it is also a module. Since it may not have a package name in composer.json
you will need to set one. You can name it app
, for example:
That way you can let the kernel load your application as a module:
Environments
Applications often need to behave differently according to the environment: dev
, prod
, etc.
PHP-DI's Kernel let you write config for specific environments through a simple convention:
You can then instruct the environment to load:
Note that environments are optional.