bangpound/legacy-php-http-kernel
Composer 安装命令:
composer require bangpound/legacy-php-http-kernel
包简介
Symfony HttpKernel for supporting controllers that exit or return null.
README 文档
README
Controllers in legacy PHP applications don't return Symfony Response objects, and they might return nothing or even exit. These low-level Symfony components provide a simple bridge to legacy PHP applications.
Usage
Use the HttpKernel class and add the ShutdownListener and OutputBufferListener
subscribers to the EventDispatcher.
Working Example #1
This component is used in Drufony to run Drupal 7 in the Symfony2 framework.
Working Example #2
- Download and expand a recent version of WordPress.
- In the WordPress directory, create
composer.json:
{
"require": {
"bangpound/legacy-php-http-kernel": "1.0.*"
}
}
- Run
composer install. - Replace WordPress's
index.phpfront controller:
<?php require "vendor/autoload.php"; use Bangpound\LegacyPhp\EventListener\OutputBufferListener; use Bangpound\LegacyPhp\EventListener\ShutdownListener; use Bangpound\LegacyPhp\HttpKernel; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestMatcher; use Symfony\Component\HttpKernel\Controller\ControllerResolver; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; // Use a request attribute to identify requests which are legacy. $matcher = new RequestMatcher(); $matcher->matchAttribute('_legacy', 'true'); $dispatcher = new EventDispatcher(); // Event listeners make Symfony reponses from output buffer and // register a shutdown handler. $dispatcher->addSubscriber(new OutputBufferListener($matcher)); $dispatcher->addSubscriber(new ShutdownListener($matcher)); // Add a listener that modifies every request to have a controller // that imitates Wordpress index.php. $dispatcher->addListener(KernelEvents::REQUEST, function (GetResponseEvent $event) { $request = $event->getRequest(); $request->attributes->add(array( '_legacy' => 'true', '_controller' => function () { define('WP_USE_THEMES', true); require( dirname( __FILE__ ) . '/wp-blog-header.php' ); }, )); } ); // This HttpKernel has a shutdown method which completes the kernel // response cyle when a controller exits or dies. $kernel = new HttpKernel($dispatcher, new ControllerResolver()); // Symfony front controller code call_user_func(function () use ($kernel) { $request = Request::createFromGlobals(); $response = $kernel->handle($request); $response->send(); $kernel->terminate($request, $response); });
- Run
php -S localhost:8000
bangpound/legacy-php-http-kernel 适用场景与选型建议
bangpound/legacy-php-http-kernel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 134 次下载、GitHub Stars 达 1, 最近一次更新时间为 2014 年 03 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 bangpound/legacy-php-http-kernel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bangpound/legacy-php-http-kernel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 134
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 3
- 推荐数: 2
其他信息
- 授权协议: MIT
- 更新时间: 2014-03-28