2017 © Pedro Peláez
 

symfony-bundle post-process-bundle

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

image

as3/post-process-bundle

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

  • Thursday, March 16, 2017
  • by zarathustra323
  • Repository
  • 3 Watchers
  • 1 Stars
  • 4,365 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 10 Versions
  • 11 % Grown

The README.md

PostProcessBundle

Scrutinizer Code Quality Build Status Packagist SensioLabsInsight, (*1)

Provides centralized support for executing callable code before Symfony framework termination, (*2)

Installation

Install packages with Composer

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

Register the Bundle

Once installed, register the bundle in your AppKernel.php:, (*4)

// 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.), (*5)

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., (*6)

Example:, (*7)

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):, (*8)

    $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., (*9)

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

# 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., (*11)

Example:, (*12)

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:, (*13)

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

The Versions

16/03 2017

dev-master

9999999-dev

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

  Sources   Download

MIT

The Requires

 

by Jacob Bare
by Josh Worden

16/03 2017

1.0.8

1.0.8.0

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

  Sources   Download

MIT

The Requires

 

by Jacob Bare
by Josh Worden

14/12 2016

1.0.7

1.0.7.0

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

  Sources   Download

MIT

The Requires

 

by Jacob Bare
by Josh Worden

12/12 2016

1.0.6

1.0.6.0

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

  Sources   Download

MIT

The Requires

 

by Jacob Bare
by Josh Worden

12/12 2016

1.0.5

1.0.5.0

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

  Sources   Download

MIT

The Requires

 

by Jacob Bare
by Josh Worden

02/11 2016

1.0.4

1.0.4.0

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

  Sources   Download

MIT

The Requires

 

by Jacob Bare
by Josh Worden

01/11 2016

1.0.3

1.0.3.0

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

  Sources   Download

MIT

The Requires

 

by Jacob Bare
by Josh Worden

01/11 2016

1.0.2

1.0.2.0

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

  Sources   Download

MIT

The Requires

 

by Jacob Bare
by Josh Worden

01/11 2016

1.0.1

1.0.1.0

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

  Sources   Download

MIT

The Requires

 

by Jacob Bare
by Josh Worden

01/11 2016

1.0

1.0.0.0

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

  Sources   Download

MIT

The Requires

 

by Jacob Bare
by Josh Worden