Developed with love by KnpLabs Hire us for your project!
27

LiipMultiplexBundle

by liip

Symfony2 controller that allows calling multiple URL's in one request as well as JSON-ifying any controller

Overview Build Status

This Bundles enables "multiplexing" multiple requests into a single Request/Response:

for example this request:

http://foo.com/multiplex.json?requests[login][uri]=/session/new&requests[notification][uri]=/notifications&requests[notification][method]=get&requests[notification][parameters][]=broadcasts&requests[notification][parameters][]=personal

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

Installation

  1. Add this bundle to your project with Composer:

    $ php composer.phar require liip/multiplex-bundle
    
  2. Add this bundle to your application's kernel:

      // app/AppKernel.php
      public function registerBundles()
      {
          return array(
              // ...
              new Liip\MultiplexBundle\LiipMultiplexBundle(),
              // ...
          );
      }
    

Configuration

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 with restrict_routes, defines the route option which should be looked up if restrict_routes is on (default: multiplex_expose)
  • restrict_routes : if enabled only routes with the route_option are multiplexable (default: false)

Application Configuration

here the default config

liip_multiplex:
    allow_externals: true
    display_errors: true
    route_option: 'multiplex_expose'
    restrict_routes: false

Routing Configuration

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!

Usage

This Bundles provides a decent Javascript Library to use the Multiplexer Endpoint.

Integration of the Javascript

  {% javascripts
  "@LiipMultiplexBundle/Resources/public/js/ajax_multiplexer.js"
    output='js/multiplexer.js'
  %}
    <script src="{{ asset_url }}"></script>
  {% endjavascripts %}

Using the Javascript Multiplexer


//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']);

Tests

  1. To run the unit tests, require all dependencies

    $ php composer.phar update --dev
    
  2. Run PHPUnit

    $ phpunit
    
  3. See Travis for automated Tests

    https://travis-ci.org/liip/LiipMultiplexBundle

TODO

  • more output formats (usable html/xml formats)
Copyright (c) 2010-2011 Liip

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
liip_multiplex:
display_errors: true
restrict_routes: false
allow_externals: true
route_option: multiplex_expose
  • Merge pull request #6 from liip/js_callbacks
    By digitalkaoz, 4 years ago
  • tiny js callback refactorings
    By digitalkaoz, 4 years ago
  • Merge pull request #5 from liip/router_context
    By lsmith77, 4 years ago
  • fixed a symfony2.1>2.2 JsonResponse Issue
    By digitalkaoz, 4 years ago
  • fixed travis setup
    By lsmith77, 4 years ago
  • fixed symfony-2.3 requirement
    By digitalkaoz, 4 years ago
  • fixed the router context for matching routes with different http methods
    By digitalkaoz, 4 years ago
  • fixed added of tagged services
    By digitalkaoz, 4 years ago
  • Merge pull request #4 from liip/error_response_fix
    By digitalkaoz, 4 years ago
  • fixed a error response issue
    By digitalkaoz, 4 years ago
  • Merge pull request #3 from liip/dispatcher
    By lsmith77, 4 years ago
  • cs fixes
    By digitalkaoz, 4 years ago
  • using a dispatcher now, and registering the multiplexer with DIC tags
    By digitalkaoz, 4 years ago
  • Merge pull request #2 from liip/more_refactoring
    By lsmith77, 4 years ago
  • made buzz completly optional
    By digitalkaoz, 4 years ago
  • subclassing and renaming of the multiplexer
    By digitalkaoz, 4 years ago
  • [WIP] refactored MultiplexManager, currently broken
    By lsmith77, 4 years ago
  • ignore composer.lock and vendor dir
    By lsmith77, 4 years ago
  • added missing phpdoc line
    By lsmith77, 4 years ago
  • Update README.md
    By digitalkaoz, 4 years ago
  • Merge pull request #1 from digitalkaoz/refactorings
    By digitalkaoz, 4 years ago
  • tiny code cleanups
    By digitalkaoz, 4 years ago
  • some review refactorings
    By digitalkaoz, 4 years ago
  • moved request to the multiplex method, so the service must not be scoped
    By digitalkaoz, 4 years ago
  • latest symfony refactorings, fixed testsuite, added travis-ci
    By digitalkaoz, 4 years ago
  • added note that the bundle is currently not maintained
    By lsmith77, 5 years ago
  • updated repo url
    By lsmith77, 5 years ago
  • Symfony2 will not get subrequest security
    By lsmith77, 5 years ago
  • fixed relative path to symfony src
    By lsmith77, 5 years ago
  • s/src/vendor\\bundles/
    By lsmith77, 5 years ago