From 9af9cf4f6b71d052d2b3117efab2a06fe7a10c2c Mon Sep 17 00:00:00 2001 From: Tim Date: Sat, 10 Oct 2015 17:31:05 +0100 Subject: [PATCH] PSR-4 support for #70 plus PhpDoc --- Example.php => Examples/Example.php | 4 +- RconExample.php => Examples/RconExample.php | 4 +- View.php => Examples/View.php | 6 ++- SourceQuery/{Buffer.class.php => Buffer.php} | 21 ++++++-- .../Exception/AuthenticationException.php | 19 ++++++++ .../Exception/InvalidArgumentException.php | 18 +++++++ .../Exception/InvalidPacketException.php | 21 ++++++++ SourceQuery/Exception/SocketException.php | 18 +++++++ .../Exception/SourceQueryException.php | 18 +++++++ SourceQuery/Exception/TimeoutException.php | 18 +++++++ SourceQuery/Exceptions.class.php | 43 ----------------- ...ourceRcon.class.php => GoldSourceRcon.php} | 28 ++++++++--- SourceQuery/{Socket.class.php => Socket.php} | 28 ++++++++--- ...{SourceQuery.class.php => SourceQuery.php} | 48 +++++++++++-------- .../{SourceRcon.class.php => SourceRcon.php} | 29 ++++++++--- SourceQuery/bootstrap.php | 27 +++++++++++ composer.json | 7 ++- 17 files changed, 259 insertions(+), 98 deletions(-) rename Example.php => Examples/Example.php (87%) rename RconExample.php => Examples/RconExample.php (87%) rename View.php => Examples/View.php (97%) rename SourceQuery/{Buffer.class.php => Buffer.php} (88%) create mode 100644 SourceQuery/Exception/AuthenticationException.php create mode 100644 SourceQuery/Exception/InvalidArgumentException.php create mode 100644 SourceQuery/Exception/InvalidPacketException.php create mode 100644 SourceQuery/Exception/SocketException.php create mode 100644 SourceQuery/Exception/SourceQueryException.php create mode 100644 SourceQuery/Exception/TimeoutException.php delete mode 100644 SourceQuery/Exceptions.class.php rename SourceQuery/{GoldSourceRcon.class.php => GoldSourceRcon.php} (85%) rename SourceQuery/{Socket.class.php => Socket.php} (87%) rename SourceQuery/{SourceQuery.class.php => SourceQuery.php} (93%) rename SourceQuery/{SourceRcon.class.php => SourceRcon.php} (89%) create mode 100644 SourceQuery/bootstrap.php diff --git a/Example.php b/Examples/Example.php similarity index 87% rename from Example.php rename to Examples/Example.php index 4f51c10..1064bd2 100644 --- a/Example.php +++ b/Examples/Example.php @@ -1,5 +1,7 @@ define( 'SQ_SERVER_ADDR', 'localhost' ); @@ -56,7 +58,7 @@ -
+

Source Query PHP Class

diff --git a/SourceQuery/Buffer.class.php b/SourceQuery/Buffer.php similarity index 88% rename from SourceQuery/Buffer.class.php rename to SourceQuery/Buffer.php index ac1c3b1..6c4188a 100644 --- a/SourceQuery/Buffer.class.php +++ b/SourceQuery/Buffer.php @@ -1,12 +1,23 @@ * - * Website: https://xpaw.me - * GitHub: https://github.com/xPaw/PHP-Source-Query-Class + * @link https://xpaw.me + * @link https://github.com/xPaw/PHP-Source-Query-Class + * + * @license GNU Lesser General Public License, version 2.1 + * + * @internal + */ + + namespace xPaw\SourceQuery; + + /** + * Class Buffer + * + * @package xPaw\SourceQuery */ - - class SourceQueryBuffer + class Buffer { /** * Buffer diff --git a/SourceQuery/Exception/AuthenticationException.php b/SourceQuery/Exception/AuthenticationException.php new file mode 100644 index 0000000..ff0b2a1 --- /dev/null +++ b/SourceQuery/Exception/AuthenticationException.php @@ -0,0 +1,19 @@ + + * + * @link https://xpaw.me + * @link https://github.com/xPaw/PHP-Source-Query-Class + * + * @license GNU Lesser General Public License, version 2.1 + * + * @internal + */ + + namespace xPaw\SourceQuery\Exception; + + class AuthenticationException extends SourceQueryException + { + const BAD_PASSWORD = 1; + const BANNED = 2; + } diff --git a/SourceQuery/Exception/InvalidArgumentException.php b/SourceQuery/Exception/InvalidArgumentException.php new file mode 100644 index 0000000..5bf6288 --- /dev/null +++ b/SourceQuery/Exception/InvalidArgumentException.php @@ -0,0 +1,18 @@ + + * + * @link https://xpaw.me + * @link https://github.com/xPaw/PHP-Source-Query-Class + * + * @license GNU Lesser General Public License, version 2.1 + * + * @internal + */ + + namespace xPaw\SourceQuery\Exception; + + class InvalidArgumentException extends SourceQueryException + { + const TIMEOUT_NOT_INTEGER = 1; + } diff --git a/SourceQuery/Exception/InvalidPacketException.php b/SourceQuery/Exception/InvalidPacketException.php new file mode 100644 index 0000000..5acde62 --- /dev/null +++ b/SourceQuery/Exception/InvalidPacketException.php @@ -0,0 +1,21 @@ + + * + * @link https://xpaw.me + * @link https://github.com/xPaw/PHP-Source-Query-Class + * + * @license GNU Lesser General Public License, version 2.1 + * + * @internal + */ + + namespace xPaw\SourceQuery\Exception; + + class InvalidPacketException extends SourceQueryException + { + const PACKET_HEADER_MISMATCH = 1; + const BUFFER_EMPTY = 2; + const BUFFER_NOT_EMPTY = 3; + const CHECKSUM_MISMATCH = 4; + } diff --git a/SourceQuery/Exception/SocketException.php b/SourceQuery/Exception/SocketException.php new file mode 100644 index 0000000..3afa954 --- /dev/null +++ b/SourceQuery/Exception/SocketException.php @@ -0,0 +1,18 @@ + + * + * @link https://xpaw.me + * @link https://github.com/xPaw/PHP-Source-Query-Class + * + * @license GNU Lesser General Public License, version 2.1 + * + * @internal + */ + + namespace xPaw\SourceQuery\Exception; + + class SocketException extends SourceQueryException + { + const COULD_NOT_CREATE_SOCKET = 1; + } diff --git a/SourceQuery/Exception/SourceQueryException.php b/SourceQuery/Exception/SourceQueryException.php new file mode 100644 index 0000000..cc16b7b --- /dev/null +++ b/SourceQuery/Exception/SourceQueryException.php @@ -0,0 +1,18 @@ + + * + * @link https://xpaw.me + * @link https://github.com/xPaw/PHP-Source-Query-Class + * + * @license GNU Lesser General Public License, version 2.1 + * + * @internal + */ + + namespace xPaw\SourceQuery\Exception; + + abstract class SourceQueryException extends \Exception + { + // Base exception class + } diff --git a/SourceQuery/Exception/TimeoutException.php b/SourceQuery/Exception/TimeoutException.php new file mode 100644 index 0000000..ec93fb4 --- /dev/null +++ b/SourceQuery/Exception/TimeoutException.php @@ -0,0 +1,18 @@ + + * + * @link https://xpaw.me + * @link https://github.com/xPaw/PHP-Source-Query-Class + * + * @license GNU Lesser General Public License, version 2.1 + * + * @internal + */ + + namespace xPaw\SourceQuery\Exception; + + class TimeoutException extends SourceQueryException + { + const TIMEOUT_CONNECT = 1; + } diff --git a/SourceQuery/Exceptions.class.php b/SourceQuery/Exceptions.class.php deleted file mode 100644 index a9d4377..0000000 --- a/SourceQuery/Exceptions.class.php +++ /dev/null @@ -1,43 +0,0 @@ - * - * Website: https://xpaw.me - * GitHub: https://github.com/xPaw/PHP-Source-Query-Class + * @link https://xpaw.me + * @link https://github.com/xPaw/PHP-Source-Query-Class + * + * @license GNU Lesser General Public License, version 2.1 + * + * @internal */ + + namespace xPaw\SourceQuery; use xPaw\SourceQuery\Exception\AuthenticationException; - - class SourceQueryGoldSourceRcon + + /** + * Class GoldSourceRcon + * + * @package xPaw\SourceQuery + * + * @uses xPaw\SourceQuery\Exception\AuthenticationException + */ + class GoldSourceRcon { /** * Points to buffer class * - * @var SourceQueryBuffer + * @var Buffer */ private $Buffer; /** * Points to socket class * - * @var SourceQuerySocket + * @var Socket */ private $Socket; @@ -57,6 +70,7 @@ /** * @param int $Length * @throws AuthenticationException + * @return bool */ public function Read( $Length = 1400 ) { diff --git a/SourceQuery/Socket.class.php b/SourceQuery/Socket.php similarity index 87% rename from SourceQuery/Socket.class.php rename to SourceQuery/Socket.php index 41bb7a5..6599b13 100644 --- a/SourceQuery/Socket.class.php +++ b/SourceQuery/Socket.php @@ -1,15 +1,29 @@ * - * Website: https://xpaw.me - * GitHub: https://github.com/xPaw/PHP-Source-Query-Class + * @link https://xpaw.me + * @link https://github.com/xPaw/PHP-Source-Query-Class + * + * @license GNU Lesser General Public License, version 2.1 + * + * @internal */ + + namespace xPaw\SourceQuery; use xPaw\SourceQuery\Exception\InvalidPacketException; use xPaw\SourceQuery\Exception\SocketException; - - class SourceQuerySocket + + /** + * Class Socket + * + * @package xPaw\SourceQuery + * + * @uses xPaw\SourceQuery\Exception\InvalidPacketException + * @uses xPaw\SourceQuery\Exception\SocketException + */ + class Socket { public $Socket; public $Engine; @@ -21,7 +35,7 @@ /** * Points to buffer class * - * @var SourceQueryBuffer + * @var Buffer */ private $Buffer; @@ -144,7 +158,7 @@ // Let's make sure this function exists, it's not included in PHP by default if( !Function_Exists( 'bzdecompress' ) ) { - throw new RuntimeException( 'Received compressed packet, PHP doesn\'t have Bzip2 library installed, can\'t decompress.' ); + throw new \RuntimeException( 'Received compressed packet, PHP doesn\'t have Bzip2 library installed, can\'t decompress.' ); } $Buffer = bzdecompress( $Buffer ); diff --git a/SourceQuery/SourceQuery.class.php b/SourceQuery/SourceQuery.php similarity index 93% rename from SourceQuery/SourceQuery.class.php rename to SourceQuery/SourceQuery.php index 1fc2bab..0c0e94b 100644 --- a/SourceQuery/SourceQuery.class.php +++ b/SourceQuery/SourceQuery.php @@ -1,30 +1,36 @@ * - * Special thanks to koraktor for his awesome Steam Condenser class, - * I used it as a reference at some points. + * @link https://xpaw.me + * @link https://github.com/xPaw/PHP-Source-Query-Class + * + * @license GNU Lesser General Public License, version 2.1 */ - - require __DIR__ . '/Exceptions.class.php'; - require __DIR__ . '/Buffer.class.php'; - require __DIR__ . '/Socket.class.php'; - require __DIR__ . '/SourceRcon.class.php'; - require __DIR__ . '/GoldSourceRcon.class.php'; - + + namespace xPaw\SourceQuery; + use xPaw\SourceQuery\Exception\InvalidArgumentException; use xPaw\SourceQuery\Exception\TimeoutException; use xPaw\SourceQuery\Exception\InvalidPacketException; - + + /** + * Class SourceQuery + * + * @package xPaw\SourceQuery + * + * @uses xPaw\SourceQuery\Exception\InvalidArgumentException + * @uses xPaw\SourceQuery\Exception\TimeoutException + * @uses xPaw\SourceQuery\Exception\InvalidPacketException + */ class SourceQuery { /** * Values returned by GetChallenge() * - * TODO: Get rid of this? Improve? Do something else? + * @todo Get rid of this? Improve? Do something else? */ const GETCHALLENGE_FAILED = 0; const GETCHALLENGE_ALL_CLEAR = 1; @@ -71,21 +77,21 @@ /** * Points to rcon class * - * @var SourceQueryRcon + * @var SourceRcon */ private $Rcon; /** * Points to buffer class * - * @var SourceQueryBuffer + * @var Buffer */ private $Buffer; /** * Points to socket class * - * @var SourceQuerySocket + * @var Socket */ private $Socket; @@ -112,8 +118,8 @@ public function __construct( ) { - $this->Buffer = new SourceQueryBuffer( ); - $this->Socket = new SourceQuerySocket( $this->Buffer ); + $this->Buffer = new Buffer( ); + $this->Socket = new Socket( $this->Buffer ); } public function __destruct( ) @@ -530,13 +536,13 @@ { case SourceQuery :: GOLDSOURCE: { - $this->Rcon = new SourceQueryGoldSourceRcon( $this->Buffer, $this->Socket ); + $this->Rcon = new GoldSourceRcon( $this->Buffer, $this->Socket ); break; } case SourceQuery :: SOURCE: { - $this->Rcon = new SourceQuerySourceRcon( $this->Buffer, $this->Socket ); + $this->Rcon = new SourceRcon( $this->Buffer, $this->Socket ); break; } diff --git a/SourceQuery/SourceRcon.class.php b/SourceQuery/SourceRcon.php similarity index 89% rename from SourceQuery/SourceRcon.class.php rename to SourceQuery/SourceRcon.php index c2fc518..7e6e03f 100644 --- a/SourceQuery/SourceRcon.class.php +++ b/SourceQuery/SourceRcon.php @@ -1,28 +1,43 @@ * - * Website: https://xpaw.me - * GitHub: https://github.com/xPaw/PHP-Source-Query-Class + * @link https://xpaw.me + * @link https://github.com/xPaw/PHP-Source-Query-Class + * + * @license GNU Lesser General Public License, version 2.1 + * + * @internal */ + + namespace xPaw\SourceQuery; use xPaw\SourceQuery\Exception\AuthenticationException; use xPaw\SourceQuery\Exception\TimeoutException; use xPaw\SourceQuery\Exception\InvalidPacketException; - - class SourceQuerySourceRcon + + /** + * Class SourceRcon + * + * @package xPaw\SourceQuery + * + * @uses xPaw\SourceQuery\Exception\AuthenticationException + * @uses xPaw\SourceQuery\Exception\TimeoutException + * @uses xPaw\SourceQuery\Exception\InvalidPacketException + */ + class SourceRcon { /** * Points to buffer class * - * @var SourceQueryBuffer + * @var Buffer */ private $Buffer; /** * Points to socket class * - * @var SourceQuerySocket + * @var Socket */ private $Socket; diff --git a/SourceQuery/bootstrap.php b/SourceQuery/bootstrap.php new file mode 100644 index 0000000..63885d7 --- /dev/null +++ b/SourceQuery/bootstrap.php @@ -0,0 +1,27 @@ + + * + * @link https://xpaw.me + * @link https://github.com/xPaw/PHP-Source-Query-Class + * + * @license GNU Lesser General Public License, version 2.1 + */ + + require_once __DIR__ . '/Exception/SourceQueryException.php'; + require_once __DIR__ . '/Exception/AuthenticationException.php'; + require_once __DIR__ . '/Exception/InvalidArgumentException.php'; + require_once __DIR__ . '/Exception/SocketException.php'; + require_once __DIR__ . '/Exception/InvalidPacketException.php'; + require_once __DIR__ . '/Exception/TimeoutException.php'; + + require_once __DIR__ . '/Buffer.php'; + require_once __DIR__ . '/Socket.php'; + require_once __DIR__ . '/SourceRcon.php'; + require_once __DIR__ . '/GoldSourceRcon.php'; + require_once __DIR__ . '/SourceQuery.php'; diff --git a/composer.json b/composer.json index 4496722..f893033 100644 --- a/composer.json +++ b/composer.json @@ -17,9 +17,8 @@ }, "autoload": { - "files": - [ - "SourceQuery/SourceQuery.class.php" - ] + "psr-4": { + "xPaw\\SourceQuery\\": "SourceQuery/" + } } }