liip/multiplex-bundle

该软件包已被废弃且不再维护。未建议替代软件包。

此软件包允许将多个请求合并为单个请求/响应。

安装: 45

依赖: 0

建议者: 0

安全: 0

星标: 12

关注者: 49

分支: 2

开放问题: 0

类型:symfony-bundle

1.1.2 2013-02-11 14:19 UTC

This package is not auto-updated.

Last update: 2020-01-18 20:57:40 UTC


README

此软件包已不再维护。如有需要,请随意进行分支。

概述 Build Status

此软件包允许将多个请求合并为单个请求/响应。

例如此请求

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

将内部调用

/session/new/notifications

并返回 一个 响应

{
    "/session/new"   : {"request" : "/session/new", "status": 200, "response": "the Response Content of /session/new"},
    "/notifications" : {"request" : "/notifications", "status": 403, "response": "Forbidden"}
}

注意:安装此软件包基本上让任何人都可以绕过安全防火墙。因此,重要的是要保护合并路由的安全,或者在每个相关控制器中实施安全检查。

安装

  1. 使用 Composer 将此软件包添加到您的项目中
```
$ php composer.phar require liip/multiplex-bundle
```
  1. 将此软件包添加到您的应用程序内核中
``` php
  // app/AppKernel.php
  public function registerBundles()
  {
      return array(
          // ...
          new Liip\MultiplexBundle\LiipMultiplexBundle(),
          // ...
      );
  }
```

配置

以下配置选项存在

  • allow_externals:如果启用,还可以合并外部 URL(默认:true
  • display_errors:如果启用且发生错误,将返回错误消息,否则(如果可用)返回 HTTP 状态码消息(默认:true
  • route_option:仅与 restrict_routes 结合使用,定义在 restrict_routes 启用时应查找的路线选项(默认:multiplex_expose
  • restrict_routes:如果启用,只有具有 route_option 的路由可合并(默认:false

应用程序配置

以下是默认配置

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

路由配置

如果您想将合并限制为特定路由,请在要公开的每个路由中定义选项

<route id="_my_route" pattern="/foo/bar">
    <default key="_controller">MyBundle:Controller:index</default>
    <option key="multiplex_expose">true</option>
</route>

并不要忘记将 restrict_routes 设置为 true

用法

此软件包提供了一款不错的 JavaScript 库,用于使用合并端点。

JavaScript 集成

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

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

测试

  1. 要运行单元测试,需要所有依赖项
```
$ php composer.phar update --dev
```
  1. 运行 PHPUnit
```
$ phpunit
```
  1. 查看 Travis 以获取自动测试
https://travis-ci.org/liip/LiipMultiplexBundle

待办事项

  • 更多输出格式(可用的 HTML/XML 格式)