This bundle is no longer maintained. Feel free to fork it if needed.
This Bundles enables "multiplexing" multiple requests into a single Request/Response:
for example this request:
will internally call:
/session/new
and /notifications
and return one Response:
{
"/session/new" : {"request" : "/session/new", "status": 200, "response": "the Response Content of /session/new"},
"/notifications" : {"request" : "/notifications", "status": 403, "response": "Forbidden"}
}
Attention: Installing this Bundle basically lets anyone side step the security firewall. Therefore its important to either secure the multiplex route or to implement security checks inside all relevant controllers
- Add this bundle to your project with Composer:
```
$ php composer.phar require liip/multiplex-bundle
```
- Add this bundle to your application's kernel:
``` php
// app/AppKernel.php
public function registerBundles()
{
return array(
// ...
new Liip\MultiplexBundle\LiipMultiplexBundle(),
// ...
);
}
```
The following Configuration Options exists:
allow_externals
: if enabled also external urls can be multiplexed (default: true)display_errors
: if enabled and an error occured, the error message will be returned, otherwise (if available) the http status code message (default: true)route_option
: only used in combination withrestrict_routes
, defines the route option which should be looked up ifrestrict_routes
is on (default: multiplex_expose)restrict_routes
: if enabled only routes with theroute_option
are multiplexable (default: false)
here the default config
liip_multiplex:
allow_externals: true
display_errors: true
route_option: 'multiplex_expose'
restrict_routes: false
if you want to restrict multiplexing to specific routes, define the option in each route you want to expose
<route id="_my_route" pattern="/foo/bar">
<default key="_controller">MyBundle:Controller:index</default>
<option key="multiplex_expose">true</option>
</route>
and don't forget to set restrict_routes
to true
!
This Bundles provides a decent Javascript Library to use the Multiplexer Endpoint.
{% javascripts
"@LiipMultiplexBundle/Resources/public/js/ajax_multiplexer.js"
output='js/multiplexer.js'
%}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
//configuring the Multiplexer
Multiplexer.setEndpoint('/path/to/multiplexer/endpoint'); //as in your routing defaults to /multiplex.json
Multiplexer.setFormat('json'); //only useful exchange format
//adding Requests to the Multiplexer
Multiplexer.add(
{'uri' : '/foo/bar', 'method' : 'GET', 'parameters' : {'foo':'bar'}}, //the Request Object
function(content) { /* ... */}, // the Success Callback
function(content) { /* ... */} // the Error Callback
);
Multiplexer.add(
{'uri' : 'http://google.com', 'method' : 'GET', 'parameters' : {'q':'Symfony2'}},
function(content) { /* this callback is called on success for this request*/},
function(content) { /* this callback is called on error for this request*/}
);
//pushing all Requests to the Server
Multiplexer.call(
function(r){ /* ... */ }, //the global success callback (optional)
function(r){ /* ... */ } //the global error callback (optional)
);
//pushing only a set of Requests to the Server
Multiplexer.call(['/foo/bar']);
- To run the unit tests, require all dependencies
```
$ php composer.phar update --dev
```
- Run PHPUnit
```
$ phpunit
```
- See Travis for automated Tests
https://travis-ci.org/liip/LiipMultiplexBundle
- more output formats (usable html/xml formats)