From 5320efe4e7941a831d88ebc4df5f6e95575ceed6 Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Sun, 4 Sep 2011 12:11:24 -0400 Subject: [PATCH] File structure set, Hiby10 token handshake complete and unit tested --- README.md | 0 lib/Ratchet/Client.php | 0 lib/Ratchet/Exception.php | 5 + lib/Ratchet/Protocol/WebSocket/Adapter.php | 12 ++ .../Protocol/WebSocket/Version/Hixie76.php | 5 + .../Protocol/WebSocket/Version/Hybi10.php | 10 ++ .../WebSocket/Version/VersionInterface.php | 10 ++ lib/Ratchet/Server.php | 8 + lib/Ratchet/Socket.php | 17 +++ phpunit.xml.dist | 17 +++ .../Protocol/WebSocket/Version/Hybi10Test.php | 33 +++++ tests/SplClassLoader.php | 139 ++++++++++++++++++ tests/bootstrap.php | 5 + 13 files changed, 261 insertions(+) create mode 100644 README.md create mode 100644 lib/Ratchet/Client.php create mode 100644 lib/Ratchet/Exception.php create mode 100644 lib/Ratchet/Protocol/WebSocket/Adapter.php create mode 100644 lib/Ratchet/Protocol/WebSocket/Version/Hixie76.php create mode 100644 lib/Ratchet/Protocol/WebSocket/Version/Hybi10.php create mode 100644 lib/Ratchet/Protocol/WebSocket/Version/VersionInterface.php create mode 100644 lib/Ratchet/Server.php create mode 100644 lib/Ratchet/Socket.php create mode 100644 phpunit.xml.dist create mode 100644 tests/Ratchet/Tests/Protocol/WebSocket/Version/Hybi10Test.php create mode 100644 tests/SplClassLoader.php create mode 100644 tests/bootstrap.php diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/lib/Ratchet/Client.php b/lib/Ratchet/Client.php new file mode 100644 index 0000000..e69de29 diff --git a/lib/Ratchet/Exception.php b/lib/Ratchet/Exception.php new file mode 100644 index 0000000..a6b7e27 --- /dev/null +++ b/lib/Ratchet/Exception.php @@ -0,0 +1,5 @@ +_socket = socket_open(); + } + + public function __call($method, $arguments) { + if (function_exists('socket_' . $method)) { + array_unshift($arguments, $this->_socket); + return call_user_func_array('socket_' . $method, $arguments); + } + } +} \ No newline at end of file diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..de09a7b --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,17 @@ + + + + + + ./tests/Ratchet/ + + + \ No newline at end of file diff --git a/tests/Ratchet/Tests/Protocol/WebSocket/Version/Hybi10Test.php b/tests/Ratchet/Tests/Protocol/WebSocket/Version/Hybi10Test.php new file mode 100644 index 0000000..2d4a8e1 --- /dev/null +++ b/tests/Ratchet/Tests/Protocol/WebSocket/Version/Hybi10Test.php @@ -0,0 +1,33 @@ +_version = new Hybi10(); + } + + public function testClassImplementsVersionInterface() { + $constraint = $this->isInstanceOf('\\Ratchet\\Protocol\\WebSocket\\Version\\VersionInterface'); + $this->assertThat($this->_version, $constraint); + } + + /** + * @dataProvider HandshakeProvider + */ + public function testKeySigningForHandshake($key, $accept) { + $this->assertEquals($accept, $this->_version->sign($key)); + } + + public static function HandshakeProvider() { + return Array( + Array('x3JJHMbDL1EzLkh9GBhXDw==', 'HSmrc0sMlYUkAGmm5OPpG2HaGWk=') + , Array('dGhlIHNhbXBsZSBub25jZQ==', 's3pPLMBiTxaQ9kYGzzhZRbK+xOo=') + ); + } +} \ No newline at end of file diff --git a/tests/SplClassLoader.php b/tests/SplClassLoader.php new file mode 100644 index 0000000..4cba7a3 --- /dev/null +++ b/tests/SplClassLoader.php @@ -0,0 +1,139 @@ +register(); + * + * @author Jonathan H. Wage + * @author Roman S. Borschel + * @author Matthew Weier O'Phinney + * @author Kris Wallsmith + * @author Fabien Potencier + */ +class SplClassLoader +{ + private $_fileExtension = '.php'; + private $_namespace; + private $_includePath; + private $_namespaceSeparator = '\\'; + + /** + * Creates a new SplClassLoader that loads classes of the + * specified namespace. + * + * @param string $ns The namespace to use. + */ + public function __construct($ns = null, $includePath = null) + { + $this->_namespace = $ns; + $this->_includePath = $includePath; + } + + /** + * Sets the namespace separator used by classes in the namespace of this class loader. + * + * @param string $sep The separator to use. + */ + public function setNamespaceSeparator($sep) + { + $this->_namespaceSeparator = $sep; + } + + /** + * Gets the namespace seperator used by classes in the namespace of this class loader. + * + * @return void + */ + public function getNamespaceSeparator() + { + return $this->_namespaceSeparator; + } + + /** + * Sets the base include path for all class files in the namespace of this class loader. + * + * @param string $includePath + */ + public function setIncludePath($includePath) + { + $this->_includePath = $includePath; + } + + /** + * Gets the base include path for all class files in the namespace of this class loader. + * + * @return string $includePath + */ + public function getIncludePath() + { + return $this->_includePath; + } + + /** + * Sets the file extension of class files in the namespace of this class loader. + * + * @param string $fileExtension + */ + public function setFileExtension($fileExtension) + { + $this->_fileExtension = $fileExtension; + } + + /** + * Gets the file extension of class files in the namespace of this class loader. + * + * @return string $fileExtension + */ + public function getFileExtension() + { + return $this->_fileExtension; + } + + /** + * Installs this class loader on the SPL autoload stack. + */ + public function register() + { + spl_autoload_register(array($this, 'loadClass')); + } + + /** + * Uninstalls this class loader from the SPL autoloader stack. + */ + public function unregister() + { + spl_autoload_unregister(array($this, 'loadClass')); + } + + /** + * Loads the given class or interface. + * + * @param string $className The name of the class to load. + * @return void + */ + public function loadClass($className) + { + if (null === $this->_namespace || $this->_namespace.$this->_namespaceSeparator === substr($className, 0, strlen($this->_namespace.$this->_namespaceSeparator))) { + $fileName = ''; + $namespace = ''; + if (false !== ($lastNsPos = strripos($className, $this->_namespaceSeparator))) { + $namespace = substr($className, 0, $lastNsPos); + $className = substr($className, $lastNsPos + 1); + $fileName = str_replace($this->_namespaceSeparator, DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; + } + $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . $this->_fileExtension; + $filePath = ($this->_includePath !== null ? $this->_includePath . DIRECTORY_SEPARATOR : '') . $fileName; + + if (is_file($filePath)) { + require $filePath; + } + } + } +} \ No newline at end of file diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..a8909cb --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,5 @@ +register(); \ No newline at end of file