edouardkombo / ek-api-caller-bundle
cURL API 调用功能,轻松与任何 web API 通信。
dev-master
2014-07-27 07:21 UTC
Requires
- php: >=5.3.0
- edouardkombo/php-objects-contract-bundle: dev-master
This package is not auto-updated.
Last update: 2024-09-24 02:47:26 UTC
README
关于
此包可以帮助您通过 cURL 轻松调用任何 web API。它采用 CABIN 设计模式(接口的具象抽象),提供清晰、符合 S.O.L.I.D 原则的逻辑代码语法。
CABIN 原则是什么意思?
CABIN 代表接口的具象抽象(Concrete ABstraction of INterfaces),更多信息请参阅:https://creativcoders.wordpress.com/2014/05/10/cabin-principle-or-how-to-define-an-object-oriented-code/
要求
需要 PHP 版本 5.3 或更高。
安装
在 composer.json 中注册此包
{
"require": {
"edouardkombo/ek-api-caller-bundle": "dev-master"
}
}
现在,安装供应商
php composer.phar install
在 app/appKernel.php 中注册 MultiStepFormsBundle 命名空间
new EdouardKombo\EkApiCallerBundle\EkApiCallerBundle(),
在 app/config/config.php 中设置配置参数
ek_api_caller:
cache: true
verify_ssl_certificates: false
timeout: 90 #Maximum time of curl request
connect_timeout: 30 #Wait x seconds before reconnect
文档
如何使用?在您的控制器中,像这样调用 httpContract 服务
$curl = $this->get('ek_api_caller.contract.http');
$curl->setParameter('url', $url);
$curl->setParameter('headers', $httpHeaders); //$httpHeaders => array
$curl->setParameter('datas', $urlDatas); //$urlDatas => array
//Available methods for request are post, get, delete
//These methods return an array of two values (response message, and http status code)
//You can use these values to generate your api specific errors
$curl->post();
//$urlDatas array are automatically encoded, just specify an array of key => values
//Example for stripe api
$urlDatas = [
'amount' => 5500,
'currency' => 'EUR',
'card' => [
'number' => '4242424242424242',
'exp_month' => '10',
'exp_year' => '16',
'cvc' => '123',
],
];
//$httpHeaders must be array to, but without key values
//Example for stripe api
$user_agent = [
'bindings_version' => '1.0.0',
'lang' => 'php',
'lang_version' => PHP_VERSION,
'publisher' => 'scribe',
'uname' => php_uname(),
];
$httpHeaders = [
'X-Stripe-Client-User-Agent: ' . json_encode($user_agent),
'User-Agent: Stripe/v1 ScribeStripeBundle/' . '1.0.0',
'Authorization: Bearer ' . 'STRIPE_SECRET_KEY',
'Stripe-Version: ' . '2014-01-31'
];
贡献
如果您想帮助我改进此包,请确保它符合 PSR 编码标准。最容易的贡献方式是工作在仓库的检查中,或者您的分支,而不是已安装的版本。
问题
在 Github 问题跟踪器 上提交错误报告和功能请求。
如需更多信息,请直接联系我:edouard.kombo@gmail.com。