as3/post-process-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

as3/post-process-bundle

Composer 安装命令:

composer require as3/post-process-bundle

包简介

Provides centralized support for executing callable code before Symfony framework termination.

README 文档

README

Scrutinizer Code Quality Build Status Packagist SensioLabsInsight

Provides centralized support for executing callable code before Symfony framework termination

Installation

Install packages with Composer

To install this bundle via composer, perform the following command: composer require as3/post-process-bundle ^1.0.

Register the Bundle

Once installed, register the bundle in your AppKernel.php:

// app/AppKernel.php
public function registerBundles()
{
    $bundles = array(
        // ...
        new As3\Bundle\PostProcessBundle\As3PostProcessBundle(),
    );

    // ...
}

Usage

To use the PostProcessBundle, you must first create a class adhering to the Task\TaskInterface or Plugins\PluginInterface. A task is a process that will be executed on the Symfony terminate event (after the response is sent,) whereas a Plugin is a process that is run before the response is sent (allowing you to modify it.)

Tasks

A task can be used to execute logic after the response has been sent to the user, allowing you to trigger long-running processes that need to complete, but the user does not need to wait for them.

Example:

use As3\Bundle\PostProcessBundle\TaskInterface;

class SleepTestTask implements TaskInterface
{
    /**
     * {@inhericDoc}
     */
    public function run()
    {
        // Some process that takes 5 minutes
        sleep(300);
    }
}

To register your task, call the addTask method against the task manager's service (as3_post_process.task.manager):

    $manager = $this->get('as3_post_process.task.manager');
    $manager->addTask(new SleepTestTask(), 5);

Tasks can have a priority set when they are added to the manager -- by default new tasks are added with a priority of 0. Tasks are executed in ascending order by their priority.

You can also register a service by using the tag as3_post_process.task if your task should be run on every request.

# src\MyBundle\Resources\services.yml
services:
my_app.my_cool_task:
    class: MyCoolTask
    tags:
        - { name: as3_post_process.task, priority: 5 }

Plugins

A plugin can be used to modify the response before it is returned to the user.

Example:

use Symfony\Component\HttpFoundation\Response;

/**
 * Integration with New Relic End User Monitoring services
 */
class NewRelicInjector extends PluginInterface
{
    /**
     * Handles injection of NREUM Javascript
     */
    public function filterResponse(Response $response)
    {
        if (extension_loaded('newrelic')) {
            newrelic_disable_autorum();

            $content = $response->getContent();

            if (false != strpos($content, '</head>')) {
                $content = str_replace('</head>', sprintf("\n%s\n</head>", newrelic_get_browser_timing_header()), $content);
            }

            if (false != strpos($content, '</body>')) {
                $content = str_replace('</body>', sprintf("\n%s\n</body>", newrelic_get_browser_timing_footer()), $content);
            }

            $response->headers->set('X-NREUM', 'Enabled');

            // If we modified the content, set it on the response.
            if ($content !== $response->getContent()) {
                $response->setContent($content);
            }

            return $response;
        }
    }
}

This plugin will disable automatic injection of NewRelic end user monitoring javascript. To enable this for all requests, add the following service definition:

    my_app.my_bundle.new_relic_injector:
        class: MyApp\MyBundle\NewRelicPlugin
        tags:
            - { name: as3_post_process.plugin }

as3/post-process-bundle 适用场景与选型建议

as3/post-process-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12.99k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2016 年 11 月 01 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 as3/post-process-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 as3/post-process-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 as3/post-process-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 12.99k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 23
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

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