2017 © Pedro Peláez
 

library kernel

Kernel for PHP-DI applications

image

php-di/kernel

Kernel for PHP-DI applications

  • Sunday, July 16, 2017
  • by mnapoli
  • Repository
  • 3 Watchers
  • 10 Stars
  • 347 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 9 Versions
  • 3 % Grown

The README.md

PHP-DI application kernel

Kernel for building modules with PHP-DI., (*1)

Build Status Coverage Status, (*2)

Introduction

The Kernel let's you build an application based on PHP-DI modules., (*3)

Installation

composer require php-di/kernel

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:, (*4)

$kernel = new Kernel([
    'twig/twig',
    'doctrine/dbal',
    'vendor/app',
]);

$container = $kernel->createContainer();

If you want to register configuration on the container, you can:, (*5)

  • 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:, (*6)

    $kernel = new Kernel();
    $kernel->addConfig([
        'db.host' => 'localhost',
    ]);
    

Installing a module

To install a 3rd party module:, (*7)

  • install the package using Composer
  • add it to the list of modules your kernel will load, for example:, (*8)

    $kernel = new Kernel([
        'twig/twig',
    ]);
    

Creating a module

  1. the Composer package name is the module name
  2. create a resource directory in your package, usually res/
  3. create as many PHP-DI configuration files as needed in res/config/

That's it. Here is what your package should look like:, (*9)

res/
    config/
        config.php
    ...
src/
    ...
composer.json

When the module is registered in the kernel like this:, (*10)

$kernel = new Kernel([
    'foo/bar',
]);

all the files in vendor/foo/bar/res/config/*.php will be loaded., (*11)

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:, (*12)

{
    "name": "app",
    "require": {
        // ...
    }
}

That way you can let the kernel load your application as a module:, (*13)

$kernel = new Kernel([
    'app',
]);

Environments

Applications often need to behave differently according to the environment: dev, prod, etc., (*14)

PHP-DI's Kernel let you write config for specific environments through a simple convention:, (*15)

res/
    config/
        config.php
        env/
            dev.php
            prod.php
    ...

You can then instruct the environment to load:, (*16)

$kernel = new Kernel($modules, 'dev'); // dev environment
$kernel = new Kernel($modules, 'prod'); // prod environment

Note that environments are optional., (*17)

The Versions

16/07 2017

dev-master

9999999-dev http://php-di.org

Kernel for PHP-DI applications

  Sources   Download

MIT

The Requires

 

The Development Requires

application kernel php-di

16/07 2017

0.4.1

0.4.1.0 http://php-di.org

Kernel for PHP-DI applications

  Sources   Download

MIT

The Requires

 

The Development Requires

application kernel php-di

16/07 2017

0.4.0

0.4.0.0 http://php-di.org

Kernel for PHP-DI applications

  Sources   Download

MIT

The Requires

 

The Development Requires

application kernel php-di

09/04 2017

0.3.0

0.3.0.0 http://php-di.org

Kernel for PHP-DI applications

  Sources   Download

MIT

The Requires

 

The Development Requires

application kernel php-di

19/06 2016
18/06 2016

0.2.1

0.2.1.0 http://php-di.org

Kernel for PHP-DI applications

  Sources   Download

MIT

The Requires

 

The Development Requires

application kernel php-di

10/01 2016

0.2.0

0.2.0.0 http://php-di.org

Kernel for PHP-DI applications

  Sources   Download

MIT

The Requires

 

The Development Requires

application kernel php-di

03/01 2016

0.1.1

0.1.1.0 http://php-di.org

Kernel for PHP-DI applications

  Sources   Download

MIT

The Requires

 

The Development Requires

application kernel php-di

03/01 2016

0.1.0

0.1.0.0 http://php-di.org

Kernel for PHP-DI applications

  Sources   Download

MIT

The Requires

 

The Development Requires

application kernel php-di