chippyash/slim-symfony-dic
Composer 安装命令:
composer require chippyash/slim-symfony-dic
包简介
Symfony 2 DIC integration for the Slim Framework 3
README 文档
README
Quality Assurance
The above badges represent the current development branch. As a rule, I don't push to GitHub unless tests, coverage and usability are acceptable. This may not be true for short periods of time; on holiday, need code for some other downstream project etc. If you need stable code, use a tagged version. Read 'Installation'.
See the tests and the Test Contract for additional information.
Please note that developer support for PHP5.5 was withdrawn at version 3.0.0 of this library.
If you need support for PHP 5.5, please use a version >=2,<3
What?
Provides a Symfony Dependency Injection Container V2 or Symfony Dependency Injection Container V4 for a Slim Application V3. The DI container depends on the version of PHP you are using. < 7, then V2, >=7.1 then V4
Why?
The Slim framework is great for lightweight sites and in version V3 adopts the interop interfaces for dependency injection containers. Slim V3 uses the Pimple DI by default. Symfony DI does not yet support the interop interface definition.
This small library supports the integration of the easy to use, yet powerful Symfony version of a DI container with the lightweight Slim Framework, giving you the ability to create great, maintainable and configurable web sites quickly.
The Builder supports XML DI definition. XML is the most powerful and complete form of Symfony DI configuration. The Builder also supports Yaml DI definition. Many developers prefer to put the parameters into a Yaml file and service definitions into an XML file. The supplied minimal example files demonstrate this usage.
How?
To create and return a Slim\App object with a Symfony DIC:
use Chippyash\Type\String\StringType; use Slimdic\Dic\Builder; use Slim\App; $xmlDiFileLocation = '/mysite/cfg/dic.production.xml'; /** * @var Slim\App */ $app = new App(Builder::buildDic(new StringType($xmlDiFileLocation)));
Please see the examples/dic.slim.v2.xml, examples/dic.slim.v3.xml and examples/dic.slim.yml
files for the minimum that you need to build the DIC with to support Slim. You are
recommended to put the files in with the rest of your DI configs and use the <imports>
directive in your main config to pull it in.
You can add to the compilation process by utilising the pre and post compile functions. This is often useful for setting up synthetic services or initialising parameters in the DI container.
Register a PreCompile function
The PreCompile function is called just before the container is compiled.
use Slimdic\Dic\ServiceContainer;
use Symfony\Component\DependencyInjection\Definition;
Builder::registerPreCompileFunction(function($dic) {
//set a parameter
$dic->setParameter('foo', 'bar');
//set up a synthetic
$dic->setDefinition('bar', (new Definition())->setSynthetic(true));
});
$app = new App(Builder::buildDic(new StringType($xmlDiFileLocation)));
Register a PostCompile function
The PostCompile function is called just after compiling the container.
The post compile function only really makes sense to set a synthetic definition as after compilation the rest of the DI Container is frozen and cannot be changed.
use Slimdic\Dic\ServiceContainer;
Builder::registerPreCompileFunction(function($dic) {
$dic->setDefinition('foo', (new Definition())->setSynthetic(true));
});
Builder::registerPostCompileFunction(function($dic, $stage) {
$dic->set('foo', $myFooService);
});
Changing the library
- fork it
- write the test
- amend it
- do a pull request
Found a bug you can't figure out?
- fork it
- write the test
- do a pull request
or raise an issue ticket
NB. Make sure you rebase to HEAD before your pull request
Where?
The library is hosted at Github. It is available at Packagist.org
Check out ZF4 Packages for more packages
See My blog for ramblings on coding and curries
Installation
Install Composer
For production
"chippyash/slim-symfony-dic": ">=3,<4"
to your composer.json "requires" section
For development
Clone this repo, and then run Composer in local repo root to pull in dependencies
git clone git@github.com:chippyash/Slim-Symfony-Dic.git Slimdic
cd Slimdic
composer install --dev
To run the tests:
cd Slimdic
vendor/bin/phpunit -c test/phpunit.xml test/
License
This software library is released under the BSD 3 Clause license
This software library is Copyright (c) 2016-2018, Ashley Kitson, UK
History
V1.0.0 Initial Release
V1.1.0 Update dependencies
V1.1.1 Add link to packages
V1.1.2 Verify PHP 7 compatibilty
V1.1.3 Update Slim dependency to 3.*
V1.1.4 Update dependencies
V1.1.5 Update build script
V2.0.0 PHP 7.0 support withdrawn, updated to use 7.1, primarily because of underlaying libraries that don't support 7.0
V2.0.2 Fix unit tests to run under PHP 7.1
V3.0.0 BC Break. Withdraw support for PHP <5.6
V3.1.0 Change of license from GPL V3 to BSD 3 Clause
V3.1.1 dependency update
chippyash/slim-symfony-dic 适用场景与选型建议
chippyash/slim-symfony-dic 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.31k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2016 年 01 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「dependency」 「web」 「injection」 「slim」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 chippyash/slim-symfony-dic 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 chippyash/slim-symfony-dic 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 chippyash/slim-symfony-dic 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Model of a web-based resource
The bundle for easy using json-rpc api on your project
A fast and intuitive dependency injection container.
Retrieve a WebResourceInterface instance over HTTP
Bundle Symfony DaplosBundle
Dependency injection container for the Monolith framework.
统计信息
- 总下载量: 4.31k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 4
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2016-01-23