Skip to content

Commit 20fe2da

Browse files
committed
Initial commit
1 parent 204ba82 commit 20fe2da

File tree

12 files changed

+496
-0
lines changed

12 files changed

+496
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,4 @@
4646

4747
# Backup entities generated with doctrine:generate:entities command
4848
*/Entity/*~
49+
.DS_Store

As3PostProcessBundle.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
namespace As3\PostProcessBundle;
3+
4+
use Symfony\Component\HttpKernel\Bundle\Bundle;
5+
use Symfony\Component\DependencyInjection\ContainerBuilder;
6+
use As3\PostProcessBundle\DependencyInjection\Compiler;
7+
8+
class As3PostProcessBundle extends Bundle
9+
{
10+
public function build(ContainerBuilder $container)
11+
{
12+
$container->addCompilerPass(new Compiler\AddTasksCompilerPass());
13+
$container->addCompilerPass(new Compiler\AddPluginsCompilerPass());
14+
}
15+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
namespace As3\PostProcessBundle\DependencyInjection\Compiler;
3+
4+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
5+
use Symfony\Component\DependencyInjection\ContainerBuilder;
6+
use Symfony\Component\DependencyInjection\Reference;
7+
8+
class AddPluginsCompilerPass implements CompilerPassInterface
9+
{
10+
/**
11+
* Adds tagged autoloaders to the manager service
12+
*
13+
* @param ContainerBuilder $container
14+
*/
15+
public function process(ContainerBuilder $container)
16+
{
17+
$managerId = 'as3_post_process.task.manager';
18+
if (!$container->hasDefinition($managerId)) {
19+
return;
20+
}
21+
// Get the manager service definition
22+
$definition = $container->getDefinition($managerId);
23+
24+
// Get the tagged plugins
25+
$tag = 'as3_post_process.plugin';
26+
$plugins = $container->findTaggedServiceIds($tag);
27+
28+
foreach ($plugins as $id => $tagAttributes) {
29+
foreach ($tagAttributes as $attributes) {
30+
// Add the plugin to the manager service definition
31+
$definition->addMethodCall(
32+
'addPlugin',
33+
[new Reference($id)]
34+
);
35+
}
36+
}
37+
}
38+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
namespace As3\PostProcessBundle\DependencyInjection\Compiler;
3+
4+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
5+
use Symfony\Component\DependencyInjection\ContainerBuilder;
6+
use Symfony\Component\DependencyInjection\Reference;
7+
8+
class AddTasksCompilerPass implements CompilerPassInterface
9+
{
10+
/**
11+
* Adds tagged autoloaders to the manager service
12+
*
13+
* @param ContainerBuilder $container
14+
*/
15+
public function process(ContainerBuilder $container)
16+
{
17+
$managerId = 'as3_post_process.task.manager';
18+
if (!$container->hasDefinition($managerId)) {
19+
return;
20+
}
21+
// Get the manager service definition
22+
$definition = $container->getDefinition($managerId);
23+
24+
// Get the tagged tasks
25+
$tag = 'as3_post_process.task';
26+
$tasks = $container->findTaggedServiceIds($tag);
27+
28+
foreach ($tasks as $id => $tagAttributes) {
29+
foreach ($tagAttributes as $attributes) {
30+
// Add the task to the manager service definition
31+
$priority = isset($attributes['priority']) ? $attributes['priority'] : 0;
32+
$definition->addMethodCall(
33+
'addTask',
34+
[new Reference($id), $priority]
35+
);
36+
}
37+
}
38+
}
39+
}

DependencyInjection/Configuration.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace As3\PostProcessBundle\DependencyInjection;
4+
5+
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6+
use Symfony\Component\Config\Definition\ConfigurationInterface;
7+
8+
/**
9+
* This is the class that validates and merges configuration from your app/config files
10+
*
11+
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
12+
*/
13+
class Configuration implements ConfigurationInterface
14+
{
15+
/**
16+
* {@inheritDoc}
17+
*/
18+
public function getConfigTreeBuilder()
19+
{
20+
$treeBuilder = new TreeBuilder();
21+
$rootNode = $treeBuilder->root('as3_post_process');
22+
return $treeBuilder;
23+
}
24+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace As3\PostProcessBundle\DependencyInjection;
4+
5+
use Symfony\Component\DependencyInjection\ContainerBuilder;
6+
use Symfony\Component\Config\FileLocator;
7+
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
8+
use Symfony\Component\DependencyInjection\Loader;
9+
use Symfony\Component\DependencyInjection\Definition;
10+
use Symfony\Component\DependencyInjection\Reference;
11+
12+
/**
13+
* This is the class that loads and manages your bundle configuration
14+
*
15+
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
16+
*/
17+
class As3PostProcessExtension extends Extension
18+
{
19+
/**
20+
* {@inheritDoc}
21+
*/
22+
public function load(array $configs, ContainerBuilder $container)
23+
{
24+
$configuration = new Configuration();
25+
$config = $this->processConfiguration($configuration, $configs);
26+
27+
// Load bundle services
28+
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
29+
$loader->load('services.yml');
30+
}
31+
}

Plugins/PluginInterface.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace As3\PostProcessBundle\Plugins;
4+
5+
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
6+
use Symfony\Component\HttpFoundation\Response;
7+
8+
/**
9+
* Defines structure for PostProcess plugins
10+
*
11+
* @author Josh Worden <solocommand@gmail.com>
12+
*/
13+
interface PluginInterface
14+
{
15+
/**
16+
* Fires before TaskManager registers shutdown functions for loaded tasks.
17+
* Called by As3\PostProcessBundle\Task\TaskManager::execute()
18+
*
19+
* @param PostResponseEvent $event The Symfony post response event
20+
*/
21+
public function execute(PostResponseEvent $event);
22+
23+
/**
24+
* Handles modification (filtering) of the response as needed.
25+
* Called by As3\PostProcessBundle\Task\TaskManager::filterResponse() before returning the response.
26+
*
27+
* @param Response $event The Symfony Response
28+
*/
29+
public function filterResponse(Response $response);
30+
}

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,28 @@
11
# PostProcessBundle
2+
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/as3io/As3ModlrBundle/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/as3io/As3ModlrBundle/?branch=master) [![Build Status](https://travis-ci.org/as3io/As3ModlrBundle.svg?branch=master)](https://travis-ci.org/as3io/As3ModlrBundle) [![Packagist](https://img.shields.io/packagist/dt/as3/modlr-bundle.svg)](https://packagist.org/packages/as3/modlr-bundle) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/6d7d530c-f405-4815-847a-4f7ff82960c5/mini.png)](https://insight.sensiolabs.com/projects/6d7d530c-f405-4815-847a-4f7ff82960c5)
3+
24
Provides centralized support for executing callable code before Symfony framework termination
5+
6+
## Installation
7+
8+
### Install packages with Composer
9+
10+
To install this bundle via composer, perform the following command: `composer require as3/post-process-bundle ^1.0`.
11+
12+
### Register the Bundle
13+
14+
Once installed, register the bundle in your `AppKernel.php`:
15+
```
16+
// app/AppKernel.php
17+
public function registerBundles()
18+
{
19+
$bundles = array(
20+
// ...
21+
new As3\Bundle\PostProcessBundle\As3PostProcessBundle(),
22+
);
23+
24+
// ...
25+
}
26+
```
27+
28+
## Configuration

Resources/config/services.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
services:
2+
as3_post_process.task.manager:
3+
class: As3\PostProcessBundle\Task\TaskManager
4+
tags:
5+
- { name: kernel.event_listener, event: kernel.response, method: filterResponse, priority: -255 }
6+
- { name: kernel.event_listener, event: kernel.terminate, method: execute, priority: 1 }

Task/TaskInterface.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace As3\PostProcessBundle\Task;
4+
5+
/**
6+
* Interface for Tasks to be executed "post process" - after the response is sent
7+
*
8+
* @author Jacob Bare <jacob.bare@gmail.com>
9+
*/
10+
interface TaskInterface
11+
{
12+
/**
13+
* Runs the task/code
14+
*
15+
* @return self
16+
*/
17+
public function run();
18+
}

0 commit comments

Comments
 (0)