예제 #1
0
 /**
  * @param Browser $client
  * @param ListenerInterface $listener
  *
  * @return bool
  */
 protected function hasListener(Browser $client, ListenerInterface $listener)
 {
     /** @var ListenerInterface $listenerClient */
     if (!($listenerClient = $client->getListener())) {
         return false;
     }
     if (!$listenerClient instanceof ListenerChain) {
         return $listenerClient instanceof $listener;
     }
     /** @var ListenerChain $listenerBrowser */
     /** @var ListenerInterface $listenerItem */
     foreach ($listenerClient->getListeners() as $listenerItem) {
         if ($listenerItem instanceof $listener) {
             return true;
         }
     }
     return false;
 }
 /**
  * Add UserAuth Cookie to the local storage
  * for later requests.
  * It needs to be prepended otherwise only the incorrect AUTH Cookie from the original request will be send
  *
  * @see self::initContaoRequestHeaders()
  * @param Browser $browser
  */
 protected function prependAuthCookie(Browser $browser)
 {
     // Append the FE_USER_AUTH Cookie to the current request, so followed request like loadlayout don't have
     // to run through the autologin / 303 process
     foreach ($browser->getListener()->getCookies() as $cookie) {
         if ($cookie->getName() == 'FE_USER_AUTH' && !$cookie->isExpired()) {
             $this->cookieAppendix = 'FE_USER_AUTH=' . $cookie->getValue() . '; ';
         }
     }
 }
    /**
     * Create Sahi API Connection with custom SID.
     *
     * @param string  $sid     sahi id
     * @param Browser $browser
     * @param boolean $correct add correct responses to browser Queue for browser creation
     *
     * @return Connection
     */
    protected function createConnection($sid, Browser $browser, $correct = false)
    {
        if ($correct) {
            $browser->getClient()->sendToQueue($this->createResponse('1.0 200 OK', 'true'));
            $browser->getClient()->sendToQueue($this->createResponse('1.0 200 OK'));
        }

        $connection = new Connection($sid, 'localhost', 9999, $browser);

        if ($correct) {
            $browser->getListener()->getJournal()->clear();
        }

        return $connection;
    }