Use compact use statements where possible and removed RuntimeException extensions.
This commit is contained in:
parent
51f97b7a67
commit
50af08e54f
51 changed files with 138 additions and 316 deletions
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
||||||
0.2408.12215
|
0.2408.12316
|
||||||
|
|
|
@ -7,9 +7,7 @@ namespace Index\Bencode;
|
||||||
|
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use Index\IO\GenericStream;
|
use Index\IO\{GenericStream,Stream,TempFileStream};
|
||||||
use Index\IO\Stream;
|
|
||||||
use Index\IO\TempFileStream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides a Bencode serialiser.
|
* Provides a Bencode serialiser.
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
<?php
|
|
||||||
// BeginTransactionFailedException.php
|
|
||||||
// Created: 2021-05-02
|
|
||||||
// Updated: 2021-05-12
|
|
||||||
|
|
||||||
namespace Index\Data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exception to be thrown when transaction start fails.
|
|
||||||
*/
|
|
||||||
class BeginTransactionFailedException extends TransactionException {}
|
|
|
@ -1,11 +0,0 @@
|
||||||
<?php
|
|
||||||
// CommitFailedException.php
|
|
||||||
// Created: 2021-05-02
|
|
||||||
// Updated: 2021-05-12
|
|
||||||
|
|
||||||
namespace Index\Data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exception to be thrown when a transaction commit fails.
|
|
||||||
*/
|
|
||||||
class CommitFailedException extends TransactionException {}
|
|
|
@ -1,11 +0,0 @@
|
||||||
<?php
|
|
||||||
// ConnectionFailedException.php
|
|
||||||
// Created: 2022-01-29
|
|
||||||
// Updated: 2022-02-02
|
|
||||||
|
|
||||||
namespace Index\Data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exception to be thrown when a connection fails.
|
|
||||||
*/
|
|
||||||
class ConnectionFailedException extends DataException {}
|
|
|
@ -1,13 +0,0 @@
|
||||||
<?php
|
|
||||||
// DataException.php
|
|
||||||
// Created: 2021-05-02
|
|
||||||
// Updated: 2024-08-01
|
|
||||||
|
|
||||||
namespace Index\Data;
|
|
||||||
|
|
||||||
use RuntimeException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exception type for the Index\Data namespace.
|
|
||||||
*/
|
|
||||||
class DataException extends RuntimeException {}
|
|
|
@ -1,12 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
// DbTools.php
|
// DbTools.php
|
||||||
// Created: 2021-05-02
|
// Created: 2021-05-02
|
||||||
// Updated: 2024-04-10
|
// Updated: 2024-08-01
|
||||||
|
|
||||||
namespace Index\Data;
|
namespace Index\Data;
|
||||||
|
|
||||||
use Countable;
|
use Countable;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
|
use RuntimeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common database actions.
|
* Common database actions.
|
||||||
|
@ -60,9 +61,9 @@ final class DbTools {
|
||||||
}
|
}
|
||||||
|
|
||||||
if($backend === null)
|
if($backend === null)
|
||||||
throw new DataException('No implementation is available for the specified scheme.');
|
throw new RuntimeException('No implementation is available for the specified scheme.');
|
||||||
if(!$backend->isAvailable())
|
if(!$backend->isAvailable())
|
||||||
throw new DataException('Requested database backend is not available, likely due to missing dependencies.');
|
throw new RuntimeException('Requested database backend is not available, likely due to missing dependencies.');
|
||||||
|
|
||||||
$backends[$name] = $backend;
|
$backends[$name] = $backend;
|
||||||
}
|
}
|
||||||
|
@ -77,7 +78,7 @@ final class DbTools {
|
||||||
*
|
*
|
||||||
* @param string $dsn URL to create database connection from.
|
* @param string $dsn URL to create database connection from.
|
||||||
* @throws InvalidArgumentException if $dsn is not a valid URL.
|
* @throws InvalidArgumentException if $dsn is not a valid URL.
|
||||||
* @throws DataException if no database connection can be made using the URL.
|
* @throws RuntimeException if no database connection can be made using the URL.
|
||||||
* @return IDbBackend Database backend instance.
|
* @return IDbBackend Database backend instance.
|
||||||
*/
|
*/
|
||||||
public static function backend(string $dsn): IDbBackend {
|
public static function backend(string $dsn): IDbBackend {
|
||||||
|
@ -91,7 +92,7 @@ final class DbTools {
|
||||||
*
|
*
|
||||||
* @param string $dsn URL to create database connection from.
|
* @param string $dsn URL to create database connection from.
|
||||||
* @throws InvalidArgumentException if $dsn is not a valid URL.
|
* @throws InvalidArgumentException if $dsn is not a valid URL.
|
||||||
* @throws DataException if no database connection can be made using the URL.
|
* @throws RuntimeException if no database connection can be made using the URL.
|
||||||
* @return IDbConnectionInfo Database connection info.
|
* @return IDbConnectionInfo Database connection info.
|
||||||
*/
|
*/
|
||||||
public static function parse(string $dsn): IDbConnectionInfo {
|
public static function parse(string $dsn): IDbConnectionInfo {
|
||||||
|
@ -106,7 +107,7 @@ final class DbTools {
|
||||||
*
|
*
|
||||||
* @param string $dsn URL to create database connection from.
|
* @param string $dsn URL to create database connection from.
|
||||||
* @throws InvalidArgumentException if $dsn is not a valid URL.
|
* @throws InvalidArgumentException if $dsn is not a valid URL.
|
||||||
* @throws DataException if no database connection can be made using the URL.
|
* @throws RuntimeException if no database connection can be made using the URL.
|
||||||
* @return IDbConnection An active database connection.
|
* @return IDbConnection An active database connection.
|
||||||
*/
|
*/
|
||||||
public static function create(string $dsn): IDbConnection {
|
public static function create(string $dsn): IDbConnection {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
// IDbTransactions.php
|
// IDbTransactions.php
|
||||||
// Created: 2021-05-02
|
// Created: 2021-05-02
|
||||||
// Updated: 2022-02-16
|
// Updated: 2024-08-01
|
||||||
|
|
||||||
namespace Index\Data;
|
namespace Index\Data;
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ interface IDbTransactions extends IDbConnection {
|
||||||
/**
|
/**
|
||||||
* Enters a transaction.
|
* Enters a transaction.
|
||||||
*
|
*
|
||||||
* @throws BeginTransactionFailedException If the creation of the transaction failed.
|
* @throws \RuntimeException If the creation of the transaction failed.
|
||||||
*/
|
*/
|
||||||
function beginTransaction(): void;
|
function beginTransaction(): void;
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ interface IDbTransactions extends IDbConnection {
|
||||||
* Commits the actions done during a transaction and ends the transaction.
|
* Commits the actions done during a transaction and ends the transaction.
|
||||||
* A new transaction will be started if auto-commit is disabled.
|
* A new transaction will be started if auto-commit is disabled.
|
||||||
*
|
*
|
||||||
* @throws CommitFailedException If the commit failed.
|
* @throws \RuntimeException If the commit failed.
|
||||||
*/
|
*/
|
||||||
function commit(): void;
|
function commit(): void;
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ interface IDbTransactions extends IDbConnection {
|
||||||
* Rolls back to the state before a transaction start or to a specified save point.
|
* Rolls back to the state before a transaction start or to a specified save point.
|
||||||
*
|
*
|
||||||
* @param ?string $name Name of the save point, null for the entire transaction.
|
* @param ?string $name Name of the save point, null for the entire transaction.
|
||||||
* @throws RollbackFailedException If rollback failed.
|
* @throws \RuntimeException If rollback failed.
|
||||||
*/
|
*/
|
||||||
function rollback(?string $name = null): void;
|
function rollback(?string $name = null): void;
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ interface IDbTransactions extends IDbConnection {
|
||||||
* Creates a save point in the transaction that can be rolled back to.
|
* Creates a save point in the transaction that can be rolled back to.
|
||||||
*
|
*
|
||||||
* @param string $name Name for the save point.
|
* @param string $name Name for the save point.
|
||||||
* @throws SavePointFailedException If save point creation failed.
|
* @throws \RuntimeException If save point creation failed.
|
||||||
*/
|
*/
|
||||||
function savePoint(string $name): void;
|
function savePoint(string $name): void;
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ interface IDbTransactions extends IDbConnection {
|
||||||
* Releases a save point.
|
* Releases a save point.
|
||||||
*
|
*
|
||||||
* @param string $name Name of the save point.
|
* @param string $name Name of the save point.
|
||||||
* @throws ReleaseSavePointFailedException If releasing the save point failed.
|
* @throws \RuntimeException If releasing the save point failed.
|
||||||
*/
|
*/
|
||||||
function releaseSavePoint(string $name): void;
|
function releaseSavePoint(string $name): void;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
// MariaDBBackend.php
|
// MariaDBBackend.php
|
||||||
// Created: 2021-04-30
|
// Created: 2021-04-30
|
||||||
// Updated: 2024-07-31
|
// Updated: 2024-08-01
|
||||||
|
|
||||||
namespace Index\Data\MariaDB;
|
namespace Index\Data\MariaDB;
|
||||||
|
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use Index\Data\IDbBackend;
|
use Index\Data\{IDbBackend,IDbConnection,IDbConnectionInfo};
|
||||||
use Index\Data\IDbConnection;
|
use Index\Net\{EndPoint,UnixEndPoint};
|
||||||
use Index\Data\IDbConnectionInfo;
|
|
||||||
use Index\Net\EndPoint;
|
|
||||||
use Index\Net\UnixEndPoint;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Information about the MariaDB/MySQL database layer.
|
* Information about the MariaDB/MySQL database layer.
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
// MariaDBConnection.php
|
// MariaDBConnection.php
|
||||||
// Created: 2021-04-30
|
// Created: 2021-04-30
|
||||||
// Updated: 2024-07-31
|
// Updated: 2024-08-01
|
||||||
|
|
||||||
namespace Index\Data\MariaDB;
|
namespace Index\Data\MariaDB;
|
||||||
|
|
||||||
|
@ -9,16 +9,7 @@ use mysqli;
|
||||||
use mysqli_sql_exception;
|
use mysqli_sql_exception;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use Index\Data\BeginTransactionFailedException;
|
use Index\Data\{IDbConnection,IDbTransactions};
|
||||||
use Index\Data\DataException;
|
|
||||||
use Index\Data\IDbConnection;
|
|
||||||
use Index\Data\IDbTransactions;
|
|
||||||
use Index\Data\CommitFailedException;
|
|
||||||
use Index\Data\ConnectionFailedException;
|
|
||||||
use Index\Data\ReleaseSavePointFailedException;
|
|
||||||
use Index\Data\RollbackFailedException;
|
|
||||||
use Index\Data\SavePointFailedException;
|
|
||||||
use Index\Data\QueryExecuteException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a connection with a MariaDB or MySQL database server.
|
* Represents a connection with a MariaDB or MySQL database server.
|
||||||
|
@ -146,7 +137,7 @@ class MariaDBConnection implements IDbConnection, IDbTransactions {
|
||||||
$flags
|
$flags
|
||||||
);
|
);
|
||||||
} catch(mysqli_sql_exception $ex) {
|
} catch(mysqli_sql_exception $ex) {
|
||||||
throw new ConnectionFailedException($ex->getMessage(), $ex->getCode(), $ex);
|
throw new RuntimeException($ex->getMessage(), $ex->getCode(), $ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,22 +185,22 @@ class MariaDBConnection implements IDbConnection, IDbTransactions {
|
||||||
* @param string $userName New user name.
|
* @param string $userName New user name.
|
||||||
* @param string $password New password.
|
* @param string $password New password.
|
||||||
* @param string|null $database New default database.
|
* @param string|null $database New default database.
|
||||||
* @throws DataException If the user switch action failed.
|
* @throws RuntimeException If the user switch action failed.
|
||||||
*/
|
*/
|
||||||
public function switchUser(string $userName, string $password, string|null $database = null): void {
|
public function switchUser(string $userName, string $password, string|null $database = null): void {
|
||||||
if(!$this->connection->change_user($userName, $password, $database === null ? null : $database))
|
if(!$this->connection->change_user($userName, $password, $database === null ? null : $database))
|
||||||
throw new DataException($this->getLastErrorString(), $this->getLastErrorCode());
|
throw new RuntimeException($this->getLastErrorString(), $this->getLastErrorCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Switches the default database for this connection.
|
* Switches the default database for this connection.
|
||||||
*
|
*
|
||||||
* @param string $database New default database.
|
* @param string $database New default database.
|
||||||
* @throws DataException If the database switch failed.
|
* @throws RuntimeException If the database switch failed.
|
||||||
*/
|
*/
|
||||||
public function switchDatabase(string $database): void {
|
public function switchDatabase(string $database): void {
|
||||||
if(!$this->connection->select_db($database))
|
if(!$this->connection->select_db($database))
|
||||||
throw new DataException($this->getLastErrorString(), $this->getLastErrorCode());
|
throw new RuntimeException($this->getLastErrorString(), $this->getLastErrorCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -314,27 +305,27 @@ class MariaDBConnection implements IDbConnection, IDbTransactions {
|
||||||
|
|
||||||
public function beginTransaction(): void {
|
public function beginTransaction(): void {
|
||||||
if(!$this->connection->begin_transaction())
|
if(!$this->connection->begin_transaction())
|
||||||
throw new BeginTransactionFailedException((string)$this->getLastErrorString(), $this->getLastErrorCode());
|
throw new RuntimeException((string)$this->getLastErrorString(), $this->getLastErrorCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function commit(): void {
|
public function commit(): void {
|
||||||
if(!$this->connection->commit())
|
if(!$this->connection->commit())
|
||||||
throw new CommitFailedException((string)$this->getLastErrorString(), $this->getLastErrorCode());
|
throw new RuntimeException((string)$this->getLastErrorString(), $this->getLastErrorCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function rollback(?string $name = null): void {
|
public function rollback(?string $name = null): void {
|
||||||
if(!$this->connection->rollback(0, $name))
|
if(!$this->connection->rollback(0, $name))
|
||||||
throw new RollbackFailedException((string)$this->getLastErrorString(), $this->getLastErrorCode());
|
throw new RuntimeException((string)$this->getLastErrorString(), $this->getLastErrorCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function savePoint(string $name): void {
|
public function savePoint(string $name): void {
|
||||||
if(!$this->connection->savepoint($name))
|
if(!$this->connection->savepoint($name))
|
||||||
throw new SavePointFailedException((string)$this->getLastErrorString(), $this->getLastErrorCode());
|
throw new RuntimeException((string)$this->getLastErrorString(), $this->getLastErrorCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function releaseSavePoint(string $name): void {
|
public function releaseSavePoint(string $name): void {
|
||||||
if(!$this->connection->release_savepoint($name))
|
if(!$this->connection->release_savepoint($name))
|
||||||
throw new ReleaseSavePointFailedException((string)$this->getLastErrorString(), $this->getLastErrorCode());
|
throw new RuntimeException((string)$this->getLastErrorString(), $this->getLastErrorCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -363,10 +354,10 @@ class MariaDBConnection implements IDbConnection, IDbTransactions {
|
||||||
try {
|
try {
|
||||||
$statement = $this->connection->prepare($query);
|
$statement = $this->connection->prepare($query);
|
||||||
} catch(mysqli_sql_exception $ex) {
|
} catch(mysqli_sql_exception $ex) {
|
||||||
throw new QueryExecuteException($ex->getMessage(), $ex->getCode(), $ex);
|
throw new RuntimeException($ex->getMessage(), $ex->getCode(), $ex);
|
||||||
}
|
}
|
||||||
if($statement === false)
|
if($statement === false)
|
||||||
throw new QueryExecuteException($this->getLastErrorString(), $this->getLastErrorCode());
|
throw new RuntimeException($this->getLastErrorString(), $this->getLastErrorCode());
|
||||||
return new MariaDBStatement($statement);
|
return new MariaDBStatement($statement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -377,10 +368,10 @@ class MariaDBConnection implements IDbConnection, IDbTransactions {
|
||||||
try {
|
try {
|
||||||
$result = $this->connection->query($query, MYSQLI_STORE_RESULT);
|
$result = $this->connection->query($query, MYSQLI_STORE_RESULT);
|
||||||
} catch(mysqli_sql_exception $ex) {
|
} catch(mysqli_sql_exception $ex) {
|
||||||
throw new QueryExecuteException($ex->getMessage(), $ex->getCode(), $ex);
|
throw new RuntimeException($ex->getMessage(), $ex->getCode(), $ex);
|
||||||
}
|
}
|
||||||
if($result === false)
|
if($result === false)
|
||||||
throw new QueryExecuteException($this->getLastErrorString(), $this->getLastErrorCode());
|
throw new RuntimeException($this->getLastErrorString(), $this->getLastErrorCode());
|
||||||
// Yes, this always uses Native, for some reason the stupid limitation in libmysql only applies to preparing
|
// Yes, this always uses Native, for some reason the stupid limitation in libmysql only applies to preparing
|
||||||
return new MariaDBResultNative($result);
|
return new MariaDBResultNative($result);
|
||||||
}
|
}
|
||||||
|
@ -388,9 +379,9 @@ class MariaDBConnection implements IDbConnection, IDbTransactions {
|
||||||
public function execute(string $query): int|string {
|
public function execute(string $query): int|string {
|
||||||
try {
|
try {
|
||||||
if(!$this->connection->real_query($query))
|
if(!$this->connection->real_query($query))
|
||||||
throw new QueryExecuteException($this->getLastErrorString(), $this->getLastErrorCode());
|
throw new RuntimeException($this->getLastErrorString(), $this->getLastErrorCode());
|
||||||
} catch(mysqli_sql_exception $ex) {
|
} catch(mysqli_sql_exception $ex) {
|
||||||
throw new QueryExecuteException($ex->getMessage(), $ex->getCode(), $ex);
|
throw new RuntimeException($ex->getMessage(), $ex->getCode(), $ex);
|
||||||
}
|
}
|
||||||
return $this->connection->affected_rows;
|
return $this->connection->affected_rows;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
// MariaDBConnectionInfo.php
|
// MariaDBConnectionInfo.php
|
||||||
// Created: 2021-04-30
|
// Created: 2021-04-30
|
||||||
// Updated: 2022-02-28
|
// Updated: 2024-08-01
|
||||||
|
|
||||||
namespace Index\Data\MariaDB;
|
namespace Index\Data\MariaDB;
|
||||||
|
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use Index\Data\IDbConnectionInfo;
|
use Index\Data\IDbConnectionInfo;
|
||||||
use Index\Net\EndPoint;
|
use Index\Net\{EndPoint,DnsEndPoint,IPAddress,IPEndPoint,UnixEndPoint};
|
||||||
use Index\Net\DnsEndPoint;
|
|
||||||
use Index\Net\IPAddress;
|
|
||||||
use Index\Net\IPEndPoint;
|
|
||||||
use Index\Net\UnixEndPoint;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Describes a MariaDB or MySQL connection.
|
* Describes a MariaDB or MySQL connection.
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
// MariaDBParameter.php
|
// MariaDBParameter.php
|
||||||
// Created: 2021-05-02
|
// Created: 2021-05-02
|
||||||
// Updated: 2022-02-02
|
// Updated: 2024-08-01
|
||||||
|
|
||||||
namespace Index\Data\MariaDB;
|
namespace Index\Data\MariaDB;
|
||||||
|
|
||||||
use Index\Data\DbTools;
|
use Index\Data\{DbTools,DbType};
|
||||||
use Index\Data\DbType;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a bound parameter.
|
* Represents a bound parameter.
|
||||||
|
|
|
@ -1,17 +1,15 @@
|
||||||
<?php
|
<?php
|
||||||
// MariaDBResult.php
|
// MariaDBResult.php
|
||||||
// Created: 2021-05-02
|
// Created: 2021-05-02
|
||||||
// Updated: 2023-11-09
|
// Updated: 2024-08-01
|
||||||
|
|
||||||
namespace Index\Data\MariaDB;
|
namespace Index\Data\MariaDB;
|
||||||
|
|
||||||
use mysqli_result;
|
use mysqli_result;
|
||||||
use mysqli_stmt;
|
use mysqli_stmt;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use Index\Data\DbResultTrait;
|
use Index\Data\{DbResultTrait,IDbResult};
|
||||||
use Index\Data\IDbResult;
|
use Index\IO\{Stream,TempFileStream};
|
||||||
use Index\IO\Stream;
|
|
||||||
use Index\IO\TempFileStream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a MariaDB/MySQL database result.
|
* Represents a MariaDB/MySQL database result.
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
// MariaDBResultLib.php
|
// MariaDBResultLib.php
|
||||||
// Created: 2021-05-02
|
// Created: 2021-05-02
|
||||||
// Updated: 2023-07-10
|
// Updated: 2024-08-01
|
||||||
|
|
||||||
namespace Index\Data\MariaDB;
|
namespace Index\Data\MariaDB;
|
||||||
|
|
||||||
use mysqli_stmt;
|
use mysqli_stmt;
|
||||||
use Index\Data\QueryExecuteException;
|
use RuntimeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of MariaDBResult for libmysql.
|
* Implementation of MariaDBResult for libmysql.
|
||||||
|
@ -21,7 +21,7 @@ class MariaDBResultLib extends MariaDBResult {
|
||||||
parent::__construct($statement);
|
parent::__construct($statement);
|
||||||
|
|
||||||
if(!$statement->store_result())
|
if(!$statement->store_result())
|
||||||
throw new QueryExecuteException($statement->error, $statement->errno);
|
throw new RuntimeException($statement->error, $statement->errno);
|
||||||
|
|
||||||
$metadata = $statement->result_metadata();
|
$metadata = $statement->result_metadata();
|
||||||
while($field = $metadata->fetch_field())
|
while($field = $metadata->fetch_field())
|
||||||
|
@ -33,7 +33,7 @@ class MariaDBResultLib extends MariaDBResult {
|
||||||
public function next(): bool {
|
public function next(): bool {
|
||||||
$result = $this->result->fetch();
|
$result = $this->result->fetch();
|
||||||
if($result === false)
|
if($result === false)
|
||||||
throw new QueryExecuteException($this->result->error, $this->result->errno);
|
throw new RuntimeException($this->result->error, $this->result->errno);
|
||||||
if($result === null)
|
if($result === null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
// MariaDBResultNative.php
|
// MariaDBResultNative.php
|
||||||
// Created: 2021-05-02
|
// Created: 2021-05-02
|
||||||
// Updated: 2023-07-10
|
// Updated: 2024-08-01
|
||||||
|
|
||||||
namespace Index\Data\MariaDB;
|
namespace Index\Data\MariaDB;
|
||||||
|
|
||||||
use mysqli_result;
|
use mysqli_result;
|
||||||
use mysqli_stmt;
|
use mysqli_stmt;
|
||||||
use Index\Data\QueryExecuteException;
|
use RuntimeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of MariaDBResult for mysqlnd.
|
* Implementation of MariaDBResult for mysqlnd.
|
||||||
|
@ -19,7 +19,7 @@ class MariaDBResultNative extends MariaDBResult {
|
||||||
if($result instanceof mysqli_stmt) {
|
if($result instanceof mysqli_stmt) {
|
||||||
$_result = $result->get_result();
|
$_result = $result->get_result();
|
||||||
if($_result === false)
|
if($_result === false)
|
||||||
throw new QueryExecuteException($result->error, $result->errno);
|
throw new RuntimeException($result->error, $result->errno);
|
||||||
$result = $_result;
|
$result = $_result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
// MariaDBStatement.php
|
// MariaDBStatement.php
|
||||||
// Created: 2021-05-02
|
// Created: 2021-05-02
|
||||||
// Updated: 2023-01-01
|
// Updated: 2024-08-01
|
||||||
|
|
||||||
namespace Index\Data\MariaDB;
|
namespace Index\Data\MariaDB;
|
||||||
|
|
||||||
use mysqli_stmt;
|
use mysqli_stmt;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use Index\Data\DbType;
|
use Index\Data\{DbType,IDbStatement};
|
||||||
use Index\Data\QueryExecuteException;
|
|
||||||
use Index\Data\IDbStatement;
|
|
||||||
use Index\IO\Stream;
|
use Index\IO\Stream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -144,13 +142,13 @@ class MariaDBStatement implements IDbStatement {
|
||||||
call_user_func_array([$this->statement, 'bind_param'], $args);
|
call_user_func_array([$this->statement, 'bind_param'], $args);
|
||||||
|
|
||||||
if(!$this->statement->execute())
|
if(!$this->statement->execute())
|
||||||
throw new QueryExecuteException($this->getLastErrorString(), $this->getLastErrorCode());
|
throw new RuntimeException($this->getLastErrorString(), $this->getLastErrorCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function reset(): void {
|
public function reset(): void {
|
||||||
$this->params = [];
|
$this->params = [];
|
||||||
if(!$this->statement->reset())
|
if(!$this->statement->reset())
|
||||||
throw new QueryExecuteException($this->getLastErrorString(), $this->getLastErrorCode());
|
throw new RuntimeException($this->getLastErrorString(), $this->getLastErrorCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function close(): void {
|
public function close(): void {
|
||||||
|
|
|
@ -10,9 +10,7 @@ use InvalidArgumentException;
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
use Index\XDateTime;
|
use Index\XDateTime;
|
||||||
use Index\Data\IDbConnection;
|
use Index\Data\{IDbConnection,IDbStatement,DbType};
|
||||||
use Index\Data\IDbStatement;
|
|
||||||
use Index\Data\DbType;
|
|
||||||
use Index\Data\SQLite\SQLiteConnection;
|
use Index\Data\SQLite\SQLiteConnection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
// NullDbBackend.php
|
// NullDbBackend.php
|
||||||
// Created: 2021-05-02
|
// Created: 2021-05-02
|
||||||
// Updated: 2024-04-10
|
// Updated: 2024-08-01
|
||||||
|
|
||||||
namespace Index\Data\NullDb;
|
namespace Index\Data\NullDb;
|
||||||
|
|
||||||
use Index\Data\IDbBackend;
|
use Index\Data\{IDbBackend,IDbConnection,IDbConnectionInfo};
|
||||||
use Index\Data\IDbConnection;
|
|
||||||
use Index\Data\IDbConnectionInfo;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Information about the dummy database layer.
|
* Information about the dummy database layer.
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
// NullDbConnection.php
|
// NullDbConnection.php
|
||||||
// Created: 2021-05-02
|
// Created: 2021-05-02
|
||||||
// Updated: 2022-02-27
|
// Updated: 2024-08-01
|
||||||
|
|
||||||
namespace Index\Data\NullDb;
|
namespace Index\Data\NullDb;
|
||||||
|
|
||||||
use Index\Data\IDbConnection;
|
use Index\Data\{IDbConnection,IDbStatement,IDbResult};
|
||||||
use Index\Data\IDbStatement;
|
|
||||||
use Index\Data\IDbResult;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a dummy database connection.
|
* Represents a dummy database connection.
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
// NullDbResult.php
|
// NullDbResult.php
|
||||||
// Created: 2021-05-02
|
// Created: 2021-05-02
|
||||||
// Updated: 2024-02-06
|
// Updated: 2024-08-01
|
||||||
|
|
||||||
namespace Index\Data\NullDb;
|
namespace Index\Data\NullDb;
|
||||||
|
|
||||||
use Index\Data\IDbResult;
|
use Index\Data\{IDbResult,DbResultIterator};
|
||||||
use Index\Data\DbResultIterator;
|
|
||||||
use Index\IO\Stream;
|
use Index\IO\Stream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
// NullDbStatement.php
|
// NullDbStatement.php
|
||||||
// Created: 2021-05-02
|
// Created: 2021-05-02
|
||||||
// Updated: 2022-02-16
|
// Updated: 2024-08-01
|
||||||
|
|
||||||
namespace Index\Data\NullDb;
|
namespace Index\Data\NullDb;
|
||||||
|
|
||||||
use Index\Data\DbType;
|
use Index\Data\{DbType,IDbResult,IDbStatement};
|
||||||
use Index\Data\IDbResult;
|
|
||||||
use Index\Data\IDbStatement;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a dummy database statement.
|
* Represents a dummy database statement.
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
<?php
|
|
||||||
// QueryExecuteException.php
|
|
||||||
// Created: 2021-05-02
|
|
||||||
// Updated: 2021-05-12
|
|
||||||
|
|
||||||
namespace Index\Data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exception to be thrown when query execution fails.
|
|
||||||
*/
|
|
||||||
class QueryExecuteException extends DataException {}
|
|
|
@ -1,11 +0,0 @@
|
||||||
<?php
|
|
||||||
// ReleaseSavePointFailedException.php
|
|
||||||
// Created: 2021-05-02
|
|
||||||
// Updated: 2021-05-12
|
|
||||||
|
|
||||||
namespace Index\Data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exception to be thrown when save point release fails.
|
|
||||||
*/
|
|
||||||
class ReleaseSavePointFailedException extends TransactionException {}
|
|
|
@ -1,11 +0,0 @@
|
||||||
<?php
|
|
||||||
// RollbackFailedException.php
|
|
||||||
// Created: 2021-05-02
|
|
||||||
// Updated: 2021-05-12
|
|
||||||
|
|
||||||
namespace Index\Data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exception to be thrown when transaction rollback fails.
|
|
||||||
*/
|
|
||||||
class RollbackFailedException extends TransactionException {}
|
|
|
@ -1,15 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
// SQLiteBackend.php
|
// SQLiteBackend.php
|
||||||
// Created: 2021-05-02
|
// Created: 2021-05-02
|
||||||
// Updated: 2024-07-31
|
// Updated: 2024-08-01
|
||||||
|
|
||||||
namespace Index\Data\SQLite;
|
namespace Index\Data\SQLite;
|
||||||
|
|
||||||
use SQLite3;
|
use SQLite3;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use Index\Data\IDbBackend;
|
use Index\Data\{IDbBackend,IDbConnection,IDbConnectionInfo};
|
||||||
use Index\Data\IDbConnection;
|
|
||||||
use Index\Data\IDbConnectionInfo;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Information about the SQLite 3 database layer.
|
* Information about the SQLite 3 database layer.
|
||||||
|
|
|
@ -1,24 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
// SQLiteConnection.php
|
// SQLiteConnection.php
|
||||||
// Created: 2021-05-02
|
// Created: 2021-05-02
|
||||||
// Updated: 2022-02-27
|
// Updated: 2024-08-01
|
||||||
|
|
||||||
namespace Index\Data\SQLite;
|
namespace Index\Data\SQLite;
|
||||||
|
|
||||||
use SQLite3;
|
use SQLite3;
|
||||||
use Index\Data\BeginTransactionFailedException;
|
use Index\Data\{IDbConnection,IDbTransactions,IDbStatement,IDbResult};
|
||||||
use Index\Data\DataException;
|
use Index\IO\{GenericStream,Stream};
|
||||||
use Index\Data\IDbConnection;
|
|
||||||
use Index\Data\IDbTransactions;
|
|
||||||
use Index\Data\IDbStatement;
|
|
||||||
use Index\Data\IDbResult;
|
|
||||||
use Index\Data\CommitFailedException;
|
|
||||||
use Index\Data\ReleaseSavePointFailedException;
|
|
||||||
use Index\Data\RollbackFailedException;
|
|
||||||
use Index\Data\SavePointFailedException;
|
|
||||||
use Index\Data\QueryExecuteException;
|
|
||||||
use Index\IO\GenericStream;
|
|
||||||
use Index\IO\Stream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a client for an SQLite database.
|
* Represents a client for an SQLite database.
|
||||||
|
@ -480,13 +469,13 @@ class SQLiteConnection implements IDbConnection, IDbTransactions {
|
||||||
* @param string $table Name of the source table.
|
* @param string $table Name of the source table.
|
||||||
* @param string $column Name of the source column.
|
* @param string $column Name of the source column.
|
||||||
* @param int $rowId ID of the source row.
|
* @param int $rowId ID of the source row.
|
||||||
* @throws DataException If opening the BLOB failed.
|
* @throws RuntimeException If opening the BLOB failed.
|
||||||
* @return Stream BLOB field as a Stream.
|
* @return Stream BLOB field as a Stream.
|
||||||
*/
|
*/
|
||||||
public function getBlobStream(string $table, string $column, int $rowId): Stream {
|
public function getBlobStream(string $table, string $column, int $rowId): Stream {
|
||||||
$handle = $this->connection->openBlob($table, $column, $rowId);
|
$handle = $this->connection->openBlob($table, $column, $rowId);
|
||||||
if(!is_resource($handle))
|
if(!is_resource($handle))
|
||||||
throw new DataException((string)$this->getLastErrorString(), $this->getLastErrorCode());
|
throw new RuntimeException((string)$this->getLastErrorString(), $this->getLastErrorCode());
|
||||||
return new GenericStream($this->connection->openBlob($table, $column, $rowId));
|
return new GenericStream($this->connection->openBlob($table, $column, $rowId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -497,20 +486,20 @@ class SQLiteConnection implements IDbConnection, IDbTransactions {
|
||||||
public function prepare(string $query): IDbStatement {
|
public function prepare(string $query): IDbStatement {
|
||||||
$statement = $this->connection->prepare($query);
|
$statement = $this->connection->prepare($query);
|
||||||
if($statement === false)
|
if($statement === false)
|
||||||
throw new QueryExecuteException((string)$this->getLastErrorString(), $this->getLastErrorCode());
|
throw new RuntimeException((string)$this->getLastErrorString(), $this->getLastErrorCode());
|
||||||
return new SQLiteStatement($this, $statement);
|
return new SQLiteStatement($this, $statement);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function query(string $query): IDbResult {
|
public function query(string $query): IDbResult {
|
||||||
$result = $this->connection->query($query);
|
$result = $this->connection->query($query);
|
||||||
if($result === false)
|
if($result === false)
|
||||||
throw new QueryExecuteException($this->getLastErrorString(), $this->getLastErrorCode());
|
throw new RuntimeException($this->getLastErrorString(), $this->getLastErrorCode());
|
||||||
return new SQLiteResult($result);
|
return new SQLiteResult($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute(string $query): int|string {
|
public function execute(string $query): int|string {
|
||||||
if(!$this->connection->exec($query))
|
if(!$this->connection->exec($query))
|
||||||
throw new QueryExecuteException($this->getLastErrorString(), $this->getLastErrorCode());
|
throw new RuntimeException($this->getLastErrorString(), $this->getLastErrorCode());
|
||||||
return $this->connection->changes();
|
return $this->connection->changes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -529,31 +518,31 @@ class SQLiteConnection implements IDbConnection, IDbTransactions {
|
||||||
|
|
||||||
public function beginTransaction(): void {
|
public function beginTransaction(): void {
|
||||||
if(!$this->connection->exec('BEGIN;'))
|
if(!$this->connection->exec('BEGIN;'))
|
||||||
throw new BeginTransactionFailedException((string)$this->getLastErrorString(), $this->getLastErrorCode());
|
throw new RuntimeException((string)$this->getLastErrorString(), $this->getLastErrorCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function commit(): void {
|
public function commit(): void {
|
||||||
if(!$this->connection->exec('COMMIT;'))
|
if(!$this->connection->exec('COMMIT;'))
|
||||||
throw new CommitFailedException((string)$this->getLastErrorString(), $this->getLastErrorCode());
|
throw new RuntimeException((string)$this->getLastErrorString(), $this->getLastErrorCode());
|
||||||
if(!$this->autoCommit)
|
if(!$this->autoCommit)
|
||||||
$this->beginTransaction();
|
$this->beginTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function rollback(?string $name = null): void {
|
public function rollback(?string $name = null): void {
|
||||||
if(!$this->connection->exec(empty($name) ? 'ROLLBACK;' : "ROLLBACK TO {$name};"))
|
if(!$this->connection->exec(empty($name) ? 'ROLLBACK;' : "ROLLBACK TO {$name};"))
|
||||||
throw new CommitFailedException((string)$this->getLastErrorString(), $this->getLastErrorCode());
|
throw new RuntimeException((string)$this->getLastErrorString(), $this->getLastErrorCode());
|
||||||
if(!$this->autoCommit)
|
if(!$this->autoCommit)
|
||||||
$this->beginTransaction();
|
$this->beginTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function savePoint(string $name): void {
|
public function savePoint(string $name): void {
|
||||||
if(!$this->connection->exec("SAVEPOINT {$name};"))
|
if(!$this->connection->exec("SAVEPOINT {$name};"))
|
||||||
throw new SavePointFailedException((string)$this->getLastErrorString(), $this->getLastErrorCode());
|
throw new RuntimeException((string)$this->getLastErrorString(), $this->getLastErrorCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function releaseSavePoint(string $name): void {
|
public function releaseSavePoint(string $name): void {
|
||||||
if(!$this->connection->exec("RELEASE SAVEPOINT {$name};"))
|
if(!$this->connection->exec("RELEASE SAVEPOINT {$name};"))
|
||||||
throw new ReleaseSavePointFailedException((string)$this->getLastErrorString(), $this->getLastErrorCode());
|
throw new RuntimeException((string)$this->getLastErrorString(), $this->getLastErrorCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function close(): void {
|
public function close(): void {
|
||||||
|
|
|
@ -1,16 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
// SQLiteResult.php
|
// SQLiteResult.php
|
||||||
// Created: 2021-05-02
|
// Created: 2021-05-02
|
||||||
// Updated: 2023-11-09
|
// Updated: 2024-08-01
|
||||||
|
|
||||||
namespace Index\Data\SQLite;
|
namespace Index\Data\SQLite;
|
||||||
|
|
||||||
use SQLite3Result;
|
use SQLite3Result;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use Index\Data\DbResultTrait;
|
use Index\Data\{DbResultTrait,IDbResult};
|
||||||
use Index\Data\IDbResult;
|
use Index\IO\{Stream,TempFileStream};
|
||||||
use Index\IO\Stream;
|
|
||||||
use Index\IO\TempFileStream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an SQLite result set.
|
* Represents an SQLite result set.
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
// SQLiteStatement.php
|
// SQLiteStatement.php
|
||||||
// Created: 2021-05-02
|
// Created: 2021-05-02
|
||||||
// Updated: 2022-02-16
|
// Updated: 2024-08-01
|
||||||
|
|
||||||
namespace Index\Data\SQLite;
|
namespace Index\Data\SQLite;
|
||||||
|
|
||||||
|
@ -9,11 +9,7 @@ use SQLite3Result;
|
||||||
use SQLite3Stmt;
|
use SQLite3Stmt;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use Index\Data\DbTools;
|
use Index\Data\{DbTools,DbType,IDbStatement,IDbResult};
|
||||||
use Index\Data\DbType;
|
|
||||||
use Index\Data\QueryExecuteException;
|
|
||||||
use Index\Data\IDbStatement;
|
|
||||||
use Index\Data\IDbResult;
|
|
||||||
use Index\IO\Stream;
|
use Index\IO\Stream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -68,7 +64,7 @@ class SQLiteStatement implements IDbStatement {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$this->statement->bindValue($ordinal, $value, $type))
|
if(!$this->statement->bindValue($ordinal, $value, $type))
|
||||||
throw new QueryExecuteException((string)$this->connection->getLastErrorString(), $this->connection->getLastErrorCode());
|
throw new RuntimeException((string)$this->connection->getLastErrorString(), $this->connection->getLastErrorCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getResult(): IDbResult {
|
public function getResult(): IDbResult {
|
||||||
|
@ -84,16 +80,16 @@ class SQLiteStatement implements IDbStatement {
|
||||||
public function execute(): void {
|
public function execute(): void {
|
||||||
$result = $this->statement->execute();
|
$result = $this->statement->execute();
|
||||||
if($result === false)
|
if($result === false)
|
||||||
throw new QueryExecuteException((string)$this->connection->getLastErrorString(), $this->connection->getLastErrorCode());
|
throw new RuntimeException((string)$this->connection->getLastErrorString(), $this->connection->getLastErrorCode());
|
||||||
$this->result = $result;
|
$this->result = $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function reset(): void {
|
public function reset(): void {
|
||||||
$this->result = null;
|
$this->result = null;
|
||||||
if(!$this->statement->clear())
|
if(!$this->statement->clear())
|
||||||
throw new QueryExecuteException((string)$this->connection->getLastErrorString(), $this->connection->getLastErrorCode());
|
throw new RuntimeException((string)$this->connection->getLastErrorString(), $this->connection->getLastErrorCode());
|
||||||
if(!$this->statement->reset())
|
if(!$this->statement->reset())
|
||||||
throw new QueryExecuteException((string)$this->connection->getLastErrorString(), $this->connection->getLastErrorCode());
|
throw new RuntimeException((string)$this->connection->getLastErrorString(), $this->connection->getLastErrorCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function close(): void {}
|
public function close(): void {}
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
<?php
|
|
||||||
// SavePointFailedException.php
|
|
||||||
// Created: 2021-05-02
|
|
||||||
// Updated: 2021-05-12
|
|
||||||
|
|
||||||
namespace Index\Data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exception to be thrown when save point creation fails.
|
|
||||||
*/
|
|
||||||
class SavePointFailedException extends TransactionException {}
|
|
|
@ -1,11 +0,0 @@
|
||||||
<?php
|
|
||||||
// TransactionException.php
|
|
||||||
// Created: 2021-05-02
|
|
||||||
// Updated: 2021-05-12
|
|
||||||
|
|
||||||
namespace Index\Data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exception for errors during transactions.
|
|
||||||
*/
|
|
||||||
class TransactionException extends DataException {}
|
|
|
@ -5,10 +5,8 @@
|
||||||
|
|
||||||
namespace Index\Http\Content;
|
namespace Index\Http\Content;
|
||||||
|
|
||||||
use Index\Bencode\Bencode;
|
use Index\Bencode\{Bencode,IBencodeSerialisable};
|
||||||
use Index\Bencode\IBencodeSerialisable;
|
use Index\IO\{Stream,FileStream};
|
||||||
use Index\IO\Stream;
|
|
||||||
use Index\IO\FileStream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents Bencoded body content for a HTTP message.
|
* Represents Bencoded body content for a HTTP message.
|
||||||
|
|
|
@ -6,8 +6,7 @@
|
||||||
namespace Index\Http\Content;
|
namespace Index\Http\Content;
|
||||||
|
|
||||||
use JsonSerializable;
|
use JsonSerializable;
|
||||||
use Index\IO\Stream;
|
use Index\IO\{Stream,FileStream};
|
||||||
use Index\IO\FileStream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents JSON body content for a HTTP message.
|
* Represents JSON body content for a HTTP message.
|
||||||
|
|
|
@ -5,8 +5,7 @@
|
||||||
|
|
||||||
namespace Index\Http\Content;
|
namespace Index\Http\Content;
|
||||||
|
|
||||||
use Index\IO\Stream;
|
use Index\IO\{Stream,FileStream};
|
||||||
use Index\IO\FileStream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents Stream body content for a HTTP message.
|
* Represents Stream body content for a HTTP message.
|
||||||
|
|
|
@ -5,8 +5,7 @@
|
||||||
|
|
||||||
namespace Index\Http\ErrorHandling;
|
namespace Index\Http\ErrorHandling;
|
||||||
|
|
||||||
use Index\Http\HttpResponseBuilder;
|
use Index\Http\{HttpResponseBuilder,HttpRequest};
|
||||||
use Index\Http\HttpRequest;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an error message handler for building HTTP response messages.
|
* Represents an error message handler for building HTTP response messages.
|
||||||
|
|
|
@ -7,12 +7,7 @@ namespace Index\Http;
|
||||||
|
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use Index\IO\Stream;
|
use Index\IO\Stream;
|
||||||
use Index\Http\Content\IHttpContent;
|
use Index\Http\Content\{IHttpContent,BencodedContent,FormContent,JsonContent,StreamContent,StringContent};
|
||||||
use Index\Http\Content\BencodedContent;
|
|
||||||
use Index\Http\Content\FormContent;
|
|
||||||
use Index\Http\Content\JsonContent;
|
|
||||||
use Index\Http\Content\StreamContent;
|
|
||||||
use Index\Http\Content\StringContent;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a base HTTP message.
|
* Represents a base HTTP message.
|
||||||
|
|
|
@ -6,9 +6,7 @@
|
||||||
namespace Index\Http;
|
namespace Index\Http;
|
||||||
|
|
||||||
use Index\IO\Stream;
|
use Index\IO\Stream;
|
||||||
use Index\Http\Content\IHttpContent;
|
use Index\Http\Content\{IHttpContent,StreamContent,StringContent};
|
||||||
use Index\Http\Content\StreamContent;
|
|
||||||
use Index\Http\Content\StringContent;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a base HTTP message builder.
|
* Represents a base HTTP message builder.
|
||||||
|
|
|
@ -8,10 +8,7 @@ namespace Index\Http;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use Index\MediaType;
|
use Index\MediaType;
|
||||||
use Index\Http\Content\IHttpContent;
|
use Index\Http\Content\{IHttpContent,JsonContent,StreamContent,FormContent};
|
||||||
use Index\Http\Content\JsonContent;
|
|
||||||
use Index\Http\Content\StreamContent;
|
|
||||||
use Index\Http\Content\FormContent;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a HTTP request message.
|
* Represents a HTTP request message.
|
||||||
|
|
|
@ -6,9 +6,7 @@
|
||||||
namespace Index\Http;
|
namespace Index\Http;
|
||||||
|
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
use Index\UrlEncoding;
|
use Index\{UrlEncoding,MediaType,XDateTime};
|
||||||
use Index\MediaType;
|
|
||||||
use Index\XDateTime;
|
|
||||||
use Index\Performance\Timings;
|
use Index\Performance\Timings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -5,12 +5,10 @@
|
||||||
|
|
||||||
namespace Index\Http;
|
namespace Index\Http;
|
||||||
|
|
||||||
use Index\MediaType;
|
|
||||||
use Index\ICloseable;
|
|
||||||
use Index\IO\Stream;
|
|
||||||
use Index\IO\FileStream;
|
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
|
use Index\{MediaType,ICloseable};
|
||||||
|
use Index\IO\{Stream,FileStream};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an uploaded file in a multipart/form-data request.
|
* Represents an uploaded file in a multipart/form-data request.
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
// RouterTrait.php
|
// RouterTrait.php
|
||||||
// Created: 2024-03-28
|
// Created: 2024-03-28
|
||||||
// Updated: 2024-03-28
|
// Updated: 2024-08-01
|
||||||
|
|
||||||
namespace Index\Http\Routing;
|
namespace Index\Http\Routing;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contains implementations for HTTP request method handler registration.
|
||||||
|
*/
|
||||||
trait RouterTrait {
|
trait RouterTrait {
|
||||||
public function get(string $path, callable $handler): void {
|
public function get(string $path, callable $handler): void {
|
||||||
$this->add('GET', $path, $handler);
|
$this->add('GET', $path, $handler);
|
||||||
|
|
|
@ -1,16 +1,23 @@
|
||||||
<?php
|
<?php
|
||||||
// ScopedRouter.php
|
// ScopedRouter.php
|
||||||
// Created: 2024-03-28
|
// Created: 2024-03-28
|
||||||
// Updated: 2024-03-28
|
// Updated: 2024-08-01
|
||||||
|
|
||||||
namespace Index\Http\Routing;
|
namespace Index\Http\Routing;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides a scoped router interface, automatically adds a prefix to any routes added.
|
||||||
|
*/
|
||||||
class ScopedRouter implements IRouter {
|
class ScopedRouter implements IRouter {
|
||||||
use RouterTrait;
|
use RouterTrait;
|
||||||
|
|
||||||
private IRouter $router;
|
private IRouter $router;
|
||||||
private string $prefix;
|
private string $prefix;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param IRouter $router Underlying router.
|
||||||
|
* @param string $prefix Base path to use as a prefix.
|
||||||
|
*/
|
||||||
public function __construct(IRouter $router, string $prefix) {
|
public function __construct(IRouter $router, string $prefix) {
|
||||||
if($router instanceof ScopedRouter)
|
if($router instanceof ScopedRouter)
|
||||||
$router = $router->getParentRouter();
|
$router = $router->getParentRouter();
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
namespace Index\IO;
|
namespace Index\IO;
|
||||||
|
|
||||||
use ErrorException;
|
use ErrorException;
|
||||||
|
use RuntimeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a Stream representing a file.
|
* Represents a Stream representing a file.
|
||||||
|
@ -115,6 +116,7 @@ class FileStream extends GenericStream {
|
||||||
* @param string $path Path to the file.
|
* @param string $path Path to the file.
|
||||||
* @param string $mode Stream mode to use to open the file.
|
* @param string $mode Stream mode to use to open the file.
|
||||||
* @param int $lock Locking method to use.
|
* @param int $lock Locking method to use.
|
||||||
|
* @throws RuntimeException If the file could not be opened.
|
||||||
*/
|
*/
|
||||||
public function __construct(string $path, string $mode, int $lock) {
|
public function __construct(string $path, string $mode, int $lock) {
|
||||||
$this->lock = $lock;
|
$this->lock = $lock;
|
||||||
|
@ -122,11 +124,11 @@ class FileStream extends GenericStream {
|
||||||
try {
|
try {
|
||||||
$stream = fopen($path, $mode);
|
$stream = fopen($path, $mode);
|
||||||
} catch(ErrorException $ex) {
|
} catch(ErrorException $ex) {
|
||||||
throw new IOException('An error occurred while trying to open a file.', $ex->getCode(), $ex);
|
throw new RuntimeException('An error occurred while trying to open a file.', $ex->getCode(), $ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($stream === false)
|
if($stream === false)
|
||||||
throw new IOException('An unhandled error occurred while trying to open a file.');
|
throw new RuntimeException('An unhandled error occurred while trying to open a file.');
|
||||||
|
|
||||||
parent::__construct($stream);
|
parent::__construct($stream);
|
||||||
|
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
<?php
|
|
||||||
// IOException.php
|
|
||||||
// Created: 2021-04-30
|
|
||||||
// Updated: 2024-08-01
|
|
||||||
|
|
||||||
namespace Index\IO;
|
|
||||||
|
|
||||||
use RuntimeException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exception type for the Index\IO namespace.
|
|
||||||
*/
|
|
||||||
class IOException extends RuntimeException {}
|
|
|
@ -6,8 +6,8 @@
|
||||||
namespace Index\IO;
|
namespace Index\IO;
|
||||||
|
|
||||||
use ErrorException;
|
use ErrorException;
|
||||||
use Index\Net\IPAddress;
|
use RuntimeException;
|
||||||
use Index\Net\EndPoint;
|
use Index\Net\{IPAddress,EndPoint};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a network socket stream.
|
* Represents a network socket stream.
|
||||||
|
@ -17,17 +17,17 @@ class NetworkStream extends GenericStream {
|
||||||
* @param string $hostname Hostname to connect to.
|
* @param string $hostname Hostname to connect to.
|
||||||
* @param int $port Port to connect at.
|
* @param int $port Port to connect at.
|
||||||
* @param float|null $timeout Amount of seconds until timeout, null for php.ini default.
|
* @param float|null $timeout Amount of seconds until timeout, null for php.ini default.
|
||||||
* @throws IOException If the socket failed to open.
|
* @throws RuntimeException If the socket failed to open.
|
||||||
*/
|
*/
|
||||||
public function __construct(string $hostname, int $port, float|null $timeout) {
|
public function __construct(string $hostname, int $port, float|null $timeout) {
|
||||||
try {
|
try {
|
||||||
$stream = fsockopen($hostname, $port, $errcode, $errmsg, $timeout);
|
$stream = fsockopen($hostname, $port, $errcode, $errmsg, $timeout);
|
||||||
} catch(ErrorException $ex) {
|
} catch(ErrorException $ex) {
|
||||||
throw new IOException('An error occurred while trying to connect.', $ex->getCode(), $ex);
|
throw new RuntimeException('An error occurred while trying to connect.', $ex->getCode(), $ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($stream === false)
|
if($stream === false)
|
||||||
throw new IOException('An unhandled error occurred while trying to connect.');
|
throw new RuntimeException('An unhandled error occurred while trying to connect.');
|
||||||
|
|
||||||
parent::__construct($stream);
|
parent::__construct($stream);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
|
|
||||||
namespace Index\IO;
|
namespace Index\IO;
|
||||||
|
|
||||||
|
use RuntimeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a stream to a running sub-process.
|
* Represents a stream to a running sub-process.
|
||||||
*/
|
*/
|
||||||
|
@ -16,7 +18,7 @@ class ProcessStream extends Stream {
|
||||||
/**
|
/**
|
||||||
* @param string $command Command to run for this stream.
|
* @param string $command Command to run for this stream.
|
||||||
* @param string $mode File mode to use.
|
* @param string $mode File mode to use.
|
||||||
* @throws IOException If we were unable to spawn the process.
|
* @throws RuntimeException If we were unable to spawn the process.
|
||||||
*/
|
*/
|
||||||
public function __construct(string $command, string $mode) {
|
public function __construct(string $command, string $mode) {
|
||||||
$this->handle = popen($command, $mode);
|
$this->handle = popen($command, $mode);
|
||||||
|
@ -24,7 +26,7 @@ class ProcessStream extends Stream {
|
||||||
$this->canWrite = strpos($mode, 'w') !== false;
|
$this->canWrite = strpos($mode, 'w') !== false;
|
||||||
|
|
||||||
if(!is_resource($this->handle))
|
if(!is_resource($this->handle))
|
||||||
throw new IOException('Failed to create process.');
|
throw new RuntimeException('Failed to create process.');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPosition(): int {
|
public function getPosition(): int {
|
||||||
|
@ -80,7 +82,7 @@ class ProcessStream extends Stream {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function seek(int $offset, int $origin = self::START): bool {
|
public function seek(int $offset, int $origin = self::START): bool {
|
||||||
throw new IOException('Cannot seek ProcessStream.');
|
throw new RuntimeException('Cannot seek ProcessStream.');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function write(string $buffer, int $length = -1): void {
|
public function write(string $buffer, int $length = -1): void {
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
namespace Index\IO;
|
namespace Index\IO;
|
||||||
|
|
||||||
|
use RuntimeException;
|
||||||
use Stringable;
|
use Stringable;
|
||||||
use Index\ICloseable;
|
use Index\ICloseable;
|
||||||
|
|
||||||
|
@ -135,7 +136,7 @@ abstract class Stream implements Stringable, ICloseable {
|
||||||
*
|
*
|
||||||
* @param int $offset Offset to apply to the cursor position.
|
* @param int $offset Offset to apply to the cursor position.
|
||||||
* @param int $origin Point from which to apply the offset.
|
* @param int $origin Point from which to apply the offset.
|
||||||
* @throws IOException If the stream is not seekable.
|
* @throws RuntimeException If the stream is not seekable.
|
||||||
* @return bool true if the cursor offset was applied successfully.
|
* @return bool true if the cursor offset was applied successfully.
|
||||||
*/
|
*/
|
||||||
abstract public function seek(int $offset, int $origin = self::START): bool;
|
abstract public function seek(int $offset, int $origin = self::START): bool;
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
// CacheToolsTest.php
|
// CacheToolsTest.php
|
||||||
// Created: 2024-04-10
|
// Created: 2024-04-10
|
||||||
// Updated: 2024-07-31
|
// Updated: 2024-08-01
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use PHPUnit\Framework\Attributes\CoversClass;
|
use PHPUnit\Framework\Attributes\{CoversClass,UsesClass};
|
||||||
use PHPUnit\Framework\Attributes\UsesClass;
|
|
||||||
use Index\Cache\CacheTools;
|
use Index\Cache\CacheTools;
|
||||||
use Index\Cache\ArrayCache\{ArrayCacheBackend,ArrayCacheProvider};
|
use Index\Cache\ArrayCache\{ArrayCacheBackend,ArrayCacheProvider};
|
||||||
use Index\Cache\Memcached\MemcachedBackend;
|
use Index\Cache\Memcached\MemcachedBackend;
|
||||||
|
|
|
@ -1,17 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
// ColourTest.php
|
// ColourTest.php
|
||||||
// Created: 2023-01-02
|
// Created: 2023-01-02
|
||||||
// Updated: 2024-07-31
|
// Updated: 2024-08-01
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use PHPUnit\Framework\Attributes\CoversClass;
|
use PHPUnit\Framework\Attributes\CoversClass;
|
||||||
use Index\Colour\Colour;
|
use Index\Colour\{Colour,ColourHSL,ColourNamed,ColourNull,ColourRGB};
|
||||||
use Index\Colour\ColourHSL;
|
|
||||||
use Index\Colour\ColourNamed;
|
|
||||||
use Index\Colour\ColourNull;
|
|
||||||
use Index\Colour\ColourRGB;
|
|
||||||
|
|
||||||
#[CoversClass(Colour::class)]
|
#[CoversClass(Colour::class)]
|
||||||
#[CoversClass(ColourHSL::class)]
|
#[CoversClass(ColourHSL::class)]
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
// DbToolsTest.php
|
// DbToolsTest.php
|
||||||
// Created: 2021-04-28
|
// Created: 2021-04-28
|
||||||
// Updated: 2024-07-31
|
// Updated: 2024-08-01
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use PHPUnit\Framework\Attributes\CoversClass;
|
use PHPUnit\Framework\Attributes\{CoversClass,UsesClass};
|
||||||
use PHPUnit\Framework\Attributes\UsesClass;
|
use Index\Data\{DbTools,DbType};
|
||||||
use Index\Data\DbTools;
|
|
||||||
use Index\Data\DbType;
|
|
||||||
use Index\Data\MariaDB\MariaDBBackend;
|
use Index\Data\MariaDB\MariaDBBackend;
|
||||||
use Index\Data\NullDb\NullDbConnection;
|
use Index\Data\NullDb\NullDbConnection;
|
||||||
use Index\Data\SQLite\SQLiteBackend;
|
use Index\Data\SQLite\SQLiteBackend;
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
// IPAddressRangeTest.php
|
// IPAddressRangeTest.php
|
||||||
// Created: 2021-04-27
|
// Created: 2021-04-27
|
||||||
// Updated: 2024-07-31
|
// Updated: 2024-08-01
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use PHPUnit\Framework\Attributes\CoversClass;
|
use PHPUnit\Framework\Attributes\{CoversClass,UsesClass};
|
||||||
use PHPUnit\Framework\Attributes\UsesClass;
|
use Index\Net\{IPAddress,IPAddressRange};
|
||||||
use Index\Net\IPAddress;
|
|
||||||
use Index\Net\IPAddressRange;
|
|
||||||
|
|
||||||
#[CoversClass(IPAddressRange::class)]
|
#[CoversClass(IPAddressRange::class)]
|
||||||
#[UsesClass(IPAddress::class)]
|
#[UsesClass(IPAddress::class)]
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
// IndexTest.php
|
// IndexTest.php
|
||||||
// Created: 2021-05-02
|
// Created: 2021-05-02
|
||||||
// Updated: 2024-07-31
|
// Updated: 2024-08-01
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use PHPUnit\Framework\Attributes\CoversClass;
|
use PHPUnit\Framework\Attributes\{CoversClass,UsesClass};
|
||||||
use PHPUnit\Framework\Attributes\UsesClass;
|
|
||||||
use Index\Index;
|
use Index\Index;
|
||||||
|
|
||||||
#[CoversClass(Index::class)]
|
#[CoversClass(Index::class)]
|
||||||
|
|
Loading…
Reference in a new issue