本文整理汇总了PHP中Guzzle\Parser\ParserRegistry::get方法的典型用法代码示例。如果您正苦于以下问题:PHP ParserRegistry::get方法的具体用法?PHP ParserRegistry::get怎么用?PHP ParserRegistry::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Parser\ParserRegistry
的用法示例。
在下文中一共展示了ParserRegistry::get方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSignsRequestsProperly
/**
* @dataProvider testSuiteProvider
* @covers Aws\Common\Signature\SignatureV4
* @covers Aws\Common\Signature\AbstractSignature
*/
public function testSignsRequestsProperly($group)
{
ParserRegistry::get('url')->setUtf8Support(true);
// Create a request based on the '.req' file
$requestString = file_get_contents($group['req']);
$request = RequestFactory::getInstance()->fromMessage($requestString);
// Sanitize the request
$request->removeHeader('User-Agent');
$request->removeHeader('Content-Length');
// Sign the request using the test credentials
$credentials = new Credentials(self::DEFAULT_KEY, self::DEFAULT_SECRET);
// Get a mock signature object
$signature = $this->getSignature();
// Sign the request
$signature->signRequest($request, $credentials);
// Get debug signature information
$context = $request->getParams()->get('aws.signature');
// Test that the canonical request is correct
$this->assertEquals(str_replace("\r", '', file_get_contents($group['creq'])), $context['canonical_request']);
// Test that the string to sign is correct
$this->assertEquals(str_replace("\r", '', file_get_contents($group['sts'])), $context['string_to_sign']);
// Test that the authorization header is correct
$this->assertEquals(str_replace("\r", '', file_get_contents($group['authz'])), $request->getHeader('Authorization'));
ParserRegistry::get('url')->setUtf8Support(false);
}
示例2: factory
/**
* Factory method to create a new URL from a URL string
*
* @param string $url Full URL used to create a Url object
*
* @return Url
*/
public static function factory($url)
{
$parts = ParserRegistry::get('url')->parseUrl($url);
// Convert the query string into a QueryString object
if ($parts['query']) {
$parts['query'] = QueryString::fromString($parts['query']);
}
return new self($parts['scheme'], $parts['host'], $parts['user'], $parts['pass'], $parts['port'], $parts['path'], $parts['query'], $parts['fragment']);
}
示例3: testReturnsLazyLoadedDefault
public function testReturnsLazyLoadedDefault()
{
// Clear out what might be cached
$refObject = new \ReflectionClass('Guzzle\\Parser\\ParserRegistry');
$refProperty = $refObject->getProperty('instances');
$refProperty->setAccessible(true);
$refProperty->setValue(null, array());
$c = ParserRegistry::get('cookie');
$this->assertInstanceOf('Guzzle\\Parser\\Cookie\\CookieParser', $c);
$this->assertSame($c, ParserRegistry::get('cookie'));
}
示例4: fromMessage
/**
* Create a new Response based on a raw response message
*
* @param string $message Response message
*
* @return Response|bool Returns false on error
*/
public static function fromMessage($message)
{
$data = ParserRegistry::get('message')->parseResponse($message);
if (!$data) {
return false;
}
// Always set the appropriate Content-Length
unset($data['headers']['Content-Length']);
unset($data['headers']['content-length']);
$data['headers']['Content-Length'] = strlen($data['body']);
$response = new static($data['code'], $data['headers'], $data['body']);
$response->setProtocol($data['protocol'], $data['version'])->setStatus($data['code'], $data['reason_phrase']);
return $response;
}
示例5: fromMessage
/**
* {@inheritdoc}
*/
public function fromMessage($message)
{
$parsed = ParserRegistry::get('message')->parseRequest($message);
if (!$parsed) {
return false;
}
$request = $this->fromParts($parsed['method'], $parsed['request_url'], $parsed['headers'], $parsed['body'], $parsed['protocol'], $parsed['version']);
// EntityEnclosingRequest adds an "Expect: 100-Continue" header when
// using a raw request body for PUT or POST requests. This factory
// method should accurately reflect the message, so here we are
// removing the Expect header if one was not supplied in the message.
if (!isset($parsed['headers']['Expect']) && !isset($parsed['headers']['expect'])) {
$request->removeHeader('Expect');
}
return $request;
}
示例6: build
/**
* {@inheritdoc}
*/
protected function build()
{
$uri = $this->apiCommand->getUri();
if (!$uri) {
$url = $this->client->getBaseUrl();
} else {
// Get the path values and use the client config settings
$variables = $this->client->getConfig()->getAll();
foreach ($this->apiCommand->getParams() as $name => $arg) {
$configValue = $this->get($name);
if (is_scalar($configValue)) {
$variables[$name] = $arg->getPrepend() . $configValue . $arg->getAppend();
}
}
// Merge the client's base URL with an expanded URI template
$url = (string) Url::factory($this->client->getBaseUrl())->combine(ParserRegistry::get('uri_template')->expand($uri, $variables));
}
// Inject path and base_url values into the URL
$this->request = $this->client->createRequest($this->apiCommand->getMethod(), $url);
// Add arguments to the request using the location attribute
foreach ($this->apiCommand->getParams() as $name => $arg) {
$location = $arg->getLocation();
// Visit with the associated visitor
if (isset($this->visitors[$location])) {
// Ensure that a value has been set for this parameter
$configValue = $this->get($name);
if ($configValue !== null) {
// Create the value based on prepend and append settings
if ($arg->getPrepend() || $arg->getAppend()) {
$value = $arg->getPrepend() . $configValue . $arg->getAppend();
} else {
$value = $configValue;
}
// Apply the parameter value with the location visitor
$this->visitors[$location]->visit($this, $this->request, $arg->getLocationKey() ?: $name, $value);
}
}
}
// Call the after method on each visitor
foreach ($this->visitors as $visitor) {
$visitor->after($this, $this->request);
}
}
示例7: getCookies
/**
* {@inheritdoc}
*/
public function getCookies()
{
if ($cookie = $this->getHeader('Cookie')) {
$data = ParserRegistry::get('cookie')->parseCookie($cookie);
return $data['cookies'];
}
return array();
}
示例8: updateRequestFromTransfer
/**
* Update a request based on the log messages of the CurlHandle
*
* @param RequestInterface $request Request to update
*/
public function updateRequestFromTransfer(RequestInterface $request)
{
$log = $this->getStderr(true);
if (!$log || !$request->getResponse()) {
return;
}
// Update the transfer stats of the response
$request->getResponse()->setInfo($this->getInfo());
// Parse the cURL stderr output for outgoing requests
$headers = '';
fseek($log, 0);
while (($line = fgets($log)) !== false) {
if ($line && $line[0] == '>') {
$headers = substr(trim($line), 2) . "\r\n";
while (($line = fgets($log)) !== false) {
if ($line[0] == '*' || $line[0] == '<') {
break;
} else {
$headers .= trim($line) . "\r\n";
}
}
}
}
// Add request headers to the request exactly as they were sent
if ($headers) {
$parsed = ParserRegistry::get('message')->parseRequest($headers);
if (!empty($parsed['headers'])) {
$request->setHeaders(array());
foreach ($parsed['headers'] as $name => $value) {
$request->setHeader($name, $value);
}
}
if (!empty($parsed['version'])) {
$request->setProtocolVersion($parsed['version']);
}
}
}
示例9: getUriTemplate
/**
* {@inheritdoc}
*/
public function getUriTemplate()
{
if (!$this->uriTemplate) {
$this->uriTemplate = ParserRegistry::get('uri_template');
}
return $this->uriTemplate;
}
示例10: build
/**
* {@inheritdoc}
*/
protected function build()
{
if (!$this->apiCommand->getUri()) {
$url = $this->getClient()->getBaseUrl();
} else {
// Get the path values and use the client config settings
$variables = $this->getClient()->getConfig()->getAll();
foreach ($this->apiCommand->getParams() as $name => $arg) {
$configValue = $this->get($name);
if (is_scalar($configValue)) {
$variables[$name] = $arg->getPrepend() . $configValue . $arg->getAppend();
}
}
// Expand the URI template using the URI values
$uri = ParserRegistry::get('uri_template')->expand($this->apiCommand->getUri(), $variables);
// Merge the client's base URL with the URI template
$url = Url::factory($this->getClient()->getBaseUrl());
$url->combine($uri);
$url = (string) $url;
}
// Inject path and base_url values into the URL
$this->request = $this->getClient()->createRequest($this->apiCommand->getMethod(), $url);
// Add arguments to the request using the location attribute
foreach ($this->apiCommand->getParams() as $name => $arg) {
$configValue = $this->get($name);
$location = $arg->getLocation();
if (!$configValue || !$location) {
continue;
}
// Create the value based on prepend and append settings
if ($arg->getPrepend() || $arg->getAppend()) {
$value = $arg->getPrepend() . $configValue . $arg->getAppend();
} else {
$value = $configValue;
}
// If a location key mapping is set, then use it
$key = $arg->getLocationKey() ?: $name;
// Add the parameter to the request
switch ($location) {
case 'body':
$this->request->setBody(EntityBody::factory($value));
break;
case 'header':
$this->request->setHeader($key, $value);
break;
case 'query':
$this->request->getQuery()->set($key, $value);
break;
case 'post_field':
$this->request->setPostField($key, $value);
break;
case 'post_file':
if ($value instanceof PostFileInterface) {
$this->request->addPostFile($value);
} else {
$this->request->addPostFile($key, $value);
}
break;
}
}
}
示例11: addCookiesFromResponse
/**
* {@inheritdoc}
*/
public function addCookiesFromResponse(Response $response)
{
if ($cookieHeader = $response->getSetCookie()) {
$request = $response->getRequest();
$parser = ParserRegistry::get('cookie');
foreach ($cookieHeader as $cookie) {
$parsed = $request ? $parser->parseCookie($cookie, $request->getHost(), $request->getPath()) : $parser->parseCookie($cookie);
if ($parsed) {
// Break up cookie v2 into multiple cookies
foreach ($parsed['cookies'] as $key => $value) {
$row = $parsed;
$row['name'] = $key;
$row['value'] = $value;
unset($row['cookies']);
$this->add(new Cookie($row));
}
}
}
}
}