leaseweb / api-caller-bundle-ivisedo
具有完整Web调试工具栏集成的cURL API调用功能
Requires
- php: >=5.3.2
- ext-curl: *
- symfony/framework-bundle: >=2.1
- symfony/security-bundle: >=2.1
Requires (Dev)
- doctrine/doctrine-bundle: *
- swiftmailer/swiftmailer: *
- symfony/validator: 2.1.*
- symfony/yaml: 2.1.*
- twig/twig: *
- willdurand/propel-typehintable-behavior: dev-master
README
LswApiCallerBundle向您的Symfony2应用程序添加一个CURL API调用器。它易于从代码中调用,并旨在具有完整的调试功能。
阅读关于LswApiCallerBundle的LeaseWebLabs博客
要求
- PHP 5.3带curl支持
- Symfony 2.1(也可在Symfony 2.0下运行)
安装
安装分为以下步骤
- 使用composer下载LswApiCallerBundle
- 启用Bundle
- 确保PHP中的cURL模块已启用
步骤1:使用composer下载LswApiCallerBundle
在您的composer.json中添加LswApiCallerBundle
{ "require": { "leaseweb/api-caller-bundle": "*", ... } }
现在运行以下命令告诉composer下载bundle
$ php composer.phar update leaseweb/api-caller-bundle
Composer将bundle安装到您的项目的vendor/leaseweb
目录。
步骤2:启用Bundle
在kernel中启用bundle
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Lsw\ApiCallerBundle\LswApiCallerBundle(), ); }
步骤3:确保PHP中的cURL模块已启用
在基于Debian的发行版(如Ubuntu)中,该软件包名为"php5-curl",可以使用以下命令安装
$ sudo apt-get install php5-curl $ sudo service apache2 restart
在基于RedHat的发行版(如CentOS)中,该软件包名为"php-curl",可以使用以下命令安装
$ sudo yum install php-curl $ sudo service httpd restart
创建并运行以下内容的PHP文件以进行检查
<?php phpinfo() ?>
它应显示"curl支持"选项设置为"启用"。
如果PHP中启用了CURL支持,该软件包也应能在Windows安装上运行。
用法
您可以通过获取服务"api_caller"并使用一个可用的调用类型(如HttpGetJson、HttpPostJson等)来使用调用器
- HttpGetJson
- HttpPostJson
- HttpPutJson
- HttpDeleteJson
- HttpGetHtml
使用HttpGetJson调用类型的用法示例
use Symfony\Bundle\FrameworkBundle\Controller\Controller use Lsw\ApiCallerBundle\Call\HttpGetJson; class SomeController extends Controller { public function someAction() { ... $output = $this->get('api_caller')->call(new HttpGetJson($url, $parameters)); $entities = $output[0]; $httpCode = $output[1]; ... } }
配置
默认情况下,它使用以下cURL选项
parameters: api_caller.options: timeout: 10 # maximum transport + execution duration of the call in sec. ssl_verifypeer: false # to stop cURL from verifying the peer's certificate. useragent: "LeaseWeb API Caller" # contents of the "User-Agent: " header. followlocation: true # to follow any "Location: " header that the server sends. sslversion: 3 # set to 3 to avoid any bugs that relate to automatic version selection. fresh_connect: false # set to true to force full reconnect every call.
许可证
此bundle受MIT许可证的约束。
Web调试工具栏中的"wall-socket"图标是Picas图标集的一部分(官方网站:[http://www.picasicons.com](http://www.picasicons.com))。图标已获得许可,并且只能用于在Symfony2 Web调试工具栏中标识LswApiCallerBundle。此图标的全部所有权和版权均归Rok Benedik所有。