symlex/di-microkernel
Composer 安装命令:
composer require symlex/di-microkernel
包简介
Micro-Kernel for PHP Applications
关键字:
README 文档
README
This library contains a micro-kernel for bootstrapping almost any PHP application, including Silex, Symlex (a framework stack for agile Web development based on Symfony) and Symfony Console. The kernel itself is just a few lines to set a bunch of environment parameters and create a service container instance with that.
Run an App
Creating a kernel instance and calling run() is enough to start an application:
#!/usr/bin/env php <?php // Composer require_once 'vendor/autoload.php'; $app = new \DIMicroKernel\Kernel('console'); // Run the 'app' service defined in config/console.yml $app->run();
Configuration
YAML files located in config/ configure the application and all of it's dependencies as a service. The filename matches
the application's environment name (e.g. config/console.yml). The configuration can additionally be modified
for sub environments such as local or production by providing a matching config file like config/console.local.yml
(see app.sub_environment parameter). These files are in the same well documented format you might know from Symfony:
parameters: app.name: 'My App' app.version: '1.0' services: doctrine.migrations.migrate: class: Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand app: class: Symfony\Component\Console\Application public: true arguments: [%app.name%, %app.version%] calls: - [ add, [ "@doctrine.migrations.migrate" ] ]
This provides a uniform approach for bootstrapping Web applications like Silex\Application,
Symlex\Application\Web or command-line applications like Symfony\Component\Console\Application using the same kernel.
The result is much cleaner and leaner than the usual bootstrap and configuration madness you know from many frameworks.
Parameters
The kernel sets a number of default parameters that can be used for configuring services. The default values can be
changed via setter methods of the kernel or overwritten/extended by container config files
and environment variables (e.g. url: '%env(DATABASE_URL)%').
| Parameter | Getter method | Setter method | Default value |
|---|---|---|---|
| app.name | getName() | setName() | 'Kernel' |
| app.version | getVersion() | setVersion() | '1.0' |
| app.environment | getEnvironment() | setEnvironment() | 'app' |
| app.sub_environment | getSubEnvironment() | setSubEnvironment() | 'local' |
| app.debug | isDebug() | setDebug() | false |
| app.charset | getCharset() | setCharset() | 'UTF-8' |
| app.path | getAppPath() | setAppPath() | './' |
| app.config_path | getConfigPath() | setConfigPath() | './config' |
| app.base_path | getBasePath() | setBasePath() | '../' |
| app.storage_path | getStoragePath() | setStoragePath() | '../storage' |
| app.log_path | getLogPath() | setLogPath() | '../storage/log' |
| app.cache_path | getCachePath() | setCachePath() | '../storage/cache' |
| app.src_path | getSrcPath() | setSrcPath() | '../src' |
Customization
The kernel base class can be extended to customize it for a specific purpose such as long running console applications:
<?php use DIMicroKernel\Kernel; class ConsoleApp extends Kernel { public function __construct($appPath, $debug = false) { parent::__construct('console', $appPath, $debug); } public function setUp() { set_time_limit(0); ini_set('memory_limit', '-1'); } }
Caching
If debug mode is turned off, the service container configuration is cached by the kernel in the directory set as cache path. You have to delete all cache files after updating the configuration. To disable caching completely, add container.cache: false to your configuration parameters:
parameters: container.cache: false
Composer
To use this library in your project, simply run composer require symlex/di-microkernel or
add "symlex/di-microkernel" to your composer.json file and run composer update:
{
"require": {
"php": ">=7.1",
"symlex/di-microkernel": "^2.0"
}
}
About
DIMicroKernel is maintained by Michael Mayer. Feel free to send an e-mail to hello@symlex.org if you have any questions, need commercial support or just want to say hello. We welcome contributions of any kind. If you have a bug or an idea, read our guide before opening an issue.
symlex/di-microkernel 适用场景与选型建议
symlex/di-microkernel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.37k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2017 年 04 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「dependency injection」 「symfony」 「performance」 「micro-framework」 「kernel」 「bootstrapping」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 symlex/di-microkernel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 symlex/di-microkernel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 symlex/di-microkernel 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The bundle for easy using json-rpc api on your project
A fast and intuitive dependency injection container.
Bundle Symfony DaplosBundle
Dependency injection container for the Monolith framework.
Http Microframework for Hack
统计信息
- 总下载量: 6.37k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 16
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-04-05