Download the PHP package weew/kernel without Composer
On this page you can find all versions of the php package weew/kernel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package kernel
Short Description Simple kernel for registration and invocation of service providers.
License MIT
Informations about the package kernel
PHP Kernel
Table of contents
- Installation
- Introduction
- Usage
- Creating a provider
- Registering providers
- Initialization
- Booting
- Extension
- Sharing data between providers
- Custom container support
- Existing container integrations
- Related projects
Installation
composer require weew/kernel
Introduction
Kernel is responsible for the bootstrap process of service providers. It offers you a easy and intuitive way to register your own providers. The boot process consists of three steps - instantiation
, initialization
and booting
. There is also an additional step - shutdown
. This gives your providers a lot of flexibility on when to do what.
Usage
Creating a provider
Any class can be used as a provider. If the provider has any of these methods configure
, initialize
, boot
, shutdown
, the container will invoke them accordingly. It does not require a specific interface. This is by choice, I'll explain why I chose this solution in one of the future readme updates.
Registering providers
It is fairly easy to create a kernel and register your own providers.
Configuration
When you configure the kernel, all of its service providers get instantiated and configured.
Initialization
When you initialize the kernel, all of its service providers get initialized.
Booting
On boot, all service providers will be booted. This is a good place to setup your provider and do some work.
Shutdown
This will shutdown the kernel and all of its providers.
Extension
The kernel comes without a container. Out of the box the service providers will be very limited since they have no way to share anything. There are several workarounds for this.
Sharing data between providers
The easiest way to share data between providers is to use kernel's shared arguments.
Custom container support
A better way to enable container access for your providers is to replace the default implementation of the IProviderInvoker
with your own. In this example I'll be using this powerful container.
From now on all providers will benefit from constructor and method injection and will be able to share anything in the container. Depending on which container package you use the IProviderInvoker
implementation may vary, but the idea stays the same.
Existing container integrations
There is an integration available for the weew/container container. See weew/kernel-container-aware.
Related projects
- PHP Container works very well together with this package.