Use compact use statements where possible and removed RuntimeException extensions.

This commit is contained in:
flash 2024-08-01 23:17:11 +00:00
parent 51f97b7a67
commit 50af08e54f
51 changed files with 138 additions and 316 deletions

View file

@ -1 +1 @@
0.2408.12215
0.2408.12316

View file

@ -7,9 +7,7 @@ namespace Index\Bencode;
use InvalidArgumentException;
use RuntimeException;
use Index\IO\GenericStream;
use Index\IO\Stream;
use Index\IO\TempFileStream;
use Index\IO\{GenericStream,Stream,TempFileStream};
/**
* Provides a Bencode serialiser.

View file

@ -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 {}

View file

@ -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 {}

View file

@ -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 {}

View file

@ -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 {}

View file

@ -1,12 +1,13 @@
<?php
// DbTools.php
// Created: 2021-05-02
// Updated: 2024-04-10
// Updated: 2024-08-01
namespace Index\Data;
use Countable;
use InvalidArgumentException;
use RuntimeException;
/**
* Common database actions.
@ -60,9 +61,9 @@ final class DbTools {
}
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())
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;
}
@ -77,7 +78,7 @@ final class DbTools {
*
* @param string $dsn URL to create database connection from.
* @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.
*/
public static function backend(string $dsn): IDbBackend {
@ -91,7 +92,7 @@ final class DbTools {
*
* @param string $dsn URL to create database connection from.
* @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.
*/
public static function parse(string $dsn): IDbConnectionInfo {
@ -106,7 +107,7 @@ final class DbTools {
*
* @param string $dsn URL to create database connection from.
* @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.
*/
public static function create(string $dsn): IDbConnection {

View file

@ -1,7 +1,7 @@
<?php
// IDbTransactions.php
// Created: 2021-05-02
// Updated: 2022-02-16
// Updated: 2024-08-01
namespace Index\Data;
@ -19,7 +19,7 @@ interface IDbTransactions extends IDbConnection {
/**
* Enters a transaction.
*
* @throws BeginTransactionFailedException If the creation of the transaction failed.
* @throws \RuntimeException If the creation of the transaction failed.
*/
function beginTransaction(): void;
@ -27,7 +27,7 @@ interface IDbTransactions extends IDbConnection {
* Commits the actions done during a transaction and ends the transaction.
* 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;
@ -35,7 +35,7 @@ interface IDbTransactions extends IDbConnection {
* 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.
* @throws RollbackFailedException If rollback failed.
* @throws \RuntimeException If rollback failed.
*/
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.
*
* @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;
@ -51,7 +51,7 @@ interface IDbTransactions extends IDbConnection {
* Releases a 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;
}

View file

@ -1,16 +1,13 @@
<?php
// MariaDBBackend.php
// Created: 2021-04-30
// Updated: 2024-07-31
// Updated: 2024-08-01
namespace Index\Data\MariaDB;
use InvalidArgumentException;
use Index\Data\IDbBackend;
use Index\Data\IDbConnection;
use Index\Data\IDbConnectionInfo;
use Index\Net\EndPoint;
use Index\Net\UnixEndPoint;
use Index\Data\{IDbBackend,IDbConnection,IDbConnectionInfo};
use Index\Net\{EndPoint,UnixEndPoint};
/**
* Information about the MariaDB/MySQL database layer.

View file

@ -1,7 +1,7 @@
<?php
// MariaDBConnection.php
// Created: 2021-04-30
// Updated: 2024-07-31
// Updated: 2024-08-01
namespace Index\Data\MariaDB;
@ -9,16 +9,7 @@ use mysqli;
use mysqli_sql_exception;
use InvalidArgumentException;
use RuntimeException;
use Index\Data\BeginTransactionFailedException;
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;
use Index\Data\{IDbConnection,IDbTransactions};
/**
* Represents a connection with a MariaDB or MySQL database server.
@ -146,7 +137,7 @@ class MariaDBConnection implements IDbConnection, IDbTransactions {
$flags
);
} 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 $password New password.
* @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 {
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.
*
* @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 {
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 {
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 {
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 {
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 {
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 {
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 {
$statement = $this->connection->prepare($query);
} catch(mysqli_sql_exception $ex) {
throw new QueryExecuteException($ex->getMessage(), $ex->getCode(), $ex);
throw new RuntimeException($ex->getMessage(), $ex->getCode(), $ex);
}
if($statement === false)
throw new QueryExecuteException($this->getLastErrorString(), $this->getLastErrorCode());
throw new RuntimeException($this->getLastErrorString(), $this->getLastErrorCode());
return new MariaDBStatement($statement);
}
@ -377,10 +368,10 @@ class MariaDBConnection implements IDbConnection, IDbTransactions {
try {
$result = $this->connection->query($query, MYSQLI_STORE_RESULT);
} catch(mysqli_sql_exception $ex) {
throw new QueryExecuteException($ex->getMessage(), $ex->getCode(), $ex);
throw new RuntimeException($ex->getMessage(), $ex->getCode(), $ex);
}
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
return new MariaDBResultNative($result);
}
@ -388,9 +379,9 @@ class MariaDBConnection implements IDbConnection, IDbTransactions {
public function execute(string $query): int|string {
try {
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) {
throw new QueryExecuteException($ex->getMessage(), $ex->getCode(), $ex);
throw new RuntimeException($ex->getMessage(), $ex->getCode(), $ex);
}
return $this->connection->affected_rows;
}

View file

@ -1,17 +1,13 @@
<?php
// MariaDBConnectionInfo.php
// Created: 2021-04-30
// Updated: 2022-02-28
// Updated: 2024-08-01
namespace Index\Data\MariaDB;
use InvalidArgumentException;
use Index\Data\IDbConnectionInfo;
use Index\Net\EndPoint;
use Index\Net\DnsEndPoint;
use Index\Net\IPAddress;
use Index\Net\IPEndPoint;
use Index\Net\UnixEndPoint;
use Index\Net\{EndPoint,DnsEndPoint,IPAddress,IPEndPoint,UnixEndPoint};
/**
* Describes a MariaDB or MySQL connection.

View file

@ -1,12 +1,11 @@
<?php
// MariaDBParameter.php
// Created: 2021-05-02
// Updated: 2022-02-02
// Updated: 2024-08-01
namespace Index\Data\MariaDB;
use Index\Data\DbTools;
use Index\Data\DbType;
use Index\Data\{DbTools,DbType};
/**
* Represents a bound parameter.

View file

@ -1,17 +1,15 @@
<?php
// MariaDBResult.php
// Created: 2021-05-02
// Updated: 2023-11-09
// Updated: 2024-08-01
namespace Index\Data\MariaDB;
use mysqli_result;
use mysqli_stmt;
use InvalidArgumentException;
use Index\Data\DbResultTrait;
use Index\Data\IDbResult;
use Index\IO\Stream;
use Index\IO\TempFileStream;
use Index\Data\{DbResultTrait,IDbResult};
use Index\IO\{Stream,TempFileStream};
/**
* Represents a MariaDB/MySQL database result.

View file

@ -1,12 +1,12 @@
<?php
// MariaDBResultLib.php
// Created: 2021-05-02
// Updated: 2023-07-10
// Updated: 2024-08-01
namespace Index\Data\MariaDB;
use mysqli_stmt;
use Index\Data\QueryExecuteException;
use RuntimeException;
/**
* Implementation of MariaDBResult for libmysql.
@ -21,7 +21,7 @@ class MariaDBResultLib extends MariaDBResult {
parent::__construct($statement);
if(!$statement->store_result())
throw new QueryExecuteException($statement->error, $statement->errno);
throw new RuntimeException($statement->error, $statement->errno);
$metadata = $statement->result_metadata();
while($field = $metadata->fetch_field())
@ -33,7 +33,7 @@ class MariaDBResultLib extends MariaDBResult {
public function next(): bool {
$result = $this->result->fetch();
if($result === false)
throw new QueryExecuteException($this->result->error, $this->result->errno);
throw new RuntimeException($this->result->error, $this->result->errno);
if($result === null)
return false;

View file

@ -1,13 +1,13 @@
<?php
// MariaDBResultNative.php
// Created: 2021-05-02
// Updated: 2023-07-10
// Updated: 2024-08-01
namespace Index\Data\MariaDB;
use mysqli_result;
use mysqli_stmt;
use Index\Data\QueryExecuteException;
use RuntimeException;
/**
* Implementation of MariaDBResult for mysqlnd.
@ -19,7 +19,7 @@ class MariaDBResultNative extends MariaDBResult {
if($result instanceof mysqli_stmt) {
$_result = $result->get_result();
if($_result === false)
throw new QueryExecuteException($result->error, $result->errno);
throw new RuntimeException($result->error, $result->errno);
$result = $_result;
}

View file

@ -1,16 +1,14 @@
<?php
// MariaDBStatement.php
// Created: 2021-05-02
// Updated: 2023-01-01
// Updated: 2024-08-01
namespace Index\Data\MariaDB;
use mysqli_stmt;
use InvalidArgumentException;
use RuntimeException;
use Index\Data\DbType;
use Index\Data\QueryExecuteException;
use Index\Data\IDbStatement;
use Index\Data\{DbType,IDbStatement};
use Index\IO\Stream;
/**
@ -144,13 +142,13 @@ class MariaDBStatement implements IDbStatement {
call_user_func_array([$this->statement, 'bind_param'], $args);
if(!$this->statement->execute())
throw new QueryExecuteException($this->getLastErrorString(), $this->getLastErrorCode());
throw new RuntimeException($this->getLastErrorString(), $this->getLastErrorCode());
}
public function reset(): void {
$this->params = [];
if(!$this->statement->reset())
throw new QueryExecuteException($this->getLastErrorString(), $this->getLastErrorCode());
throw new RuntimeException($this->getLastErrorString(), $this->getLastErrorCode());
}
public function close(): void {

View file

@ -10,9 +10,7 @@ use InvalidArgumentException;
use DateTimeImmutable;
use DateTimeInterface;
use Index\XDateTime;
use Index\Data\IDbConnection;
use Index\Data\IDbStatement;
use Index\Data\DbType;
use Index\Data\{IDbConnection,IDbStatement,DbType};
use Index\Data\SQLite\SQLiteConnection;
/**

View file

@ -1,13 +1,11 @@
<?php
// NullDbBackend.php
// Created: 2021-05-02
// Updated: 2024-04-10
// Updated: 2024-08-01
namespace Index\Data\NullDb;
use Index\Data\IDbBackend;
use Index\Data\IDbConnection;
use Index\Data\IDbConnectionInfo;
use Index\Data\{IDbBackend,IDbConnection,IDbConnectionInfo};
/**
* Information about the dummy database layer.

View file

@ -1,13 +1,11 @@
<?php
// NullDbConnection.php
// Created: 2021-05-02
// Updated: 2022-02-27
// Updated: 2024-08-01
namespace Index\Data\NullDb;
use Index\Data\IDbConnection;
use Index\Data\IDbStatement;
use Index\Data\IDbResult;
use Index\Data\{IDbConnection,IDbStatement,IDbResult};
/**
* Represents a dummy database connection.

View file

@ -1,12 +1,11 @@
<?php
// NullDbResult.php
// Created: 2021-05-02
// Updated: 2024-02-06
// Updated: 2024-08-01
namespace Index\Data\NullDb;
use Index\Data\IDbResult;
use Index\Data\DbResultIterator;
use Index\Data\{IDbResult,DbResultIterator};
use Index\IO\Stream;
/**

View file

@ -1,13 +1,11 @@
<?php
// NullDbStatement.php
// Created: 2021-05-02
// Updated: 2022-02-16
// Updated: 2024-08-01
namespace Index\Data\NullDb;
use Index\Data\DbType;
use Index\Data\IDbResult;
use Index\Data\IDbStatement;
use Index\Data\{DbType,IDbResult,IDbStatement};
/**
* Represents a dummy database statement.

View file

@ -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 {}

View file

@ -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 {}

View file

@ -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 {}

View file

@ -1,15 +1,13 @@
<?php
// SQLiteBackend.php
// Created: 2021-05-02
// Updated: 2024-07-31
// Updated: 2024-08-01
namespace Index\Data\SQLite;
use SQLite3;
use InvalidArgumentException;
use Index\Data\IDbBackend;
use Index\Data\IDbConnection;
use Index\Data\IDbConnectionInfo;
use Index\Data\{IDbBackend,IDbConnection,IDbConnectionInfo};
/**
* Information about the SQLite 3 database layer.

View file

@ -1,24 +1,13 @@
<?php
// SQLiteConnection.php
// Created: 2021-05-02
// Updated: 2022-02-27
// Updated: 2024-08-01
namespace Index\Data\SQLite;
use SQLite3;
use Index\Data\BeginTransactionFailedException;
use Index\Data\DataException;
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;
use Index\Data\{IDbConnection,IDbTransactions,IDbStatement,IDbResult};
use Index\IO\{GenericStream,Stream};
/**
* 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 $column Name of the source column.
* @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.
*/
public function getBlobStream(string $table, string $column, int $rowId): Stream {
$handle = $this->connection->openBlob($table, $column, $rowId);
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));
}
@ -497,20 +486,20 @@ class SQLiteConnection implements IDbConnection, IDbTransactions {
public function prepare(string $query): IDbStatement {
$statement = $this->connection->prepare($query);
if($statement === false)
throw new QueryExecuteException((string)$this->getLastErrorString(), $this->getLastErrorCode());
throw new RuntimeException((string)$this->getLastErrorString(), $this->getLastErrorCode());
return new SQLiteStatement($this, $statement);
}
public function query(string $query): IDbResult {
$result = $this->connection->query($query);
if($result === false)
throw new QueryExecuteException($this->getLastErrorString(), $this->getLastErrorCode());
throw new RuntimeException($this->getLastErrorString(), $this->getLastErrorCode());
return new SQLiteResult($result);
}
public function execute(string $query): int|string {
if(!$this->connection->exec($query))
throw new QueryExecuteException($this->getLastErrorString(), $this->getLastErrorCode());
throw new RuntimeException($this->getLastErrorString(), $this->getLastErrorCode());
return $this->connection->changes();
}
@ -529,31 +518,31 @@ class SQLiteConnection implements IDbConnection, IDbTransactions {
public function beginTransaction(): void {
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 {
if(!$this->connection->exec('COMMIT;'))
throw new CommitFailedException((string)$this->getLastErrorString(), $this->getLastErrorCode());
throw new RuntimeException((string)$this->getLastErrorString(), $this->getLastErrorCode());
if(!$this->autoCommit)
$this->beginTransaction();
}
public function rollback(?string $name = null): void {
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)
$this->beginTransaction();
}
public function savePoint(string $name): void {
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 {
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 {

View file

@ -1,16 +1,14 @@
<?php
// SQLiteResult.php
// Created: 2021-05-02
// Updated: 2023-11-09
// Updated: 2024-08-01
namespace Index\Data\SQLite;
use SQLite3Result;
use InvalidArgumentException;
use Index\Data\DbResultTrait;
use Index\Data\IDbResult;
use Index\IO\Stream;
use Index\IO\TempFileStream;
use Index\Data\{DbResultTrait,IDbResult};
use Index\IO\{Stream,TempFileStream};
/**
* Represents an SQLite result set.

View file

@ -1,7 +1,7 @@
<?php
// SQLiteStatement.php
// Created: 2021-05-02
// Updated: 2022-02-16
// Updated: 2024-08-01
namespace Index\Data\SQLite;
@ -9,11 +9,7 @@ use SQLite3Result;
use SQLite3Stmt;
use InvalidArgumentException;
use RuntimeException;
use Index\Data\DbTools;
use Index\Data\DbType;
use Index\Data\QueryExecuteException;
use Index\Data\IDbStatement;
use Index\Data\IDbResult;
use Index\Data\{DbTools,DbType,IDbStatement,IDbResult};
use Index\IO\Stream;
/**
@ -68,7 +64,7 @@ class SQLiteStatement implements IDbStatement {
}
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 {
@ -84,16 +80,16 @@ class SQLiteStatement implements IDbStatement {
public function execute(): void {
$result = $this->statement->execute();
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;
}
public function reset(): void {
$this->result = null;
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())
throw new QueryExecuteException((string)$this->connection->getLastErrorString(), $this->connection->getLastErrorCode());
throw new RuntimeException((string)$this->connection->getLastErrorString(), $this->connection->getLastErrorCode());
}
public function close(): void {}

View file

@ -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 {}

View file

@ -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 {}

View file

@ -5,10 +5,8 @@
namespace Index\Http\Content;
use Index\Bencode\Bencode;
use Index\Bencode\IBencodeSerialisable;
use Index\IO\Stream;
use Index\IO\FileStream;
use Index\Bencode\{Bencode,IBencodeSerialisable};
use Index\IO\{Stream,FileStream};
/**
* Represents Bencoded body content for a HTTP message.

View file

@ -6,8 +6,7 @@
namespace Index\Http\Content;
use JsonSerializable;
use Index\IO\Stream;
use Index\IO\FileStream;
use Index\IO\{Stream,FileStream};
/**
* Represents JSON body content for a HTTP message.

View file

@ -5,8 +5,7 @@
namespace Index\Http\Content;
use Index\IO\Stream;
use Index\IO\FileStream;
use Index\IO\{Stream,FileStream};
/**
* Represents Stream body content for a HTTP message.

View file

@ -5,8 +5,7 @@
namespace Index\Http\ErrorHandling;
use Index\Http\HttpResponseBuilder;
use Index\Http\HttpRequest;
use Index\Http\{HttpResponseBuilder,HttpRequest};
/**
* Represents an error message handler for building HTTP response messages.

View file

@ -7,12 +7,7 @@ namespace Index\Http;
use RuntimeException;
use Index\IO\Stream;
use Index\Http\Content\IHttpContent;
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;
use Index\Http\Content\{IHttpContent,BencodedContent,FormContent,JsonContent,StreamContent,StringContent};
/**
* Represents a base HTTP message.

View file

@ -6,9 +6,7 @@
namespace Index\Http;
use Index\IO\Stream;
use Index\Http\Content\IHttpContent;
use Index\Http\Content\StreamContent;
use Index\Http\Content\StringContent;
use Index\Http\Content\{IHttpContent,StreamContent,StringContent};
/**
* Represents a base HTTP message builder.

View file

@ -8,10 +8,7 @@ namespace Index\Http;
use InvalidArgumentException;
use RuntimeException;
use Index\MediaType;
use Index\Http\Content\IHttpContent;
use Index\Http\Content\JsonContent;
use Index\Http\Content\StreamContent;
use Index\Http\Content\FormContent;
use Index\Http\Content\{IHttpContent,JsonContent,StreamContent,FormContent};
/**
* Represents a HTTP request message.

View file

@ -6,9 +6,7 @@
namespace Index\Http;
use DateTimeInterface;
use Index\UrlEncoding;
use Index\MediaType;
use Index\XDateTime;
use Index\{UrlEncoding,MediaType,XDateTime};
use Index\Performance\Timings;
/**

View file

@ -5,12 +5,10 @@
namespace Index\Http;
use Index\MediaType;
use Index\ICloseable;
use Index\IO\Stream;
use Index\IO\FileStream;
use InvalidArgumentException;
use RuntimeException;
use Index\{MediaType,ICloseable};
use Index\IO\{Stream,FileStream};
/**
* Represents an uploaded file in a multipart/form-data request.

View file

@ -1,10 +1,13 @@
<?php
// RouterTrait.php
// Created: 2024-03-28
// Updated: 2024-03-28
// Updated: 2024-08-01
namespace Index\Http\Routing;
/**
* Contains implementations for HTTP request method handler registration.
*/
trait RouterTrait {
public function get(string $path, callable $handler): void {
$this->add('GET', $path, $handler);

View file

@ -1,16 +1,23 @@
<?php
// ScopedRouter.php
// Created: 2024-03-28
// Updated: 2024-03-28
// Updated: 2024-08-01
namespace Index\Http\Routing;
/**
* Provides a scoped router interface, automatically adds a prefix to any routes added.
*/
class ScopedRouter implements IRouter {
use RouterTrait;
private IRouter $router;
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) {
if($router instanceof ScopedRouter)
$router = $router->getParentRouter();

View file

@ -6,6 +6,7 @@
namespace Index\IO;
use ErrorException;
use RuntimeException;
/**
* Represents a Stream representing a file.
@ -115,6 +116,7 @@ class FileStream extends GenericStream {
* @param string $path Path to the file.
* @param string $mode Stream mode to use to open the file.
* @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) {
$this->lock = $lock;
@ -122,11 +124,11 @@ class FileStream extends GenericStream {
try {
$stream = fopen($path, $mode);
} 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)
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);

View file

@ -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 {}

View file

@ -6,8 +6,8 @@
namespace Index\IO;
use ErrorException;
use Index\Net\IPAddress;
use Index\Net\EndPoint;
use RuntimeException;
use Index\Net\{IPAddress,EndPoint};
/**
* Represents a network socket stream.
@ -17,17 +17,17 @@ class NetworkStream extends GenericStream {
* @param string $hostname Hostname to connect to.
* @param int $port Port to connect at.
* @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) {
try {
$stream = fsockopen($hostname, $port, $errcode, $errmsg, $timeout);
} 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)
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);
}

View file

@ -5,6 +5,8 @@
namespace Index\IO;
use RuntimeException;
/**
* 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 $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) {
$this->handle = popen($command, $mode);
@ -24,7 +26,7 @@ class ProcessStream extends Stream {
$this->canWrite = strpos($mode, 'w') !== false;
if(!is_resource($this->handle))
throw new IOException('Failed to create process.');
throw new RuntimeException('Failed to create process.');
}
public function getPosition(): int {
@ -80,7 +82,7 @@ class ProcessStream extends Stream {
}
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 {

View file

@ -5,6 +5,7 @@
namespace Index\IO;
use RuntimeException;
use Stringable;
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 $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.
*/
abstract public function seek(int $offset, int $origin = self::START): bool;

View file

@ -1,13 +1,12 @@
<?php
// CacheToolsTest.php
// Created: 2024-04-10
// Updated: 2024-07-31
// Updated: 2024-08-01
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\Attributes\{CoversClass,UsesClass};
use Index\Cache\CacheTools;
use Index\Cache\ArrayCache\{ArrayCacheBackend,ArrayCacheProvider};
use Index\Cache\Memcached\MemcachedBackend;

View file

@ -1,17 +1,13 @@
<?php
// ColourTest.php
// Created: 2023-01-02
// Updated: 2024-07-31
// Updated: 2024-08-01
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use Index\Colour\Colour;
use Index\Colour\ColourHSL;
use Index\Colour\ColourNamed;
use Index\Colour\ColourNull;
use Index\Colour\ColourRGB;
use Index\Colour\{Colour,ColourHSL,ColourNamed,ColourNull,ColourRGB};
#[CoversClass(Colour::class)]
#[CoversClass(ColourHSL::class)]

View file

@ -1,15 +1,13 @@
<?php
// DbToolsTest.php
// Created: 2021-04-28
// Updated: 2024-07-31
// Updated: 2024-08-01
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\UsesClass;
use Index\Data\DbTools;
use Index\Data\DbType;
use PHPUnit\Framework\Attributes\{CoversClass,UsesClass};
use Index\Data\{DbTools,DbType};
use Index\Data\MariaDB\MariaDBBackend;
use Index\Data\NullDb\NullDbConnection;
use Index\Data\SQLite\SQLiteBackend;

View file

@ -1,15 +1,13 @@
<?php
// IPAddressRangeTest.php
// Created: 2021-04-27
// Updated: 2024-07-31
// Updated: 2024-08-01
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\UsesClass;
use Index\Net\IPAddress;
use Index\Net\IPAddressRange;
use PHPUnit\Framework\Attributes\{CoversClass,UsesClass};
use Index\Net\{IPAddress,IPAddressRange};
#[CoversClass(IPAddressRange::class)]
#[UsesClass(IPAddress::class)]

View file

@ -1,13 +1,12 @@
<?php
// IndexTest.php
// Created: 2021-05-02
// Updated: 2024-07-31
// Updated: 2024-08-01
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\Attributes\{CoversClass,UsesClass};
use Index\Index;
#[CoversClass(Index::class)]