mirror of
https://github.com/xPaw/PHP-Source-Query.git
synced 2026-05-18 14:33:34 +02:00
Make an abstract class for sockets and allow specifying different socket in SourceQuery
This is a preparation for tests
This commit is contained in:
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Pavel Djundik <sourcequery@xpaw.me>
|
||||||
|
*
|
||||||
|
* @link https://xpaw.me
|
||||||
|
* @link https://github.com/xPaw/PHP-Source-Query
|
||||||
|
*
|
||||||
|
* @license GNU Lesser General Public License, version 2.1
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace xPaw\SourceQuery;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base socket interface
|
||||||
|
*
|
||||||
|
* @package xPaw\SourceQuery
|
||||||
|
*/
|
||||||
|
abstract class BaseSocket
|
||||||
|
{
|
||||||
|
public $Socket;
|
||||||
|
public $Engine;
|
||||||
|
|
||||||
|
public $Ip;
|
||||||
|
public $Port;
|
||||||
|
public $Timeout;
|
||||||
|
|
||||||
|
public function __destruct( )
|
||||||
|
{
|
||||||
|
$this->Close( );
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract public function Close( );
|
||||||
|
abstract public function Open( $Ip, $Port, $Timeout, $Engine );
|
||||||
|
abstract public function Write( $Header, $String = '' );
|
||||||
|
abstract public function Read( $Length = 1400 );
|
||||||
|
}
|
||||||
@@ -23,15 +23,8 @@
|
|||||||
* @uses xPaw\SourceQuery\Exception\InvalidPacketException
|
* @uses xPaw\SourceQuery\Exception\InvalidPacketException
|
||||||
* @uses xPaw\SourceQuery\Exception\SocketException
|
* @uses xPaw\SourceQuery\Exception\SocketException
|
||||||
*/
|
*/
|
||||||
class Socket
|
class Socket extends BaseSocket
|
||||||
{
|
{
|
||||||
public $Socket;
|
|
||||||
public $Engine;
|
|
||||||
|
|
||||||
public $Ip;
|
|
||||||
public $Port;
|
|
||||||
public $Timeout;
|
|
||||||
|
|
||||||
public function Close( )
|
public function Close( )
|
||||||
{
|
{
|
||||||
if( $this->Socket )
|
if( $this->Socket )
|
||||||
|
|||||||
@@ -109,9 +109,9 @@
|
|||||||
*/
|
*/
|
||||||
private $UseOldGetChallengeMethod;
|
private $UseOldGetChallengeMethod;
|
||||||
|
|
||||||
public function __construct( )
|
public function __construct( BaseSocket $Socket = null )
|
||||||
{
|
{
|
||||||
$this->Socket = new Socket( );
|
$this->Socket = $Socket ?: new Socket( );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __destruct( )
|
public function __destruct( )
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
require_once __DIR__ . '/Exception/InvalidPacketException.php';
|
require_once __DIR__ . '/Exception/InvalidPacketException.php';
|
||||||
|
|
||||||
require_once __DIR__ . '/Buffer.php';
|
require_once __DIR__ . '/Buffer.php';
|
||||||
|
require_once __DIR__ . '/BaseSocket.php';
|
||||||
require_once __DIR__ . '/Socket.php';
|
require_once __DIR__ . '/Socket.php';
|
||||||
require_once __DIR__ . '/SourceRcon.php';
|
require_once __DIR__ . '/SourceRcon.php';
|
||||||
require_once __DIR__ . '/GoldSourceRcon.php';
|
require_once __DIR__ . '/GoldSourceRcon.php';
|
||||||
|
|||||||
Reference in New Issue
Block a user