当前位置: 首页>>代码示例>>PHP>>正文


PHP Parser\ParserRegistry类代码示例

本文整理汇总了PHP中Guzzle\Parser\ParserRegistry的典型用法代码示例。如果您正苦于以下问题:PHP ParserRegistry类的具体用法?PHP ParserRegistry怎么用?PHP ParserRegistry使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ParserRegistry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testReturnsLazyLoadedDefault

 public function testReturnsLazyLoadedDefault()
 {
     $r = new ParserRegistry();
     $c = $r->getParser('cookie');
     $this->assertInstanceOf('Guzzle\\Parser\\Cookie\\CookieParser', $c);
     $this->assertSame($c, $r->getParser('cookie'));
 }
开发者ID:alvarobfdev,项目名称:applog,代码行数:7,代码来源:ParserRegistryTest.php

示例2: get_session

 /**
  * Share session with http server
  *
  * @param  $conn \Ratchet\ConnectionInterface
  */
 public static function get_session(\Ratchet\ConnectionInterface $conn)
 {
     \Session::clear_instances();
     /**
      * Set cookie
      */
     $cookie = $conn->WebSocket->request->getHeader('cookie');
     $data = \Guzzle\Parser\ParserRegistry::getInstance()->getParser('cookie')->parseCookie($cookie);
     $_COOKIE = $data['cookies'];
     /**
      * Set remote address
      */
     $x_forwarded_for = $conn->WebSocket->request->getHeader('x-forwarded-for');
     $_SERVER['REMOTE_ADDR'] = !empty($x_forwarded_for) ? $x_forwarded_for : $conn->remoteAddress;
     /**
      * Set user agent
      * 
      * TODO: How to get user agent like remote address
      */
     \Config::load('session', true);
     \COnfig::set('session.match_ua', false);
     try {
         $session = \Session::forge();
     } catch (\Exception $e) {
         $session = null;
     }
     /**
      * Remove data
      */
     $_SERVER['REMOTE_ADDR'] = null;
     $_COOKIE = null;
     \Session::clear_instances();
     return $session;
 }
开发者ID:mp-php,项目名称:fuel-packages-ratchet,代码行数:39,代码来源:ratchet.php

示例3: testSignsRequestsProperly

 /**
  * @dataProvider testSuiteProvider
  * @covers Aws\Common\Signature\SignatureV4
  * @covers Aws\Common\Signature\AbstractSignature
  */
 public function testSignsRequestsProperly($group)
 {
     $parser = ParserRegistry::getInstance()->getParser('url');
     $parser->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", '', trim(file_get_contents($group['creq']))), $context['canonical_request']);
     // Test that the string to sign is correct
     $this->assertEquals(str_replace("\r", '', trim(file_get_contents($group['sts']))), $context['string_to_sign']);
     // Test that the authorization header is correct
     $this->assertEquals(str_replace("\r", '', trim(file_get_contents($group['authz']))), (string) $request->getHeader('Authorization'));
     $parser->setUtf8Support(false);
 }
开发者ID:njbhatt18,项目名称:Amazon_API,代码行数:31,代码来源:SignatureV4Test.php

示例4: 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::getInstance()->getParser('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']);
 }
开发者ID:unkerror,项目名称:Budabot,代码行数:16,代码来源:Url.php

示例5: 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'));
 }
开发者ID:jsnshrmn,项目名称:Suma,代码行数:11,代码来源:ParserRegistryTest.php

示例6: fromMessage

 public function fromMessage($message)
 {
     $parsed = ParserRegistry::getInstance()->getParser('message')->parseRequest($message);
     if (!$parsed) {
         return false;
     }
     $request = $this->fromParts($parsed['method'], $parsed['request_url'], $parsed['headers'], $parsed['body'], $parsed['protocol'], $parsed['version']);
     if (!isset($parsed['headers']['Expect']) && !isset($parsed['headers']['expect'])) {
         $request->removeHeader('Expect');
     }
     return $request;
 }
开发者ID:Ryu0621,项目名称:SaNaVi,代码行数:12,代码来源:RequestFactory.php

示例7: factory

 public static function factory($config = array())
 {
     ParserRegistry::getInstance()->registerParser('uri_template', new MyrrixUriTemplate(ParserRegistry::getInstance()->getParser('uri_template')));
     $default = array('base_url' => 'http://{hostname}:{port}', 'hostname' => 'localhost', 'port' => 8080, 'username' => null, 'password' => null);
     $required = array('hostname', 'port', 'base_url', 'username', 'password');
     $config = Collection::fromConfig($config, $default, $required);
     $client = new self($config->get('base_url'), $config);
     $client->setDescription(ServiceDescription::factory(__DIR__ . DIRECTORY_SEPARATOR . 'service.json'));
     $client->setDefaultHeaders(array('Accept' => 'text/html'));
     $authPlugin = new CurlAuthPlugin($config['username'], $config['password']);
     $client->addSubscriber($authPlugin);
     return $client;
 }
开发者ID:ulkas,项目名称:bcc-myrrix,代码行数:13,代码来源:MyrrixClient.php

示例8: 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;
 }
开发者ID:robertkraig,项目名称:guzzle,代码行数:21,代码来源:Response.php

示例9: fromMessage

 public static function fromMessage($message)
 {
     $data = ParserRegistry::getInstance()->getParser('message')->parseResponse($message);
     if (!$data) {
         return false;
     }
     $response = new static($data['code'], $data['headers'], $data['body']);
     $response->setProtocol($data['protocol'], $data['version'])->setStatus($data['code'], $data['reason_phrase']);
     $contentLength = (string) $response->getHeader('Content-Length');
     $actualLength = strlen($data['body']);
     if (strlen($data['body']) > 0 && $contentLength != $actualLength) {
         $response->setHeader('Content-Length', $actualLength);
     }
     return $response;
 }
开发者ID:Ryu0621,项目名称:SaNaVi,代码行数:15,代码来源:Response.php

示例10: fromMessage

 /**
  * {@inheritdoc}
  */
 public function fromMessage($message)
 {
     $parsed = ParserRegistry::getInstance()->getParser('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;
 }
开发者ID:KANU82,项目名称:guzzle,代码行数:18,代码来源:RequestFactory.php

示例11: 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);
     }
 }
开发者ID:jsnshrmn,项目名称:Suma,代码行数:46,代码来源:DynamicCommand.php

示例12: prepare

 /**
  * {@inheritdoc}
  */
 public function prepare(CommandInterface $command)
 {
     $operation = $command->getOperation();
     $client = $command->getClient();
     $uri = $operation->getUri();
     if (!$uri) {
         $url = $client->getBaseUrl();
     } else {
         // Get the path values and use the client config settings
         $variables = $client->getConfig()->getAll();
         foreach ($operation->getParams() as $name => $arg) {
             if ($arg->getLocation() == 'uri' && $command->hasKey($name)) {
                 $variables[$name] = $command->get($name);
                 if (!is_array($variables[$name])) {
                     $variables[$name] = (string) $variables[$name];
                 }
             }
         }
         // Merge the client's base URL with an expanded URI template
         $url = (string) Url::factory($client->getBaseUrl())->combine(ParserRegistry::getInstance()->getParser('uri_template')->expand($uri, $variables));
     }
     // Inject path and base_url values into the URL
     $request = $client->createRequest($operation->getHttpMethod(), $url);
     // Add arguments to the request using the location attribute
     foreach ($operation->getParams() as $name => $arg) {
         /** @var $arg \Guzzle\Service\Description\Parameter */
         $location = $arg->getLocation();
         // Visit with the associated visitor
         if (isset($this->visitors[$location])) {
             // Ensure that a value has been set for this parameter
             $value = $command->get($name);
             if ($value !== null) {
                 // Apply the parameter value with the location visitor
                 $this->visitors[$location]->visit($command, $request, $arg, $value);
             }
         }
     }
     // Call the after method on each visitor
     foreach ($this->visitors as $visitor) {
         $visitor->after($command, $request);
     }
     return $request;
 }
开发者ID:xkeygmbh,项目名称:ifresco-php,代码行数:46,代码来源:DefaultRequestSerializer.php

示例13: addCookiesFromResponse

 public function addCookiesFromResponse(Response $response, RequestInterface $request = null)
 {
     if ($cookieHeader = $response->getHeader('Set-Cookie')) {
         $parser = ParserRegistry::getInstance()->getParser('cookie');
         foreach ($cookieHeader as $cookie) {
             if ($parsed = $request ? $parser->parseCookie($cookie, $request->getHost(), $request->getPath()) : $parser->parseCookie($cookie)) {
                 foreach ($parsed['cookies'] as $key => $value) {
                     $row = $parsed;
                     $row['name'] = $key;
                     $row['value'] = $value;
                     unset($row['cookies']);
                     $this->add(new Cookie($row));
                 }
             }
         }
     }
 }
开发者ID:Ryu0621,项目名称:SaNaVi,代码行数:17,代码来源:ArrayCookieJar.php

示例14: addCookiesFromResponse

 /**
  * {@inheritdoc}
  */
 public function addCookiesFromResponse(Response $response)
 {
     if ($cookieHeader = $response->getSetCookie()) {
         $request = $response->getRequest();
         $parser = ParserRegistry::getInstance()->getParser('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));
                 }
             }
         }
     }
 }
开发者ID:idiscussforum,项目名称:providence,代码行数:23,代码来源:ArrayCookieJar.php

示例15: createRequest

 /**
  * Create a request for the command and operation
  *
  * @param CommandInterface $command Command to create a request for
  *
  * @return RequestInterface
  */
 protected function createRequest(CommandInterface $command)
 {
     $operation = $command->getOperation();
     $client = $command->getClient();
     // If the command does not specify a template, then assume the base URL of the client
     if (!($uri = $operation->getUri())) {
         return $client->createRequest($operation->getHttpMethod(), $client->getBaseUrl());
     }
     // Get the path values and use the client config settings
     $variables = array();
     foreach ($operation->getParams() as $name => $arg) {
         if ($arg->getLocation() == 'uri') {
             if ($command->hasKey($name)) {
                 $variables[$name] = $arg->filter($command->get($name));
                 if (!is_array($variables[$name])) {
                     $variables[$name] = (string) $variables[$name];
                 }
             }
         }
     }
     // Merge the client's base URL with an expanded URI template
     return $client->createRequest($operation->getHttpMethod(), (string) Url::factory($client->getBaseUrl())->combine(ParserRegistry::getInstance()->getParser('uri_template')->expand($uri, $variables)));
 }
开发者ID:creazy412,项目名称:vmware-win10-c65-drupal7,代码行数:30,代码来源:DefaultRequestSerializer.php


注:本文中的Guzzle\Parser\ParserRegistry类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。