/** * @param IConfig $config * @param ICrypto $crypto * @param ISecureRandom $random * @param IRequest $request */ public function __construct(IConfig $config, ICrypto $crypto, ISecureRandom $random, IRequest $request) { $this->crypto = $crypto; $this->config = $config; $this->random = $random; if (!is_null($request->getCookie(self::COOKIE_NAME))) { $this->passphrase = $request->getCookie(self::COOKIE_NAME); } else { $this->passphrase = $this->random->getMediumStrengthGenerator()->generate(128); $secureCookie = $request->getServerProtocol() === 'https'; // FIXME: Required for CI if (!defined('PHPUNIT_RUN')) { setcookie(self::COOKIE_NAME, $this->passphrase, 0, \OC::$WEBROOT, '', $secureCookie, true); } } }
/** * Shortcut for getting cookie variables * @deprecated 7.0.0 use $this->request instead * @param string $key the key that will be taken from the $_COOKIE array * @return array the value in the $_COOKIE element * @since 6.0.0 */ public function cookie($key) { return $this->request->getCookie($key); }
protected function supportsCookies(IRequest $request) { if (!is_null($request->getCookie('cookie_test'))) { return true; } setcookie('cookie_test', 'test', $this->timeFacory->getTime() + 3600); return false; }