liip / multiplex-bundle
该软件包已被废弃且不再维护。未建议替代软件包。
此软件包允许将多个请求合并为单个请求/响应。
1.1.2
2013-02-11 14:19 UTC
Requires
- php: >=5.3.2
- symfony/framework-bundle: >=2.1,<2.3-dev
Requires (Dev)
- kriswallsmith/buzz: >=0.7
Suggests
- kriswallsmith/buzz: allows multiplexing of external requests
This package is not auto-updated.
Last update: 2020-01-18 20:57:40 UTC
README
此软件包已不再维护。如有需要,请随意进行分支。
概述 
此软件包允许将多个请求合并为单个请求/响应。
例如此请求
将内部调用
/session/new
和 /notifications
并返回 一个 响应
{ "/session/new" : {"request" : "/session/new", "status": 200, "response": "the Response Content of /session/new"}, "/notifications" : {"request" : "/notifications", "status": 403, "response": "Forbidden"} }
注意:安装此软件包基本上让任何人都可以绕过安全防火墙。因此,重要的是要保护合并路由的安全,或者在每个相关控制器中实施安全检查。
安装
- 使用 Composer 将此软件包添加到您的项目中
```
$ php composer.phar require liip/multiplex-bundle
```
- 将此软件包添加到您的应用程序内核中
``` 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']);
测试
- 要运行单元测试,需要所有依赖项
```
$ php composer.phar update --dev
```
- 运行 PHPUnit
```
$ phpunit
```
- 查看 Travis 以获取自动测试
https://travis-ci.org/liip/LiipMultiplexBundle
待办事项
- 更多输出格式(可用的 HTML/XML 格式)