<?php require '../vendor/autoload.php'; // Get URI object. $uri = Zend\Diactoros\ServerRequestFactory::fromGlobals()->getUri(); // Setup DebugBar $debugbar = new DebugBar\StandardDebugBar(); $debugbar->getJavascriptRenderer()->setBaseUrl($uri->withPort('8000')->withPath('/')); // Setting up the stack off middlewares. $handler = GuzzleHttp\HandlerStack::create(); $middleware = new GuzzleHttp\Profiling\Middleware(new GuzzleHttp\Profiling\Debugbar\Profiler($debugbar->getCollector('time'))); $handler->unshift($middleware); $handler->unshift(Demo1\GithubAuth::create()); // Boot application. $controller = new Demo6\Controller(new GuzzleHttp\Client(compact('handler')), $debugbar->getJavascriptRenderer()); // Let application do the magic. $response = $controller->index(); // Output Response. (new Zend\Diactoros\Response\SapiEmitter())->emit($response);
private function __getClient() { $config = []; if (isset($this->_config['sparkpost']['log'])) { $stack = GuzzleHttp\HandlerStack::create(); $stack->push(GuzzleHttp\Middleware::log(class_exists('\\Cake\\Log\\Log') ? new \Cake\Log\Log() : new Cake2PsrLog(), new GuzzleHttp\MessageFormatter(isset($this->_config['sparkpost']['log']['format']) ? $this->_config['sparkpost']['log']['format'] : '{response}'), isset($this->_config['sparkpost']['log']['level']) ? $this->_config['sparkpost']['log']['level'] : 'debug')); $config = ['handler' => $stack]; } return new GuzzleHttp\Client($config); }
/** * Return Guzzle Mock * * @param int $secondStatus * @param array $secondHeaders * @param string $secondBody * @return GuzzleHttp\Client */ private function getGuzzleMock($secondStatus = null, $secondHeaders = [], $secondBody = null) { $mock = new GuzzleHttp\Handler\MockHandler([new GuzzleHttp\Psr7\Response(200, ['Content-Type' => [0 => 'application/json; charset=utf-8']], '{"token_type":"http://schemas.xmlsoap.org/ws/2009/11/swt-token-profile-1.0","access_token":"lorem-ipsum-access-token","expires_in":"599","scope":"lorem ipsum scope"}'), new GuzzleHttp\Psr7\Response($secondStatus, $secondHeaders, $secondBody)]); $handler = GuzzleHttp\HandlerStack::create($mock); return new GuzzleHttp\Client(['handler' => $handler]); }