bestit / commercetools-async-pool
处理异步commercetools请求的批处理。
3.1.0
2017-08-20 19:48 UTC
Requires
- php: ^7.0
- commercetools/php-sdk: ^1.4 || ^2.0
Requires (Dev)
- phpunit/phpunit: ^5.5
- squizlabs/php_codesniffer: ^2.0
README
处理异步commercetools请求的批处理。
介绍
Commercetools建议您使用异步请求而不是顺序请求,但PHP SDK使这并不容易。
- Client::executeAsync的Promise在原始guzzle响应上工作,而不是“请求的对象”。
- Guzzle的promise-chaining/forwarding和commercetools的AbstractApiResponse不兼容。
因此,我创建了一个帮助的异步请求池。请审阅以下信息。
安装
composer require bestit/commercetools-async-pool
API和用法
$pool = new Pool($this->getClient()); $pool->addPromise(ProductTypeByIdGetRequest::ofId('example')).then( // Success function(ProductType $productType) use ($userdata) { echo $productType->getId(); }, // optional error callback function(ErrorResponse $error) { echo $error->getStatusCode(); } ); //.then(/* chained callbacks */) //.then() // .... // Gets flushed automatically, if we overflow the tick rate from the constructor. $pool->flush();
但请注意,回调是异步发生的!这不再是顺序的PHP了!
未来
- 更多的单元测试