[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/vendor/guzzlehttp/guzzle/src/Subscriber/ -> Cookie.php (source)

   1  <?php
   2  namespace GuzzleHttp\Subscriber;
   3  
   4  use GuzzleHttp\Cookie\CookieJar;
   5  use GuzzleHttp\Cookie\CookieJarInterface;
   6  use GuzzleHttp\Event\BeforeEvent;
   7  use GuzzleHttp\Event\CompleteEvent;
   8  use GuzzleHttp\Event\RequestEvents;
   9  use GuzzleHttp\Event\SubscriberInterface;
  10  
  11  /**
  12   * Adds, extracts, and persists cookies between HTTP requests
  13   */
  14  class Cookie implements SubscriberInterface
  15  {
  16      /** @var CookieJarInterface */
  17      private $cookieJar;
  18  
  19      /**
  20       * @param CookieJarInterface $cookieJar Cookie jar used to hold cookies
  21       */
  22      public function __construct(CookieJarInterface $cookieJar = null)
  23      {
  24          $this->cookieJar = $cookieJar ?: new CookieJar();
  25      }
  26  
  27      public function getEvents()
  28      {
  29          // Fire the cookie plugin complete event before redirecting
  30          return [
  31              'before'   => ['onBefore'],
  32              'complete' => ['onComplete', RequestEvents::REDIRECT_RESPONSE + 10]
  33          ];
  34      }
  35  
  36      /**
  37       * Get the cookie cookieJar
  38       *
  39       * @return CookieJarInterface
  40       */
  41      public function getCookieJar()
  42      {
  43          return $this->cookieJar;
  44      }
  45  
  46      public function onBefore(BeforeEvent $event)
  47      {
  48          $this->cookieJar->addCookieHeader($event->getRequest());
  49      }
  50  
  51      public function onComplete(CompleteEvent $event)
  52      {
  53          $this->cookieJar->extractCookies(
  54              $event->getRequest(),
  55              $event->getResponse()
  56          );
  57      }
  58  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1