public function discover($target) { $res = $this->client->request('GET', $target); foreach (Psr7\parse_header($res->getHeader('Link')) as $linkHeader) { if ($linkHeader['rel'] == 'webmention') { return substr($linkHeader[0], 1, -1); } } throw new \Exception('Webmention link not found'); }
/** * @param ResponseInterface $response * * @return string|null */ private function next(ResponseInterface $response) { $links = Psr7\parse_header($response->getHeader('Link')); foreach ($links as $link) { if ($link['rel'] == 'next') { return trim($link[0], '<>'); } } return null; }
/** * @test */ public function shouldSetOAuthParamsInAuthorizationHeader() { $mock = new MockHandler([new Response(200)]); $handler = HandlerStack::create($mock); $container = []; // Add the history middleware to the handler stack. $history = Middleware::history($container); $handler->push($history); $client = new Client($this->APIKey, ['handler' => $handler, 'OAuthSecret' => $this->OAuthSecret]); $client->setToken($this->oauth_token, $this->oauth_token_secret); $client->get('album/rAnD0m'); foreach ($container as $transaction) { $auth_header = Psr7\parse_header($transaction['request']->getHeader('Authorization')); // Asserts the header is set and populated $this->assertNotEmpty($auth_header); // Now parse and flatten the header so we can check the values $parsed_auth_header = []; foreach ($auth_header as $h) { foreach ($h as $key => $value) { $parsed_auth_header[$key] = $value; } } $this->assertEquals($this->APIKey, $parsed_auth_header['OAuth oauth_consumer_key']); $this->assertEquals($this->oauth_token, $parsed_auth_header['oauth_token']); $this->assertEquals('HMAC-SHA1', $parsed_auth_header['oauth_signature_method']); $this->assertEquals('1.0', $parsed_auth_header['oauth_version']); $this->assertArrayHasKey('oauth_nonce', $parsed_auth_header); $this->assertArrayHasKey('oauth_signature', $parsed_auth_header); $this->assertArrayHasKey('oauth_timestamp', $parsed_auth_header); } }
/** * @dataProvider parseParamsProvider */ public function testParseParams($header, $result) { $this->assertEquals($result, Psr7\parse_header($header)); }
private function extractContentDisposition(array $headers) { return isset($headers['content-disposition']) ? parse_header($headers['content-disposition'][0])[0] : []; }