定制 php-di/kernel 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

php-di/kernel

Composer 安装命令:

composer require php-di/kernel

包简介

Kernel for PHP-DI applications

README 文档

README

Kernel for building modules with PHP-DI.

Build Status Coverage Status

Introduction

The Kernel let's you build an application based on PHP-DI modules.

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:

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

$container = $kernel->createContainer();

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:

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

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:

    $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:

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

When the module is registered in the kernel like this:

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

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:

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

That way you can let the kernel load your application as a module:

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

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:

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

You can then instruct the environment to load:

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

Note that environments are optional.

统计信息

  • 总下载量: 731
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 10
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 10
  • Watchers: 3
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-01-03

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固