for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Http\HttplugBundle\Collector;
use Closure;
use Http\Client\Common\Plugin;
use Http\Client\Exception;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
class DebugPluginDecorator implements Plugin
{
/**
* @var Plugin
*/
private $plugin;
* @var Collector
private $collector;
* @param Plugin $plugin
* @param Collector $collector
public function __construct(Plugin $plugin, Collector $collector)
$this->plugin = $plugin;
$this->collector = $collector;
}
* {@inheritdoc}
public function handleRequest(RequestInterface $request, callable $next, callable $first)
$this->plugin->handleRequest($request, $this->wrap($next, false), $this->wrap($first, true));
* @param callable $callable
* @param bool $first
*
* @return Closure
private function wrap(callable $callable, $first)
return function (RequestInterface $request) use ($callable, $first) {
$profile = $this->collector->getProfile($this->plugin, $request);
$profile->setFirst($first);
return $callable($request)->then(function (ResponseInterface $response) use ($profile) {
$profile->setResponse($response);
return $response;
}, function (Exception $exception) use ($profile) {
$profile->setException($exception);
throw $exception;
});
};