當前位置: 首頁>>代碼示例>>PHP>>正文


PHP RequestInterface::getEmitter方法代碼示例

本文整理匯總了PHP中GuzzleHttp\Message\RequestInterface::getEmitter方法的典型用法代碼示例。如果您正苦於以下問題:PHP RequestInterface::getEmitter方法的具體用法?PHP RequestInterface::getEmitter怎麽用?PHP RequestInterface::getEmitter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在GuzzleHttp\Message\RequestInterface的用法示例。


在下文中一共展示了RequestInterface::getEmitter方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: add_callback

 protected function add_callback(RequestInterface $request, callable $callback)
 {
     $request->getEmitter()->on('response.output', function (OutputEvent $event) use($callback) {
         $callback($event->getContent(), $event->getType());
     });
     $request->getConfig()->set('attach_filter', true);
 }
開發者ID:lab-dvsoftware,項目名稱:docker-php,代碼行數:7,代碼來源:MessageFactory.php

示例2: emit

 private function emit(RequestInterface $request)
 {
     $event = new BeforeEvent(new Transaction(new Client(), $request));
     $request->getEmitter()->emit('before', $event);
 }
開發者ID:hilmysyarif,項目名稱:sic,代碼行數:5,代碼來源:CurlFactoryTest.php

示例3: setupRequest

 /**
  * @param RequestInterface $request
  * @return RequestInterface
  */
 public function setupRequest(RequestInterface $request)
 {
     $identitiy = $this->getCurrentIdentity();
     if ($identitiy->getCookieJar() != null) {
         //todo
         // this seems pretty hacky... is there a better way to replace the cookie container of a request?
         // > Currently not @see https://github.com/guzzle/guzzle/issues/1028#issuecomment-96253542 - maybe with Guzzle 6
         // remove current cookie subscribers
         $emitter = $request->getEmitter();
         foreach ($emitter->listeners("complete") as $listener) {
             if (is_array($listener) && $listener[0] instanceof Cookie) {
                 $emitter->detach($listener[0]);
             }
         }
         // set new Cookie subscriber
         $cookie = new Cookie($identitiy->getCookieJar());
         $emitter->attach($cookie);
     }
     if ($identitiy->getUserAgent() != null) {
         $request->setHeader("user-agent", $identitiy->getUserAgent());
     }
     $headers = $identitiy->getDefaultRequestHeaders();
     if ($headers != null) {
         foreach ($headers as $key => $val) {
             $request->setHeader($key, $val);
         }
     }
     if ($identitiy->getReferer() != null && trim($identitiy->getReferer()) != "") {
         $request->setHeader("referer", $identitiy->getReferer());
     }
     $request = parent::setupRequest($request);
     return $request;
 }
開發者ID:paslandau,項目名稱:guzzle-rotating-proxy-subscriber,代碼行數:37,代碼來源:RotatingIdentityProxy.php

示例4: add_subscribers

 private function add_subscribers(RequestInterface $request, $value)
 {
     if (!is_array($value)) {
         throw new \InvalidArgumentException('subscribers must be an array');
     }
     $emitter = $request->getEmitter();
     foreach ($value as $subscribers) {
         $emitter->attach($subscribers);
     }
 }
開發者ID:hilmysyarif,項目名稱:sic,代碼行數:10,代碼來源:MessageFactory.php

示例5: applyOptions

 protected function applyOptions(RequestInterface $request, array $options = [])
 {
     $config = $request->getConfig();
     $emitter = $request->getEmitter();
     foreach ($options as $key => $value) {
         if (isset(self::$configMap[$key])) {
             $config[$key] = $value;
             continue;
         }
         switch ($key) {
             case 'allow_redirects':
                 if ($value === false) {
                     continue;
                 }
                 if ($value === true) {
                     $value = self::$defaultRedirect;
                 } elseif (!isset($value['max'])) {
                     throw new Iae('allow_redirects must be true, false, or an ' . 'array that contains the \'max\' key');
                 } else {
                     // Merge the default settings with the provided settings
                     $value += self::$defaultRedirect;
                 }
                 $config['redirect'] = $value;
                 $emitter->attach($this->redirectPlugin);
                 break;
             case 'decode_content':
                 if ($value === false) {
                     continue;
                 }
                 $config['decode_content'] = true;
                 if ($value !== true) {
                     $request->setHeader('Accept-Encoding', $value);
                 }
                 break;
             case 'headers':
                 if (!is_array($value)) {
                     throw new Iae('header value must be an array');
                 }
                 // Do not overwrite existing headers
                 foreach ($value as $k => $v) {
                     if (!$request->hasHeader($k)) {
                         $request->setHeader($k, $v);
                     }
                 }
                 break;
             case 'exceptions':
                 if ($value === true) {
                     $emitter->attach($this->errorPlugin);
                 }
                 break;
             case 'body':
                 if (is_array($value)) {
                     $this->addPostData($request, $value);
                 } elseif ($value !== null) {
                     $request->setBody(Stream::factory($value));
                 }
                 break;
             case 'auth':
                 if (!$value) {
                     continue;
                 }
                 if (is_array($value)) {
                     $type = isset($value[2]) ? strtolower($value[2]) : 'basic';
                 } else {
                     $type = strtolower($value);
                 }
                 $config['auth'] = $value;
                 if ($type == 'basic') {
                     $request->setHeader('Authorization', 'Basic ' . base64_encode("{$value['0']}:{$value['1']}"));
                 } elseif ($type == 'digest') {
                     // @todo: Do not rely on curl
                     $config->setPath('curl/' . CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
                     $config->setPath('curl/' . CURLOPT_USERPWD, "{$value['0']}:{$value['1']}");
                 }
                 break;
             case 'query':
                 if ($value instanceof Query) {
                     $original = $request->getQuery();
                     // Do not overwrite existing query string variables by
                     // overwriting the object with the query string data passed
                     // in the URL
                     $value->overwriteWith($original->toArray());
                     $request->setQuery($value);
                 } elseif (is_array($value)) {
                     // Do not overwrite existing query string variables
                     $query = $request->getQuery();
                     foreach ($value as $k => $v) {
                         if (!isset($query[$k])) {
                             $query[$k] = $v;
                         }
                     }
                 } else {
                     throw new Iae('query must be an array or Query object');
                 }
                 break;
             case 'cookies':
                 if ($value === true) {
                     static $cookie = null;
                     if (!$cookie) {
                         $cookie = new Cookie();
//.........這裏部分代碼省略.........
開發者ID:DeveloperOwl,項目名稱:flipside.io,代碼行數:101,代碼來源:MessageFactory.php

示例6: extractCookiesArgument

 /**
  * @param RequestInterface $request
  */
 protected function extractCookiesArgument(RequestInterface $request)
 {
     $listeners = $request->getEmitter()->listeners('before');
     foreach ($listeners as $listener) {
         if ($listener[0] instanceof Cookie) {
             $values = [];
             $scheme = $request->getScheme();
             $host = $request->getHost();
             $path = $request->getPath();
             /** @var SetCookie $cookie */
             foreach ($listener[0]->getCookieJar() as $cookie) {
                 if ($cookie->matchesPath($path) && $cookie->matchesDomain($host) && !$cookie->isExpired() && (!$cookie->getSecure() || $scheme == 'https')) {
                     $values[] = $cookie->getName() . '=' . CookieJar::getCookieValue($cookie->getValue());
                 }
             }
             if ($values) {
                 $this->addOption('b', escapeshellarg(implode('; ', $values)));
             }
         }
     }
 }
開發者ID:mdrost,項目名稱:cuzzle,代碼行數:24,代碼來源:CurlFormatter.php

示例7: addListeners

 private function addListeners(RequestInterface $request, &$calls)
 {
     $request->getEmitter()->on('before', function (BeforeEvent $e) use(&$calls) {
         $calls[] = 'before';
     }, RequestEvents::EARLY);
     $request->getEmitter()->on('complete', function (CompleteEvent $e) use(&$calls) {
         $calls[] = 'complete';
     }, RequestEvents::EARLY);
     $request->getEmitter()->on('error', function (ErrorEvent $e) use(&$calls) {
         $calls[] = 'error';
     }, RequestEvents::EARLY);
     $request->getEmitter()->on('end', function (EndEvent $e) use(&$calls) {
         $calls[] = 'end';
     }, RequestEvents::EARLY);
 }
開發者ID:GerDner,項目名稱:luck-docker,代碼行數:15,代碼來源:RequestFsmTest.php


注:本文中的GuzzleHttp\Message\RequestInterface::getEmitter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。