aboutsummaryrefslogtreecommitdiffhomepage
path: root/assets/php/vendor/cboden/ratchet/src/Ratchet/Session
diff options
context:
space:
mode:
authormarvin-borner@live.com2018-04-10 21:50:16 +0200
committermarvin-borner@live.com2018-04-10 21:54:48 +0200
commitfc9401f04a3aca5abb22f87ebc210de8afe11d32 (patch)
treeb0b310f3581764ec3955f4e496a05137a32951c3 /assets/php/vendor/cboden/ratchet/src/Ratchet/Session
parent286d643180672f20526f3dc3bd19d7b751e2fa97 (diff)
Initial Commit
Diffstat (limited to 'assets/php/vendor/cboden/ratchet/src/Ratchet/Session')
-rw-r--r--assets/php/vendor/cboden/ratchet/src/Ratchet/Session/Serialize/HandlerInterface.php16
-rw-r--r--assets/php/vendor/cboden/ratchet/src/Ratchet/Session/Serialize/PhpBinaryHandler.php33
-rw-r--r--assets/php/vendor/cboden/ratchet/src/Ratchet/Session/Serialize/PhpHandler.php49
-rw-r--r--assets/php/vendor/cboden/ratchet/src/Ratchet/Session/SessionProvider.php243
-rw-r--r--assets/php/vendor/cboden/ratchet/src/Ratchet/Session/Storage/Proxy/VirtualProxy.php54
-rw-r--r--assets/php/vendor/cboden/ratchet/src/Ratchet/Session/Storage/VirtualSessionStorage.php88
6 files changed, 483 insertions, 0 deletions
diff --git a/assets/php/vendor/cboden/ratchet/src/Ratchet/Session/Serialize/HandlerInterface.php b/assets/php/vendor/cboden/ratchet/src/Ratchet/Session/Serialize/HandlerInterface.php
new file mode 100644
index 0000000..b83635f
--- /dev/null
+++ b/assets/php/vendor/cboden/ratchet/src/Ratchet/Session/Serialize/HandlerInterface.php
@@ -0,0 +1,16 @@
+<?php
+namespace Ratchet\Session\Serialize;
+
+interface HandlerInterface {
+ /**
+ * @param array
+ * @return string
+ */
+ function serialize(array $data);
+
+ /**
+ * @param string
+ * @return array
+ */
+ function unserialize($raw);
+}
diff --git a/assets/php/vendor/cboden/ratchet/src/Ratchet/Session/Serialize/PhpBinaryHandler.php b/assets/php/vendor/cboden/ratchet/src/Ratchet/Session/Serialize/PhpBinaryHandler.php
new file mode 100644
index 0000000..ba80551
--- /dev/null
+++ b/assets/php/vendor/cboden/ratchet/src/Ratchet/Session/Serialize/PhpBinaryHandler.php
@@ -0,0 +1,33 @@
+<?php
+namespace Ratchet\Session\Serialize;
+
+class PhpBinaryHandler implements HandlerInterface {
+ /**
+ * {@inheritdoc}
+ */
+ function serialize(array $data) {
+ throw new \RuntimeException("Serialize PhpHandler:serialize code not written yet, write me!");
+ }
+
+ /**
+ * {@inheritdoc}
+ * @link http://ca2.php.net/manual/en/function.session-decode.php#108037 Code from this comment on php.net
+ */
+ public function unserialize($raw) {
+ $returnData = array();
+ $offset = 0;
+
+ while ($offset < strlen($raw)) {
+ $num = ord($raw[$offset]);
+ $offset += 1;
+ $varname = substr($raw, $offset, $num);
+ $offset += $num;
+ $data = unserialize(substr($raw, $offset));
+
+ $returnData[$varname] = $data;
+ $offset += strlen(serialize($data));
+ }
+
+ return $returnData;
+ }
+}
diff --git a/assets/php/vendor/cboden/ratchet/src/Ratchet/Session/Serialize/PhpHandler.php b/assets/php/vendor/cboden/ratchet/src/Ratchet/Session/Serialize/PhpHandler.php
new file mode 100644
index 0000000..b1df356
--- /dev/null
+++ b/assets/php/vendor/cboden/ratchet/src/Ratchet/Session/Serialize/PhpHandler.php
@@ -0,0 +1,49 @@
+<?php
+namespace Ratchet\Session\Serialize;
+
+class PhpHandler implements HandlerInterface {
+ /**
+ * Simply reverse behaviour of unserialize method.
+ * {@inheritdoc}
+ */
+ function serialize(array $data) {
+ $preSerialized = array();
+ $serialized = '';
+
+ if (count($data)) {
+ foreach ($data as $bucket => $bucketData) {
+ $preSerialized[] = $bucket . '|' . serialize($bucketData);
+ }
+ $serialized = implode('', $preSerialized);
+ }
+
+ return $serialized;
+ }
+
+ /**
+ * {@inheritdoc}
+ * @link http://ca2.php.net/manual/en/function.session-decode.php#108037 Code from this comment on php.net
+ * @throws \UnexpectedValueException If there is a problem parsing the data
+ */
+ public function unserialize($raw) {
+ $returnData = array();
+ $offset = 0;
+
+ while ($offset < strlen($raw)) {
+ if (!strstr(substr($raw, $offset), "|")) {
+ throw new \UnexpectedValueException("invalid data, remaining: " . substr($raw, $offset));
+ }
+
+ $pos = strpos($raw, "|", $offset);
+ $num = $pos - $offset;
+ $varname = substr($raw, $offset, $num);
+ $offset += $num + 1;
+ $data = unserialize(substr($raw, $offset));
+
+ $returnData[$varname] = $data;
+ $offset += strlen(serialize($data));
+ }
+
+ return $returnData;
+ }
+}
diff --git a/assets/php/vendor/cboden/ratchet/src/Ratchet/Session/SessionProvider.php b/assets/php/vendor/cboden/ratchet/src/Ratchet/Session/SessionProvider.php
new file mode 100644
index 0000000..44276c5
--- /dev/null
+++ b/assets/php/vendor/cboden/ratchet/src/Ratchet/Session/SessionProvider.php
@@ -0,0 +1,243 @@
+<?php
+namespace Ratchet\Session;
+use Ratchet\ConnectionInterface;
+use Ratchet\Http\HttpServerInterface;
+use Psr\Http\Message\RequestInterface;
+use Ratchet\Session\Storage\VirtualSessionStorage;
+use Ratchet\Session\Serialize\HandlerInterface;
+use Symfony\Component\HttpFoundation\Session\Session;
+use Symfony\Component\HttpFoundation\Session\Storage\Handler\NullSessionHandler;
+
+/**
+ * This component will allow access to session data from your website for each user connected
+ * Symfony HttpFoundation is required for this component to work
+ * Your website must also use Symfony HttpFoundation Sessions to read your sites session data
+ * If your are not using at least PHP 5.4 you must include a SessionHandlerInterface stub (is included in Symfony HttpFoundation, loaded w/ composer)
+ */
+class SessionProvider implements HttpServerInterface {
+ /**
+ * @var \Ratchet\MessageComponentInterface
+ */
+ protected $_app;
+
+ /**
+ * Selected handler storage assigned by the developer
+ * @var \SessionHandlerInterface
+ */
+ protected $_handler;
+
+ /**
+ * Null storage handler if no previous session was found
+ * @var \SessionHandlerInterface
+ */
+ protected $_null;
+
+ /**
+ * @var \Ratchet\Session\Serialize\HandlerInterface
+ */
+ protected $_serializer;
+
+ /**
+ * @param \Ratchet\Http\HttpServerInterface $app
+ * @param \SessionHandlerInterface $handler
+ * @param array $options
+ * @param \Ratchet\Session\Serialize\HandlerInterface $serializer
+ * @throws \RuntimeException
+ */
+ public function __construct(HttpServerInterface $app, \SessionHandlerInterface $handler, array $options = array(), HandlerInterface $serializer = null) {
+ $this->_app = $app;
+ $this->_handler = $handler;
+ $this->_null = new NullSessionHandler;
+
+ ini_set('session.auto_start', 0);
+ ini_set('session.cache_limiter', '');
+ ini_set('session.use_cookies', 0);
+
+ $this->setOptions($options);
+
+ if (null === $serializer) {
+ $serialClass = __NAMESPACE__ . "\\Serialize\\{$this->toClassCase(ini_get('session.serialize_handler'))}Handler"; // awesome/terrible hack, eh?
+ if (!class_exists($serialClass)) {
+ throw new \RuntimeException('Unable to parse session serialize handler');
+ }
+
+ $serializer = new $serialClass;
+ }
+
+ $this->_serializer = $serializer;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function onOpen(ConnectionInterface $conn, RequestInterface $request = null) {
+ $sessionName = ini_get('session.name');
+
+ $id = array_reduce($request->getHeader('Cookie'), function($accumulator, $cookie) use ($sessionName) {
+ if ($accumulator) {
+ return $accumulator;
+ }
+
+ $crumbs = $this->parseCookie($cookie);
+
+ return isset($crumbs['cookies'][$sessionName]) ? $crumbs['cookies'][$sessionName] : false;
+ }, false);
+
+ if (null === $request || false === $id) {
+ $saveHandler = $this->_null;
+ $id = '';
+ } else {
+ $saveHandler = $this->_handler;
+ }
+
+ $conn->Session = new Session(new VirtualSessionStorage($saveHandler, $id, $this->_serializer));
+
+ if (ini_get('session.auto_start')) {
+ $conn->Session->start();
+ }
+
+ return $this->_app->onOpen($conn, $request);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ function onMessage(ConnectionInterface $from, $msg) {
+ return $this->_app->onMessage($from, $msg);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ function onClose(ConnectionInterface $conn) {
+ // "close" session for Connection
+
+ return $this->_app->onClose($conn);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ function onError(ConnectionInterface $conn, \Exception $e) {
+ return $this->_app->onError($conn, $e);
+ }
+
+ /**
+ * Set all the php session. ini options
+ * © Symfony
+ * @param array $options
+ * @return array
+ */
+ protected function setOptions(array $options) {
+ $all = array(
+ 'auto_start', 'cache_limiter', 'cookie_domain', 'cookie_httponly',
+ 'cookie_lifetime', 'cookie_path', 'cookie_secure',
+ 'entropy_file', 'entropy_length', 'gc_divisor',
+ 'gc_maxlifetime', 'gc_probability', 'hash_bits_per_character',
+ 'hash_function', 'name', 'referer_check',
+ 'serialize_handler', 'use_cookies',
+ 'use_only_cookies', 'use_trans_sid', 'upload_progress.enabled',
+ 'upload_progress.cleanup', 'upload_progress.prefix', 'upload_progress.name',
+ 'upload_progress.freq', 'upload_progress.min-freq', 'url_rewriter.tags'
+ );
+
+ foreach ($all as $key) {
+ if (!array_key_exists($key, $options)) {
+ $options[$key] = ini_get("session.{$key}");
+ } else {
+ ini_set("session.{$key}", $options[$key]);
+ }
+ }
+
+ return $options;
+ }
+
+ /**
+ * @param string $langDef Input to convert
+ * @return string
+ */
+ protected function toClassCase($langDef) {
+ return str_replace(' ', '', ucwords(str_replace('_', ' ', $langDef)));
+ }
+
+ /**
+ * Taken from Guzzle3
+ */
+ private static $cookieParts = array(
+ 'domain' => 'Domain',
+ 'path' => 'Path',
+ 'max_age' => 'Max-Age',
+ 'expires' => 'Expires',
+ 'version' => 'Version',
+ 'secure' => 'Secure',
+ 'port' => 'Port',
+ 'discard' => 'Discard',
+ 'comment' => 'Comment',
+ 'comment_url' => 'Comment-Url',
+ 'http_only' => 'HttpOnly'
+ );
+
+ /**
+ * Taken from Guzzle3
+ */
+ private function parseCookie($cookie, $host = null, $path = null, $decode = false) {
+ // Explode the cookie string using a series of semicolons
+ $pieces = array_filter(array_map('trim', explode(';', $cookie)));
+
+ // The name of the cookie (first kvp) must include an equal sign.
+ if (empty($pieces) || !strpos($pieces[0], '=')) {
+ return false;
+ }
+
+ // Create the default return array
+ $data = array_merge(array_fill_keys(array_keys(self::$cookieParts), null), array(
+ 'cookies' => array(),
+ 'data' => array(),
+ 'path' => $path ?: '/',
+ 'http_only' => false,
+ 'discard' => false,
+ 'domain' => $host
+ ));
+ $foundNonCookies = 0;
+
+ // Add the cookie pieces into the parsed data array
+ foreach ($pieces as $part) {
+
+ $cookieParts = explode('=', $part, 2);
+ $key = trim($cookieParts[0]);
+
+ if (count($cookieParts) == 1) {
+ // Can be a single value (e.g. secure, httpOnly)
+ $value = true;
+ } else {
+ // Be sure to strip wrapping quotes
+ $value = trim($cookieParts[1], " \n\r\t\0\x0B\"");
+ if ($decode) {
+ $value = urldecode($value);
+ }
+ }
+
+ // Only check for non-cookies when cookies have been found
+ if (!empty($data['cookies'])) {
+ foreach (self::$cookieParts as $mapValue => $search) {
+ if (!strcasecmp($search, $key)) {
+ $data[$mapValue] = $mapValue == 'port' ? array_map('trim', explode(',', $value)) : $value;
+ $foundNonCookies++;
+ continue 2;
+ }
+ }
+ }
+
+ // If cookies have not yet been retrieved, or this value was not found in the pieces array, treat it as a
+ // cookie. IF non-cookies have been parsed, then this isn't a cookie, it's cookie data. Cookies then data.
+ $data[$foundNonCookies ? 'data' : 'cookies'][$key] = $value;
+ }
+
+ // Calculate the expires date
+ if (!$data['expires'] && $data['max_age']) {
+ $data['expires'] = time() + (int) $data['max_age'];
+ }
+
+ return $data;
+ }
+}
diff --git a/assets/php/vendor/cboden/ratchet/src/Ratchet/Session/Storage/Proxy/VirtualProxy.php b/assets/php/vendor/cboden/ratchet/src/Ratchet/Session/Storage/Proxy/VirtualProxy.php
new file mode 100644
index 0000000..b478d03
--- /dev/null
+++ b/assets/php/vendor/cboden/ratchet/src/Ratchet/Session/Storage/Proxy/VirtualProxy.php
@@ -0,0 +1,54 @@
+<?php
+namespace Ratchet\Session\Storage\Proxy;
+use Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy;
+
+class VirtualProxy extends SessionHandlerProxy {
+ /**
+ * @var string
+ */
+ protected $_sessionId;
+
+ /**
+ * @var string
+ */
+ protected $_sessionName;
+
+ /**
+ * {@inheritdoc}
+ */
+ public function __construct(\SessionHandlerInterface $handler) {
+ parent::__construct($handler);
+
+ $this->saveHandlerName = 'user';
+ $this->_sessionName = ini_get('session.name');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getId() {
+ return $this->_sessionId;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setId($id) {
+ $this->_sessionId = $id;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getName() {
+ return $this->_sessionName;
+ }
+
+ /**
+ * DO NOT CALL THIS METHOD
+ * @internal
+ */
+ public function setName($name) {
+ throw new \RuntimeException("Can not change session name in VirtualProxy");
+ }
+}
diff --git a/assets/php/vendor/cboden/ratchet/src/Ratchet/Session/Storage/VirtualSessionStorage.php b/assets/php/vendor/cboden/ratchet/src/Ratchet/Session/Storage/VirtualSessionStorage.php
new file mode 100644
index 0000000..daa10bb
--- /dev/null
+++ b/assets/php/vendor/cboden/ratchet/src/Ratchet/Session/Storage/VirtualSessionStorage.php
@@ -0,0 +1,88 @@
+<?php
+namespace Ratchet\Session\Storage;
+use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
+use Ratchet\Session\Storage\Proxy\VirtualProxy;
+use Ratchet\Session\Serialize\HandlerInterface;
+
+class VirtualSessionStorage extends NativeSessionStorage {
+ /**
+ * @var \Ratchet\Session\Serialize\HandlerInterface
+ */
+ protected $_serializer;
+
+ /**
+ * @param \SessionHandlerInterface $handler
+ * @param string $sessionId The ID of the session to retrieve
+ * @param \Ratchet\Session\Serialize\HandlerInterface $serializer
+ */
+ public function __construct(\SessionHandlerInterface $handler, $sessionId, HandlerInterface $serializer) {
+ $this->setSaveHandler($handler);
+ $this->saveHandler->setId($sessionId);
+ $this->_serializer = $serializer;
+ $this->setMetadataBag(null);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function start() {
+ if ($this->started && !$this->closed) {
+ return true;
+ }
+
+ // You have to call Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler::open() to use
+ // pdo_sqlite (and possible pdo_*) as session storage, if you are using a DSN string instead of a \PDO object
+ // in the constructor. The method arguments are filled with the values, which are also used by the symfony
+ // framework in this case. This must not be the best choice, but it works.
+ $this->saveHandler->open(session_save_path(), session_name());
+
+ $rawData = $this->saveHandler->read($this->saveHandler->getId());
+ $sessionData = $this->_serializer->unserialize($rawData);
+
+ $this->loadSession($sessionData);
+
+ if (!$this->saveHandler->isWrapper() && !$this->saveHandler->isSessionHandlerInterface()) {
+ $this->saveHandler->setActive(false);
+ }
+
+ return true;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function regenerate($destroy = false, $lifetime = null) {
+ // .. ?
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function save() {
+ // get the data from the bags?
+ // serialize the data
+ // save the data using the saveHandler
+// $this->saveHandler->write($this->saveHandler->getId(),
+
+ if (!$this->saveHandler->isWrapper() && !$this->getSaveHandler()->isSessionHandlerInterface()) {
+ $this->saveHandler->setActive(false);
+ }
+
+ $this->closed = true;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setSaveHandler($saveHandler = null) {
+ if (!($saveHandler instanceof \SessionHandlerInterface)) {
+ throw new \InvalidArgumentException('Handler must be instance of SessionHandlerInterface');
+ }
+
+ if (!($saveHandler instanceof VirtualProxy)) {
+ $saveHandler = new VirtualProxy($saveHandler);
+ }
+
+ $this->saveHandler = $saveHandler;
+ }
+}