From 44b44456645a7e6fea024c0ff0d3fb5bb28eebdb Mon Sep 17 00:00:00 2001 From: flashwave Date: Wed, 2 Oct 2024 02:05:40 +0000 Subject: [PATCH] HEH HEH YEAH ILIGHT HAHAHAHA WAHHH --- VERSION | 2 +- src/Bencode/Bencode.php | 2 +- ...rialisable.php => BencodeSerializable.php} | 4 +-- ...Trait.php => BencodeSerializableTrait.php} | 2 +- src/Cache/ArrayCache/ArrayCacheBackend.php | 10 +++--- src/Cache/ArrayCache/ArrayCacheProvider.php | 6 ++-- .../ArrayCache/ArrayCacheProviderInfo.php | 6 ++-- .../{ICacheBackend.php => CacheBackend.php} | 18 +++++------ .../{ICacheProvider.php => CacheProvider.php} | 8 ++--- ...ProviderInfo.php => CacheProviderInfo.php} | 6 ++-- src/Cache/CacheTools.php | 22 ++++++------- src/Cache/Memcached/MemcachedBackend.php | 10 +++--- src/Cache/Memcached/MemcachedProvider.php | 6 ++-- src/Cache/Memcached/MemcachedProviderInfo.php | 6 ++-- src/Cache/Valkey/ValkeyBackend.php | 10 +++--- src/Cache/Valkey/ValkeyProvider.php | 4 +-- src/Cache/Valkey/ValkeyProviderInfo.php | 4 +-- src/{ICloseable.php => Closeable.php} | 8 ++--- src/{IComparable.php => Comparable.php} | 6 ++-- src/Data/{IDbBackend.php => DbBackend.php} | 18 +++++------ .../{IDbConnection.php => DbConnection.php} | 16 +++++----- ...onnectionInfo.php => DbConnectionInfo.php} | 6 ++-- src/Data/{IDbResult.php => DbResult.php} | 8 ++--- src/Data/DbResultIterator.php | 12 +++---- src/Data/DbResultTrait.php | 4 +-- .../{IDbStatement.php => DbStatement.php} | 12 +++---- src/Data/DbStatementCache.php | 14 ++++---- src/Data/DbTools.php | 24 +++++++------- ...IDbTransactions.php => DbTransactions.php} | 6 ++-- src/Data/MariaDb/MariaDBBackend.php | 8 ++--- src/Data/MariaDb/MariaDBConnection.php | 4 +-- src/Data/MariaDb/MariaDBConnectionInfo.php | 4 +-- src/Data/MariaDb/MariaDBResult.php | 4 +-- src/Data/MariaDb/MariaDBStatement.php | 4 +-- src/Data/Migration/DbMigration.php | 20 ++++++++++++ ...bMigrationInfo.php => DbMigrationInfo.php} | 12 +++---- src/Data/Migration/DbMigrationManager.php | 22 ++++++------- ...bMigrationRepo.php => DbMigrationRepo.php} | 8 ++--- src/Data/Migration/FsDbMigrationInfo.php | 10 +++--- src/Data/Migration/FsDbMigrationRepo.php | 4 +-- src/Data/Migration/IDbMigration.php | 20 ------------ src/Data/NullDb/NullDbBackend.php | 10 +++--- src/Data/NullDb/NullDbConnection.php | 10 +++--- src/Data/NullDb/NullDbConnectionInfo.php | 6 ++-- src/Data/NullDb/NullDbResult.php | 4 +-- src/Data/NullDb/NullDbStatement.php | 8 ++--- src/Data/Sqlite/SqliteBackend.php | 8 ++--- src/Data/Sqlite/SqliteConnection.php | 8 ++--- src/Data/Sqlite/SqliteConnectionInfo.php | 4 +-- src/Data/Sqlite/SqliteResult.php | 4 +-- src/Data/Sqlite/SqliteStatement.php | 6 ++-- src/{IEquatable.php => Equatable.php} | 6 ++-- src/Http/Content/BencodedContent.php | 4 +-- src/Http/Content/FormContent.php | 2 +- .../{IHttpContent.php => HttpContent.php} | 6 ++-- src/Http/Content/JsonContent.php | 2 +- src/Http/Content/StreamContent.php | 2 +- src/Http/Content/StringContent.php | 4 +-- .../ContentHandling/BencodeContentHandler.php | 6 ++-- ...IContentHandler.php => ContentHandler.php} | 6 ++-- .../ContentHandling/JsonContentHandler.php | 4 +-- .../ContentHandling/StreamContentHandler.php | 2 +- .../{IErrorHandler.php => ErrorHandler.php} | 6 ++-- src/Http/ErrorHandling/HtmlErrorHandler.php | 2 +- src/Http/ErrorHandling/PlainErrorHandler.php | 4 +-- src/Http/HttpMessage.php | 10 +++--- src/Http/HttpMessageBuilder.php | 12 +++---- src/Http/HttpRequest.php | 8 ++--- src/Http/HttpResponse.php | 8 ++--- src/Http/HttpUploadedFile.php | 4 +-- src/Http/Routing/HandlerAttribute.php | 10 +++--- src/Http/Routing/HttpRouter.php | 32 +++++++++---------- src/Http/Routing/IRouteHandler.php | 18 ----------- src/Http/Routing/RouteHandler.php | 14 +++++--- src/Http/Routing/RouteHandlerTrait.php | 6 ++-- src/Http/Routing/{IRouter.php => Router.php} | 16 +++++----- src/Http/Routing/RouterTrait.php | 4 +-- src/Http/Routing/ScopedRouter.php | 12 +++---- src/Io/Stream.php | 4 +-- src/MediaType.php | 4 +-- src/Net/EndPoint.php | 4 +-- src/Net/IpAddress.php | 4 +-- src/Net/IpAddressRange.php | 4 +-- src/XArray.php | 6 ++-- tests/BencodeSerialisableTest.php | 14 ++++---- 85 files changed, 342 insertions(+), 356 deletions(-) rename src/Bencode/{IBencodeSerialisable.php => BencodeSerializable.php} (85%) rename src/Bencode/{BencodeSerialisableTrait.php => BencodeSerializableTrait.php} (99%) rename src/Cache/{ICacheBackend.php => CacheBackend.php} (62%) rename src/Cache/{ICacheProvider.php => CacheProvider.php} (95%) rename src/Cache/{ICacheProviderInfo.php => CacheProviderInfo.php} (71%) rename src/{ICloseable.php => Closeable.php} (74%) rename src/{IComparable.php => Comparable.php} (90%) rename src/Data/{IDbBackend.php => DbBackend.php} (59%) rename src/Data/{IDbConnection.php => DbConnection.php} (77%) rename src/Data/{IDbConnectionInfo.php => DbConnectionInfo.php} (72%) rename src/Data/{IDbResult.php => DbResult.php} (95%) rename src/Data/{IDbStatement.php => DbStatement.php} (89%) rename src/Data/{IDbTransactions.php => DbTransactions.php} (94%) create mode 100644 src/Data/Migration/DbMigration.php rename src/Data/Migration/{IDbMigrationInfo.php => DbMigrationInfo.php} (68%) rename src/Data/Migration/{IDbMigrationRepo.php => DbMigrationRepo.php} (63%) delete mode 100644 src/Data/Migration/IDbMigration.php rename src/{IEquatable.php => Equatable.php} (83%) rename src/Http/Content/{IHttpContent.php => HttpContent.php} (60%) rename src/Http/ContentHandling/{IContentHandler.php => ContentHandler.php} (90%) rename src/Http/ErrorHandling/{IErrorHandler.php => ErrorHandler.php} (90%) delete mode 100644 src/Http/Routing/IRouteHandler.php rename src/Http/Routing/{IRouter.php => Router.php} (88%) diff --git a/VERSION b/VERSION index ecff994..e512e30 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.2410.20136 +0.2410.20200 diff --git a/src/Bencode/Bencode.php b/src/Bencode/Bencode.php index 6622edd..bbd716c 100644 --- a/src/Bencode/Bencode.php +++ b/src/Bencode/Bencode.php @@ -59,7 +59,7 @@ final class Bencode { return $output . 'e'; case 'object': - if($value instanceof IBencodeSerializable) + if($value instanceof BencodeSerializable) return self::encode($value->bencodeSerialize(), $depth - 1); $value = get_object_vars($value); diff --git a/src/Bencode/IBencodeSerialisable.php b/src/Bencode/BencodeSerializable.php similarity index 85% rename from src/Bencode/IBencodeSerialisable.php rename to src/Bencode/BencodeSerializable.php index 50be7e7..bb5f458 100644 --- a/src/Bencode/IBencodeSerialisable.php +++ b/src/Bencode/BencodeSerializable.php @@ -1,5 +1,5 @@ $dsn DSN with provider information. * @return ArrayCacheProviderInfo Dummy provider info instance. */ - public function parseDsn(string|array $dsn): ICacheProviderInfo { + public function parseDsn(string|array $dsn): CacheProviderInfo { return new ArrayCacheProviderInfo; } } diff --git a/src/Cache/ArrayCache/ArrayCacheProvider.php b/src/Cache/ArrayCache/ArrayCacheProvider.php index eb6391f..de08f69 100644 --- a/src/Cache/ArrayCache/ArrayCacheProvider.php +++ b/src/Cache/ArrayCache/ArrayCacheProvider.php @@ -1,17 +1,17 @@ */ private array $items = []; diff --git a/src/Cache/ArrayCache/ArrayCacheProviderInfo.php b/src/Cache/ArrayCache/ArrayCacheProviderInfo.php index 3af897c..2dde5ae 100644 --- a/src/Cache/ArrayCache/ArrayCacheProviderInfo.php +++ b/src/Cache/ArrayCache/ArrayCacheProviderInfo.php @@ -1,13 +1,13 @@ $dsn DSN with provider information. - * @return ICacheProviderInfo Provider info based on the dsn. + * @return CacheProviderInfo Provider info based on the dsn. */ - function parseDsn(string|array $dsn): ICacheProviderInfo; + function parseDsn(string|array $dsn): CacheProviderInfo; } diff --git a/src/Cache/ICacheProvider.php b/src/Cache/CacheProvider.php similarity index 95% rename from src/Cache/ICacheProvider.php rename to src/Cache/CacheProvider.php index 0cc14a3..d66ab64 100644 --- a/src/Cache/ICacheProvider.php +++ b/src/Cache/CacheProvider.php @@ -1,16 +1,16 @@ $uri */ - private static function resolveBackend(array $uri): ICacheBackend { + private static function resolveBackend(array $uri): CacheBackend { static $backends = null; if(!is_array($backends)) $backends = []; @@ -51,7 +51,7 @@ final class CacheTools { $scheme = $uri['scheme']; $backend = $backends[$scheme] ?? null; - if(!($backend instanceof ICacheBackend)) { + if(!($backend instanceof CacheBackend)) { $backend = null; if(array_key_exists($scheme, self::CACHE_PROTOS)) @@ -59,7 +59,7 @@ final class CacheTools { else $name = str_replace('-', '\\', (string)$scheme); - if(class_exists($name) && is_subclass_of($name, ICacheBackend::class)) { + if(class_exists($name) && is_subclass_of($name, CacheBackend::class)) { $backend = new $name; $name = get_class($backend); } @@ -83,9 +83,9 @@ final class CacheTools { * @param string $dsn URL to create cache provider from. * @throws InvalidArgumentException if $dsn is not a valid URL. * @throws RuntimeException if no cache provider can be made using the URL. - * @return ICacheBackend Cache backend instance. + * @return CacheBackend Cache backend instance. */ - public static function backend(string $dsn): ICacheBackend { + public static function backend(string $dsn): CacheBackend { return self::resolveBackend(self::parseDsnUri($dsn)); } @@ -97,9 +97,9 @@ final class CacheTools { * @param string $dsn URL to create cache provider from. * @throws InvalidArgumentException if $dsn is not a valid URL. * @throws RuntimeException if no cache provider can be made using the URL. - * @return ICacheProviderInfo Cache provider info. + * @return CacheProviderInfo Cache provider info. */ - public static function parse(string $dsn): ICacheProviderInfo { + public static function parse(string $dsn): CacheProviderInfo { $uri = self::parseDsnUri($dsn); return self::resolveBackend($uri)->parseDsn($uri); } @@ -112,9 +112,9 @@ final class CacheTools { * @param string $dsn URL to create cache provider from. * @throws InvalidArgumentException if $dsn is not a valid URL. * @throws RuntimeException if no cache provider can be made using the URL. - * @return ICacheProvider A cache provider. + * @return CacheProvider A cache provider. */ - public static function create(string $dsn): ICacheProvider { + public static function create(string $dsn): CacheProvider { $uri = self::parseDsnUri($dsn); $backend = self::resolveBackend($uri); return $backend->createProvider($backend->parseDsn($uri)); diff --git a/src/Cache/Memcached/MemcachedBackend.php b/src/Cache/Memcached/MemcachedBackend.php index 29d7a15..6df5374 100644 --- a/src/Cache/Memcached/MemcachedBackend.php +++ b/src/Cache/Memcached/MemcachedBackend.php @@ -1,19 +1,19 @@ $dsn DSN with provider information. * @return MemcachedProviderInfo Memcached provider info instance. */ - public function parseDsn(string|array $dsn): ICacheProviderInfo { + public function parseDsn(string|array $dsn): CacheProviderInfo { if(is_string($dsn)) { $dsn = parse_url($dsn); if($dsn === false) diff --git a/src/Cache/Memcached/MemcachedProvider.php b/src/Cache/Memcached/MemcachedProvider.php index 6bef224..44847d4 100644 --- a/src/Cache/Memcached/MemcachedProvider.php +++ b/src/Cache/Memcached/MemcachedProvider.php @@ -1,16 +1,16 @@ $endPoints Memcached end points. * @param string $prefixKey Prefix to apply to keys. diff --git a/src/Cache/Valkey/ValkeyBackend.php b/src/Cache/Valkey/ValkeyBackend.php index 02cfb23..f5a71c0 100644 --- a/src/Cache/Valkey/ValkeyBackend.php +++ b/src/Cache/Valkey/ValkeyBackend.php @@ -1,13 +1,13 @@ $dsn DSN with provider information. * @return ValkeyProviderInfo Valkey provider info instance. */ - public function parseDsn(string|array $dsn): ICacheProviderInfo { + public function parseDsn(string|array $dsn): CacheProviderInfo { if(is_string($dsn)) { $dsn = parse_url($dsn); if($dsn === false) diff --git a/src/Cache/Valkey/ValkeyProvider.php b/src/Cache/Valkey/ValkeyProvider.php index 9129bf9..670b21d 100644 --- a/src/Cache/Valkey/ValkeyProvider.php +++ b/src/Cache/Valkey/ValkeyProvider.php @@ -7,13 +7,13 @@ namespace Index\Cache\Valkey; use InvalidArgumentException; use Redis; -use Index\Cache\ICacheProvider; +use Index\Cache\CacheProvider; use Index\Net\{DnsEndPoint,UnixEndPoint}; /** * Valkey provider implementation. */ -class ValkeyProvider implements ICacheProvider { +class ValkeyProvider implements CacheProvider { private Redis $redis; private bool $persist; diff --git a/src/Cache/Valkey/ValkeyProviderInfo.php b/src/Cache/Valkey/ValkeyProviderInfo.php index 7736b1e..c083dcb 100644 --- a/src/Cache/Valkey/ValkeyProviderInfo.php +++ b/src/Cache/Valkey/ValkeyProviderInfo.php @@ -7,13 +7,13 @@ namespace Index\Cache\Valkey; use InvalidArgumentException; use RuntimeException; -use Index\Cache\ICacheProviderInfo; +use Index\Cache\CacheProviderInfo; use Index\Net\{DnsEndPoint,EndPoint,IpEndPoint,UnixEndPoint}; /** * Represents Valkey provider info. */ -class ValkeyProviderInfo implements ICacheProviderInfo { +class ValkeyProviderInfo implements CacheProviderInfo { public function __construct( private EndPoint $endPoint, private string $prefix, diff --git a/src/ICloseable.php b/src/Closeable.php similarity index 74% rename from src/ICloseable.php rename to src/Closeable.php index fcf91ef..63b43ae 100644 --- a/src/ICloseable.php +++ b/src/Closeable.php @@ -1,14 +1,14 @@ * public function close(): void { @@ -22,7 +22,7 @@ namespace Index; * * However if close() is only implemented because a parent interface requires it, the __destruct() implementation may be omitted. */ -interface ICloseable { +interface Closeable { /** * Free, release or reset unmanaged resources. */ diff --git a/src/IComparable.php b/src/Comparable.php similarity index 90% rename from src/IComparable.php rename to src/Comparable.php index 41d1ad9..2459058 100644 --- a/src/IComparable.php +++ b/src/Comparable.php @@ -1,14 +1,14 @@ $dsn DSN with connection information. - * @return IDbConnectionInfo Connection info based on the dsn. + * @return DbConnectionInfo Connection info based on the dsn. */ - function parseDsn(string|array $dsn): IDbConnectionInfo; + function parseDsn(string|array $dsn): DbConnectionInfo; } diff --git a/src/Data/IDbConnection.php b/src/Data/DbConnection.php similarity index 77% rename from src/Data/IDbConnection.php rename to src/Data/DbConnection.php index d6f95d3..dc8591d 100644 --- a/src/Data/IDbConnection.php +++ b/src/Data/DbConnection.php @@ -1,16 +1,16 @@ */ @@ -18,13 +18,13 @@ class DbResultIterator implements Iterator { private object $current; /** - * Call this through an IDbResult instance instead! + * Call this through an DbResult instance instead! * - * @param IDbResult $result Result to operate on. - * @param callable(IDbResult): object $construct Constructor callback. + * @param DbResult $result Result to operate on. + * @param callable(DbResult): object $construct Constructor callback. */ public function __construct( - private IDbResult $result, + private DbResult $result, private $construct ) { if(!is_callable($construct)) diff --git a/src/Data/DbResultTrait.php b/src/Data/DbResultTrait.php index 7c62d03..2b78a74 100644 --- a/src/Data/DbResultTrait.php +++ b/src/Data/DbResultTrait.php @@ -1,12 +1,12 @@ */ + /** @var array */ private array $stmts = []; /** - * @param IDbConnection $dbConn Connection to use with this cache. + * @param DbConnection $dbConn Connection to use with this cache. */ public function __construct( - private IDbConnection $dbConn + private DbConnection $dbConn ) {} private static function hash(string $query): string { @@ -24,12 +24,12 @@ class DbStatementCache { } /** - * Gets a cached or creates a new IDbStatement instance. + * Gets a cached or creates a new DbStatement instance. * * @param string $query SQL query. - * @return IDbStatement Statement representing the query. + * @return DbStatement Statement representing the query. */ - public function get(string $query): IDbStatement { + public function get(string $query): DbStatement { $hash = self::hash($query); if(array_key_exists($hash, $this->stmts)) { diff --git a/src/Data/DbTools.php b/src/Data/DbTools.php index d74106c..992e532 100644 --- a/src/Data/DbTools.php +++ b/src/Data/DbTools.php @@ -17,7 +17,7 @@ use RuntimeException; * DbTools only handles the scheme part of the URL, * the rest of the URL is described in the documentation of the parseDsn implementation of the respective backend. * - * The scheme can be a PHP classpath to an implementation of IDbBackend, or any of these aliases: + * The scheme can be a PHP classpath to an implementation of DbBackend, or any of these aliases: * - `null`: maps to `NullDb\NullDbBackend` or `Index-Data-NullDb-NullDbBackend`, provides a fallback blackhole database backend. * - `mariadb`, `mysql`: maps to `MariaDb\MariaDbBackend` or `Index-Data-MariaDb-MariaDbBackend`, provides a backend based on the mysqli extension. * - `sqlite`, `sqlite3`: maps to `Sqlite\SqliteBackend` or `Index-Data-Sqlite-SqliteBackend`, provides a backend based on the sqlite3 extension. @@ -42,7 +42,7 @@ final class DbTools { } /** @param array $uri */ - private static function resolveBackend(array $uri): IDbBackend { + private static function resolveBackend(array $uri): DbBackend { static $backends = null; if(!is_array($backends)) $backends = []; @@ -50,7 +50,7 @@ final class DbTools { $scheme = $uri['scheme']; $backend = $backends[$scheme] ?? null; - if(!($backend instanceof IDbBackend)) { + if(!($backend instanceof DbBackend)) { $backend = null; if(array_key_exists($scheme, self::DB_PROTOS)) @@ -58,7 +58,7 @@ final class DbTools { else $name = str_replace('-', '\\', (string)$scheme); - if(class_exists($name) && is_subclass_of($name, IDbBackend::class)) { + if(class_exists($name) && is_subclass_of($name, DbBackend::class)) { $backend = new $name; $name = get_class($backend); } @@ -82,9 +82,9 @@ final class DbTools { * @param string $dsn URL to create database connection from. * @throws InvalidArgumentException if $dsn is not a valid URL. * @throws RuntimeException if no database connection can be made using the URL. - * @return IDbBackend Database backend instance. + * @return DbBackend Database backend instance. */ - public static function backend(string $dsn): IDbBackend { + public static function backend(string $dsn): DbBackend { return self::resolveBackend(self::parseDsnUri($dsn)); } @@ -96,9 +96,9 @@ final class DbTools { * @param string $dsn URL to create database connection from. * @throws InvalidArgumentException if $dsn is not a valid URL. * @throws RuntimeException if no database connection can be made using the URL. - * @return IDbConnectionInfo Database connection info. + * @return DbConnectionInfo Database connection info. */ - public static function parse(string $dsn): IDbConnectionInfo { + public static function parse(string $dsn): DbConnectionInfo { $uri = self::parseDsnUri($dsn); return self::resolveBackend($uri)->parseDsn($uri); } @@ -111,9 +111,9 @@ final class DbTools { * @param string $dsn URL to create database connection from. * @throws InvalidArgumentException if $dsn is not a valid URL. * @throws RuntimeException if no database connection can be made using the URL. - * @return IDbConnection An active database connection. + * @return DbConnection An active database connection. */ - public static function create(string $dsn): IDbConnection { + public static function create(string $dsn): DbConnection { $uri = self::parseDsnUri($dsn); $backend = self::resolveBackend($uri); return $backend->createConnection($backend->parseDsn($uri)); @@ -127,10 +127,10 @@ final class DbTools { * If the callable returns true, commit will be called. * If the callable returns false, rollback will be called. * - * @param IDbTransactions $connection A database connection with transaction support. + * @param DbTransactions $connection A database connection with transaction support. * @param callable $callable A callable that handles the transaction, may return a bool. */ - public static function transaction(IDbTransactions $connection, callable $callable): void { + public static function transaction(DbTransactions $connection, callable $callable): void { $connection->beginTransaction(); $result = $callable($connection) ?? null; if(is_bool($result)) { diff --git a/src/Data/IDbTransactions.php b/src/Data/DbTransactions.php similarity index 94% rename from src/Data/IDbTransactions.php rename to src/Data/DbTransactions.php index 59ee66a..be3ea46 100644 --- a/src/Data/IDbTransactions.php +++ b/src/Data/DbTransactions.php @@ -1,14 +1,14 @@ $dsn DSN with connection information. * @return MariaDbConnectionInfo MariaDB connection info. */ - public function parseDsn(string|array $dsn): IDbConnectionInfo { + public function parseDsn(string|array $dsn): DbConnectionInfo { if(is_string($dsn)) { $dsn = parse_url($dsn); if($dsn === false) diff --git a/src/Data/MariaDb/MariaDBConnection.php b/src/Data/MariaDb/MariaDBConnection.php index d911d0f..d982042 100644 --- a/src/Data/MariaDb/MariaDBConnection.php +++ b/src/Data/MariaDb/MariaDBConnection.php @@ -10,12 +10,12 @@ use mysqli_sql_exception; use stdClass; use InvalidArgumentException; use RuntimeException; -use Index\Data\{IDbConnection,IDbTransactions}; +use Index\Data\{DbConnection,DbTransactions}; /** * Represents a connection with a MariaDB or MySQL database server. */ -class MariaDbConnection implements IDbConnection, IDbTransactions { +class MariaDbConnection implements DbConnection, DbTransactions { /** * Refresh grant tables. * diff --git a/src/Data/MariaDb/MariaDBConnectionInfo.php b/src/Data/MariaDb/MariaDBConnectionInfo.php index 569dd2c..1c68529 100644 --- a/src/Data/MariaDb/MariaDBConnectionInfo.php +++ b/src/Data/MariaDb/MariaDBConnectionInfo.php @@ -6,13 +6,13 @@ namespace Index\Data\MariaDb; use InvalidArgumentException; -use Index\Data\IDbConnectionInfo; +use Index\Data\DbConnectionInfo; use Index\Net\{EndPoint,DnsEndPoint,IpEndPoint,UnixEndPoint}; /** * Describes a MariaDB or MySQL connection. */ -class MariaDbConnectionInfo implements IDbConnectionInfo { +class MariaDbConnectionInfo implements DbConnectionInfo { /** * Creates an instance of MariaDbConnectionInfo. * diff --git a/src/Data/MariaDb/MariaDBResult.php b/src/Data/MariaDb/MariaDBResult.php index 8c7ecbd..6d1a51d 100644 --- a/src/Data/MariaDb/MariaDBResult.php +++ b/src/Data/MariaDb/MariaDBResult.php @@ -8,13 +8,13 @@ namespace Index\Data\MariaDb; use mysqli_result; use mysqli_stmt; use InvalidArgumentException; -use Index\Data\{DbResultTrait,IDbResult}; +use Index\Data\{DbResult,DbResultTrait}; use Index\Io\{Stream,TempFileStream}; /** * Represents a MariaDB/MySQL database result. */ -abstract class MariaDbResult implements IDbResult { +abstract class MariaDbResult implements DbResult { use DbResultTrait; /** @var array */ diff --git a/src/Data/MariaDb/MariaDBStatement.php b/src/Data/MariaDb/MariaDBStatement.php index 8808f2f..221a479 100644 --- a/src/Data/MariaDb/MariaDBStatement.php +++ b/src/Data/MariaDb/MariaDBStatement.php @@ -8,13 +8,13 @@ namespace Index\Data\MariaDb; use mysqli_stmt; use InvalidArgumentException; use RuntimeException; -use Index\Data\{DbType,IDbStatement}; +use Index\Data\{DbType,DbStatement}; use Index\Io\Stream; /** * Represents a MariaDB/MySQL prepared statement. */ -class MariaDbStatement implements IDbStatement { +class MariaDbStatement implements DbStatement { /** @var array */ private array $params = []; diff --git a/src/Data/Migration/DbMigration.php b/src/Data/Migration/DbMigration.php new file mode 100644 index 0000000..fb1f690 --- /dev/null +++ b/src/Data/Migration/DbMigration.php @@ -0,0 +1,20 @@ +execute('CREATE TABLE ...'); } } EOF; - private ?IDbStatement $checkStmt = null; - private ?IDbStatement $insertStmt = null; + private ?DbStatement $checkStmt = null; + private ?DbStatement $insertStmt = null; /** - * @param IDbConnection $conn Connection to apply to migrations to. + * @param DbConnection $conn Connection to apply to migrations to. * @param string $tableName Name of the migration tracking table. */ public function __construct( - private IDbConnection $conn, + private DbConnection $conn, private string $tableName = self::DEFAULT_TABLE, ) {} @@ -209,10 +209,10 @@ EOF; /** * Runs all migrations present in a migration repository. This process is irreversible! * - * @param IDbMigrationRepo $migrations Migrations repository to fetch migrations from. + * @param DbMigrationRepo $migrations Migrations repository to fetch migrations from. * @return string[] Names of migrations that have been completed. */ - public function processMigrations(IDbMigrationRepo $migrations): array { + public function processMigrations(DbMigrationRepo $migrations): array { $migrations = $migrations->getMigrations(); $completed = []; diff --git a/src/Data/Migration/IDbMigrationRepo.php b/src/Data/Migration/DbMigrationRepo.php similarity index 63% rename from src/Data/Migration/IDbMigrationRepo.php rename to src/Data/Migration/DbMigrationRepo.php index 30efa7e..c03a77a 100644 --- a/src/Data/Migration/IDbMigrationRepo.php +++ b/src/Data/Migration/DbMigrationRepo.php @@ -1,18 +1,18 @@ className; } - public function migrate(IDbConnection $conn): void { + public function migrate(DbConnection $conn): void { require_once $this->path; $migration = new $this->className; - if($migration instanceof IDbMigration) + if($migration instanceof DbMigration) $migration->migrate($conn); } } diff --git a/src/Data/Migration/FsDbMigrationRepo.php b/src/Data/Migration/FsDbMigrationRepo.php index 2b23550..f9595a7 100644 --- a/src/Data/Migration/FsDbMigrationRepo.php +++ b/src/Data/Migration/FsDbMigrationRepo.php @@ -1,13 +1,13 @@ $dsn DSN with connection information. * @return NullDbConnectionInfo Dummy connection info instance. */ - public function parseDsn(string|array $dsn): IDbConnectionInfo { + public function parseDsn(string|array $dsn): DbConnectionInfo { return new NullDbConnectionInfo; } } diff --git a/src/Data/NullDb/NullDbConnection.php b/src/Data/NullDb/NullDbConnection.php index aee8cfa..facb4f6 100644 --- a/src/Data/NullDb/NullDbConnection.php +++ b/src/Data/NullDb/NullDbConnection.php @@ -1,16 +1,16 @@ $dsn DSN with connection information. * @return SqliteConnectionInfo SQLite connection info. */ - public function parseDsn(string|array $dsn): IDbConnectionInfo { + public function parseDsn(string|array $dsn): DbConnectionInfo { if(is_string($dsn)) { $dsn = parse_url($dsn); if($dsn === false) diff --git a/src/Data/Sqlite/SqliteConnection.php b/src/Data/Sqlite/SqliteConnection.php index b1ad476..d07fb2b 100644 --- a/src/Data/Sqlite/SqliteConnection.php +++ b/src/Data/Sqlite/SqliteConnection.php @@ -7,13 +7,13 @@ namespace Index\Data\Sqlite; use RuntimeException; use SQLite3; -use Index\Data\{IDbConnection,IDbTransactions,IDbStatement,IDbResult}; +use Index\Data\{DbConnection,DbTransactions,DbStatement,DbResult}; use Index\Io\{GenericStream,Stream}; /** * Represents a client for an SQLite database. */ -class SqliteConnection implements IDbConnection, IDbTransactions { +class SqliteConnection implements DbConnection, DbTransactions { /** * CREATE INDEX authorizer. * @@ -480,14 +480,14 @@ class SqliteConnection implements IDbConnection, IDbTransactions { return $this->connection->lastInsertRowID(); } - public function prepare(string $query): IDbStatement { + public function prepare(string $query): DbStatement { $statement = $this->connection->prepare($query); if($statement === false) throw new RuntimeException((string)$this->getLastErrorString(), $this->getLastErrorCode()); return new SqliteStatement($this, $statement); } - public function query(string $query): IDbResult { + public function query(string $query): DbResult { $result = $this->connection->query($query); if($result === false) throw new RuntimeException($this->getLastErrorString(), $this->getLastErrorCode()); diff --git a/src/Data/Sqlite/SqliteConnectionInfo.php b/src/Data/Sqlite/SqliteConnectionInfo.php index dce8276..7fee061 100644 --- a/src/Data/Sqlite/SqliteConnectionInfo.php +++ b/src/Data/Sqlite/SqliteConnectionInfo.php @@ -5,12 +5,12 @@ namespace Index\Data\Sqlite; -use Index\Data\IDbConnectionInfo; +use Index\Data\DbConnectionInfo; /** * Represents information about a SQLite Client. */ -class SqliteConnectionInfo implements IDbConnectionInfo { +class SqliteConnectionInfo implements DbConnectionInfo { /** * Creates a new SqliteConnectionInfo instance. * diff --git a/src/Data/Sqlite/SqliteResult.php b/src/Data/Sqlite/SqliteResult.php index 00fe497..916b788 100644 --- a/src/Data/Sqlite/SqliteResult.php +++ b/src/Data/Sqlite/SqliteResult.php @@ -7,13 +7,13 @@ namespace Index\Data\Sqlite; use SQLite3Result; use InvalidArgumentException; -use Index\Data\{DbResultTrait,IDbResult}; +use Index\Data\{DbResult,DbResultTrait}; use Index\Io\{Stream,TempFileStream}; /** * Represents an SQLite result set. */ -class SqliteResult implements IDbResult { +class SqliteResult implements DbResult { use DbResultTrait; /** @var array */ diff --git a/src/Data/Sqlite/SqliteStatement.php b/src/Data/Sqlite/SqliteStatement.php index c5b8e0d..8eac99b 100644 --- a/src/Data/Sqlite/SqliteStatement.php +++ b/src/Data/Sqlite/SqliteStatement.php @@ -9,13 +9,13 @@ use SQLite3Result; use SQLite3Stmt; use InvalidArgumentException; use RuntimeException; -use Index\Data\{DbTools,DbType,IDbStatement,IDbResult}; +use Index\Data\{DbTools,DbType,DbStatement,DbResult}; use Index\Io\Stream; /** * Represents a prepared SQLite SQL statement. */ -class SqliteStatement implements IDbStatement { +class SqliteStatement implements DbStatement { private ?SQLite3Result $result = null; private int $lastOrdinal = 1; @@ -73,7 +73,7 @@ class SqliteStatement implements IDbStatement { $this->bindParameter($this->lastOrdinal, $value, $type); } - public function getResult(): IDbResult { + public function getResult(): DbResult { if($this->result === null) throw new RuntimeException('No result is available.'); return new SqliteResult($this->result); diff --git a/src/IEquatable.php b/src/Equatable.php similarity index 83% rename from src/IEquatable.php rename to src/Equatable.php index 14f02b9..9314d6a 100644 --- a/src/IEquatable.php +++ b/src/Equatable.php @@ -1,14 +1,14 @@ $postFields Form fields. * @param array> $uploadedFiles Uploaded files. diff --git a/src/Http/Content/IHttpContent.php b/src/Http/Content/HttpContent.php similarity index 60% rename from src/Http/Content/IHttpContent.php rename to src/Http/Content/HttpContent.php index 23da171..6f017c9 100644 --- a/src/Http/Content/IHttpContent.php +++ b/src/Http/Content/HttpContent.php @@ -1,7 +1,7 @@ diff --git a/src/Http/ErrorHandling/PlainErrorHandler.php b/src/Http/ErrorHandling/PlainErrorHandler.php index 34f5678..bd65532 100644 --- a/src/Http/ErrorHandling/PlainErrorHandler.php +++ b/src/Http/ErrorHandling/PlainErrorHandler.php @@ -1,7 +1,7 @@ setTypePlain(); $response->setContent(sprintf('HTTP %03d %s', $code, $message)); diff --git a/src/Http/HttpMessage.php b/src/Http/HttpMessage.php index e7b53e6..147f046 100644 --- a/src/Http/HttpMessage.php +++ b/src/Http/HttpMessage.php @@ -7,7 +7,7 @@ namespace Index\Http; use RuntimeException; use Index\Io\Stream; -use Index\Http\Content\{IHttpContent,BencodedContent,FormContent,JsonContent,StreamContent,StringContent}; +use Index\Http\Content\{BencodedContent,FormContent,HttpContent,JsonContent,StreamContent,StringContent}; /** * Represents a base HTTP message. @@ -16,12 +16,12 @@ abstract class HttpMessage { /** * @param string $version HTTP message version. * @param HttpHeaders $headers HTTP message headers. - * @param ?IHttpContent $content Body contents. + * @param ?HttpContent $content Body contents. */ public function __construct( private string $version, private HttpHeaders $headers, - private ?IHttpContent $content + private ?HttpContent $content ) {} /** @@ -105,9 +105,9 @@ abstract class HttpMessage { /** * Retrieves message body contents, if present. * - * @return ?IHttpContent Body contents, null if none present. + * @return ?HttpContent Body contents, null if none present. */ - public function getContent(): ?IHttpContent { + public function getContent(): ?HttpContent { return $this->content; } diff --git a/src/Http/HttpMessageBuilder.php b/src/Http/HttpMessageBuilder.php index 687f41c..c012e04 100644 --- a/src/Http/HttpMessageBuilder.php +++ b/src/Http/HttpMessageBuilder.php @@ -6,7 +6,7 @@ namespace Index\Http; use Index\Io\Stream; -use Index\Http\Content\{IHttpContent,StreamContent,StringContent}; +use Index\Http\Content\{HttpContent,StreamContent,StringContent}; /** * Represents a base HTTP message builder. @@ -14,7 +14,7 @@ use Index\Http\Content\{IHttpContent,StreamContent,StringContent}; class HttpMessageBuilder { private ?string $version = null; private HttpHeadersBuilder $headers; - private ?IHttpContent $content = null; + private ?HttpContent $content = null; public function __construct() { $this->headers = new HttpHeadersBuilder; @@ -100,9 +100,9 @@ class HttpMessageBuilder { /** * Retrieves HTTP message body content. * - * @return ?IHttpContent Body content. + * @return ?HttpContent Body content. */ - protected function getContent(): ?IHttpContent { + protected function getContent(): ?HttpContent { return $this->content; } @@ -119,9 +119,9 @@ class HttpMessageBuilder { /** * Sets HTTP message body contents. * - * @param IHttpContent|Stream|string|null $content Body contents + * @param HttpContent|Stream|string|null $content Body contents */ - public function setContent(IHttpContent|Stream|string|null $content): void { + public function setContent(HttpContent|Stream|string|null $content): void { if($content instanceof Stream) $content = new StreamContent($content); elseif(is_string($content)) diff --git a/src/Http/HttpRequest.php b/src/Http/HttpRequest.php index 075be29..0e58989 100644 --- a/src/Http/HttpRequest.php +++ b/src/Http/HttpRequest.php @@ -1,14 +1,14 @@ $params HTTP request query parameters. * @param array $cookies HTTP request cookies. * @param HttpHeaders $headers HTTP message headers. - * @param ?IHttpContent $content Body contents. + * @param ?HttpContent $content Body contents. */ public function __construct( string $version, @@ -30,7 +30,7 @@ class HttpRequest extends HttpMessage { private array $params, private array $cookies, HttpHeaders $headers, - ?IHttpContent $content + ?HttpContent $content ) { parent::__construct($version, $headers, $content); } diff --git a/src/Http/HttpResponse.php b/src/Http/HttpResponse.php index aa0e569..6265f9f 100644 --- a/src/Http/HttpResponse.php +++ b/src/Http/HttpResponse.php @@ -1,11 +1,11 @@ getMethods(); diff --git a/src/Http/Routing/HttpRouter.php b/src/Http/Routing/HttpRouter.php index d1e6a8d..d3e419f 100644 --- a/src/Http/Routing/HttpRouter.php +++ b/src/Http/Routing/HttpRouter.php @@ -9,10 +9,10 @@ use stdClass; use InvalidArgumentException; use Index\Http\{HttpResponse,HttpResponseBuilder,HttpRequest}; use Index\Http\Content\StringContent; -use Index\Http\ContentHandling\{BencodeContentHandler,IContentHandler,JsonContentHandler,StreamContentHandler}; -use Index\Http\ErrorHandling\{HtmlErrorHandler,IErrorHandler,PlainErrorHandler}; +use Index\Http\ContentHandling\{BencodeContentHandler,ContentHandler,JsonContentHandler,StreamContentHandler}; +use Index\Http\ErrorHandling\{HtmlErrorHandler,ErrorHandler,PlainErrorHandler}; -class HttpRouter implements IRouter { +class HttpRouter implements Router { use RouterTrait; /** @var array{handler: callable, match?: string, prefix?: string}[] */ @@ -24,19 +24,19 @@ class HttpRouter implements IRouter { /** @var array> */ private array $dynamicRoutes = []; - /** @var IContentHandler[] */ + /** @var ContentHandler[] */ private array $contentHandlers = []; - private IErrorHandler $errorHandler; + private ErrorHandler $errorHandler; /** * @param string $charSet Default character set to specify when none is present. - * @param IErrorHandler|string $errorHandler Error handling to use for error responses with an empty body. 'html' for the default HTML implementation, 'plain' for the plaintext implementation. + * @param ErrorHandler|string $errorHandler Error handling to use for error responses with an empty body. 'html' for the default HTML implementation, 'plain' for the plaintext implementation. * @param bool $registerDefaultContentHandlers true to register default content handlers for JSON, Bencode, etc. */ public function __construct( private string $charSet = '', - IErrorHandler|string $errorHandler = 'html', + ErrorHandler|string $errorHandler = 'html', bool $registerDefaultContentHandlers = true, ) { $this->setErrorHandler($errorHandler); @@ -65,19 +65,19 @@ class HttpRouter implements IRouter { /** * Retrieves the error handler instance. * - * @return IErrorHandler The error handler. + * @return ErrorHandler The error handler. */ - public function getErrorHandler(): IErrorHandler { + public function getErrorHandler(): ErrorHandler { return $this->errorHandler; } /** * Changes the active error handler. * - * @param IErrorHandler|string $handler Error handling to use for error responses with an empty body. 'html' for the default HTML implementation, 'plain' for the plaintext implementation. + * @param ErrorHandler|string $handler Error handling to use for error responses with an empty body. 'html' for the default HTML implementation, 'plain' for the plaintext implementation. */ - public function setErrorHandler(IErrorHandler|string $handler): void { - if($handler instanceof IErrorHandler) + public function setErrorHandler(ErrorHandler|string $handler): void { + if($handler instanceof ErrorHandler) $this->errorHandler = $handler; elseif($handler === 'html') $this->setHTMLErrorHandler(); @@ -102,9 +102,9 @@ class HttpRouter implements IRouter { /** * Register a message body content handler. * - * @param IContentHandler $contentHandler Content handler to register. + * @param ContentHandler $contentHandler Content handler to register. */ - public function registerContentHandler(IContentHandler $contentHandler): void { + public function registerContentHandler(ContentHandler $contentHandler): void { if(!in_array($contentHandler, $this->contentHandlers)) $this->contentHandlers[] = $contentHandler; } @@ -122,9 +122,9 @@ class HttpRouter implements IRouter { * Retrieve a scoped router to a given path prefix. * * @param string $prefix Prefix to apply to paths within the returned router. - * @return IRouter Scopes router proxy. + * @return Router Scopes router proxy. */ - public function scopeTo(string $prefix): IRouter { + public function scopeTo(string $prefix): Router { return new ScopedRouter($this, $prefix); } diff --git a/src/Http/Routing/IRouteHandler.php b/src/Http/Routing/IRouteHandler.php deleted file mode 100644 index 35eeb95..0000000 --- a/src/Http/Routing/IRouteHandler.php +++ /dev/null @@ -1,18 +0,0 @@ -add('OPTIONS', $path, $handler); } - public function register(IRouteHandler $handler): void { + public function register(RouteHandler $handler): void { $handler->registerRoutes($this); } } diff --git a/src/Http/Routing/ScopedRouter.php b/src/Http/Routing/ScopedRouter.php index b3ca5b6..ac4bd42 100644 --- a/src/Http/Routing/ScopedRouter.php +++ b/src/Http/Routing/ScopedRouter.php @@ -1,22 +1,22 @@ router; } - public function scopeTo(string $prefix): IRouter { + public function scopeTo(string $prefix): Router { return $this->router->scopeTo($this->prefix . $prefix); } diff --git a/src/Io/Stream.php b/src/Io/Stream.php index 24dd3a5..e030684 100644 --- a/src/Io/Stream.php +++ b/src/Io/Stream.php @@ -7,12 +7,12 @@ namespace Index\Io; use RuntimeException; use Stringable; -use Index\ICloseable; +use Index\Closeable; /** * Represents a generic data stream. */ -abstract class Stream implements Stringable, ICloseable { +abstract class Stream implements Stringable, Closeable { /** * Place the cursor relative to the start of the file. * diff --git a/src/MediaType.php b/src/MediaType.php index dcff15e..ecee030 100644 --- a/src/MediaType.php +++ b/src/MediaType.php @@ -1,7 +1,7 @@ current(); $c2 = $iterator2->current(); - if($c1 instanceof IEquatable) { + if($c1 instanceof Equatable) { if(!$c1->equals($c2)) return false; - } elseif($c2 instanceof IEquatable) { + } elseif($c2 instanceof Equatable) { if(!$c2->equals($c1)) return false; } elseif($c1 !== $c2) diff --git a/tests/BencodeSerialisableTest.php b/tests/BencodeSerialisableTest.php index 1b7993b..ee01992 100644 --- a/tests/BencodeSerialisableTest.php +++ b/tests/BencodeSerialisableTest.php @@ -7,17 +7,17 @@ declare(strict_types=1); use PHPUnit\Framework\TestCase; use PHPUnit\Framework\Attributes\{CoversClass,UsesClass}; -use Index\Bencode\{Bencode,BencodeProperty,BencodeSerializableTrait,IBencodeSerializable}; +use Index\Bencode\{Bencode,BencodeProperty,BencodeSerializable,BencodeSerializableTrait}; #[CoversClass(BencodeProperty::class)] #[CoversClass(BencodeSerializableTrait::class)] #[UsesClass(Bencode::class)] -#[UsesClass(IBencodeSerializable::class)] +#[UsesClass(BencodeSerializable::class)] final class BencodeSerialisableTest extends TestCase { private const BASIC_BENCODED_ENCODED = 'd9:stringVal12:string value6:intVali1234e9:intStrVal4:56788:floatVal5:12.3411:floatStrVal5:56.787:trueVali1e22:truePossiblyOmittedVali1e8:falseVali0e14:nullValPresent10:scalarValsli0ei1234e5:12.343:stre16:stringVal_method12:string value9:getIntVali1234e11:getFloatVal5:12.3417:getFloatStringVal5:56.7810:getTrueVali1e25:getTruePossiblyOmittedVali1e11:getFalseVali0e17:getNullValPresent13:getScalarValsli0ei1234e5:12.343:stre5:innerd3:objd3:str21:wow this is illegibleee15:getIntStringVal4:5678e'; public function testBasicBencodedObject(): void { - $test = new class implements IBencodeSerializable { + $test = new class implements BencodeSerializable { use BencodeSerializableTrait; #[BencodeProperty] @@ -118,12 +118,12 @@ final class BencodeSerialisableTest extends TestCase { #[BencodeProperty('inner')] public function getObject(): object { - return new class implements IBencodeSerializable { + return new class implements BencodeSerializable { use BencodeSerializableTrait; #[BencodeProperty('obj')] public function getObject(): object { - return new class implements IBencodeSerializable { + return new class implements BencodeSerializable { use BencodeSerializableTrait; #[BencodeProperty('str')] @@ -150,7 +150,7 @@ final class BencodeSerialisableTest extends TestCase { public function testDoubleBencodedProperty(): void { $this->expectException(RuntimeException::class); - $test = new class implements IBencodeSerializable { + $test = new class implements BencodeSerializable { use BencodeSerializableTrait; #[BencodeProperty('test1')] @@ -170,7 +170,7 @@ final class BencodeSerialisableTest extends TestCase { public function testDuplicateBencodedProperty(): void { $this->expectException(RuntimeException::class); - $test = new class implements IBencodeSerializable { + $test = new class implements BencodeSerializable { use BencodeSerializableTrait; #[BencodeProperty]