Fixed namespace and class casing.

This commit is contained in:
flash 2024-10-02 01:35:05 +00:00
parent 2217c8c3de
commit d9a7b04a3b
61 changed files with 457 additions and 456 deletions

View file

@ -20,13 +20,13 @@ The way each implementation stores data is NOT guaranteed to be compatible, plea
Requires the `redis` extension. Requires the `redis` extension.
Valkey is the name of the Linux Foundation's fork of Redis. Valkey is the name of the Linux Foundation's fork of Redis.
### `Index\Data\MariaDB` ### `Index\Data\MariaDb`
Requires the `mysqli` extension. Requires the `mysqli` extension.
`mysqlnd` is recommended as the underlying driver, but `libmysql` should work without a hitch. `mysqlnd` is recommended as the underlying driver, but `libmysql` should work without a hitch.
This driver also works for MySQL as the dependencies would suggest, but you should consider using MariaDB instead of possible. This driver also works for MySQL as the dependencies would suggest, but you should consider using MariaDB instead of possible.
### `Index\Data\SQLite` ### `Index\Data\Sqlite`
Requires the `sqlite3` extension. Requires the `sqlite3` extension.
@ -36,7 +36,7 @@ Requires the `sqlite3` extension.
Index versioning will mostly follow the [Semantic Versioning specification v2.0.0](https://semver.org/spec/v2.0.0.html), counting dropped support for a minor PHP version (e.g. 7.1 -> 7.2 or 7.4 -> 8.0) as a reason to increment the major version. Index versioning will mostly follow the [Semantic Versioning specification v2.0.0](https://semver.org/spec/v2.0.0.html), counting dropped support for a minor PHP version (e.g. 7.1 -> 7.2 or 7.4 -> 8.0) as a reason to increment the major version.
Previous major versions may be supported for a time with backports depending on what projects of mine still target older versions of PHP. Previous major versions may be supported for a time with backports depending on what projects of mine still target older versions of PHP.
The version is stored in the root of the repository in a file called `VERSION` and can be read out within Index using `Index\Environment::getIndexVersion()`. The version is stored in the root of the repository in a file called `VERSION` and can be read out within Index using `Index\Index::version()`.
## Contribution ## Contribution

View file

@ -1 +1 @@
0.2408.611934 0.2410.20133

View file

@ -13,8 +13,8 @@
"phpstan/phpstan": "^1.11" "phpstan/phpstan": "^1.11"
}, },
"suggest": { "suggest": {
"ext-mysqli": "Support for the Index\\Data\\MariaDB namespace (both mysqlnd and libmysql are supported).", "ext-mysqli": "Support for the Index\\Data\\MariaDb namespace (both mysqlnd and libmysql are supported).",
"ext-sqlite3": "Support for the Index\\Data\\SQLite namespace." "ext-sqlite3": "Support for the Index\\Data\\Sqlite namespace."
}, },
"authors": [ "authors": [
{ {

View file

@ -1,13 +1,13 @@
<?php <?php
// Bencode.php // Bencode.php
// Created: 2022-01-13 // Created: 2022-01-13
// Updated: 2024-08-18 // Updated: 2024-10-02
namespace Index\Bencode; namespace Index\Bencode;
use InvalidArgumentException; use InvalidArgumentException;
use RuntimeException; use RuntimeException;
use Index\IO\{GenericStream,Stream,TempFileStream}; use Index\Io\{GenericStream,Stream,TempFileStream};
/** /**
* Provides a Bencode serialiser. * Provides a Bencode serialiser.

View file

@ -1,13 +1,13 @@
<?php <?php
// MemcachedProviderLegacy.php // MemcachedProviderLegacy.php
// Created: 2024-04-10 // Created: 2024-04-10
// Updated: 2024-08-03 // Updated: 2024-10-02
namespace Index\Cache\Memcached; namespace Index\Cache\Memcached;
use InvalidArgumentException; use InvalidArgumentException;
use Memcache; use Memcache;
use Index\Net\{DnsEndPoint,IPEndPoint,UnixEndPoint}; use Index\Net\{DnsEndPoint,IpEndPoint,UnixEndPoint};
/** /**
* Legacy Memcached provider implementation. * Legacy Memcached provider implementation.
@ -31,7 +31,7 @@ class MemcachedProviderLegacy extends MemcachedProvider {
} elseif($endPointInfo[0] instanceof DnsEndPoint) { } elseif($endPointInfo[0] instanceof DnsEndPoint) {
$host = $endPointInfo[0]->getHost(); $host = $endPointInfo[0]->getHost();
$port = $endPointInfo[0]->getPort(); $port = $endPointInfo[0]->getPort();
} elseif($endPointInfo[0] instanceof IPEndPoint) { } elseif($endPointInfo[0] instanceof IpEndPoint) {
$host = $endPointInfo[0]->getAddress()->getCleanAddress(); $host = $endPointInfo[0]->getAddress()->getCleanAddress();
$port = $endPointInfo[0]->getPort(); $port = $endPointInfo[0]->getPort();
} else throw new InvalidArgumentException('One of the servers specified in $providerInfo is not a supported endpoint.'); } else throw new InvalidArgumentException('One of the servers specified in $providerInfo is not a supported endpoint.');

View file

@ -1,14 +1,14 @@
<?php <?php
// MemcachedProviderModern.php // MemcachedProviderModern.php
// Created: 2024-04-10 // Created: 2024-04-10
// Updated: 2024-08-03 // Updated: 2024-10-02
namespace Index\Cache\Memcached; namespace Index\Cache\Memcached;
use InvalidArgumentException; use InvalidArgumentException;
use Memcached; use Memcached;
use RuntimeException; use RuntimeException;
use Index\Net\{DnsEndPoint,IPEndPoint,UnixEndPoint}; use Index\Net\{DnsEndPoint,IpEndPoint,UnixEndPoint};
/** /**
* Base Memcached provider implementation. * Base Memcached provider implementation.
@ -30,7 +30,7 @@ class MemcachedProviderModern extends MemcachedProvider {
} elseif($endPointInfo[0] instanceof DnsEndPoint) { } elseif($endPointInfo[0] instanceof DnsEndPoint) {
$host = $endPointInfo[0]->getHost(); $host = $endPointInfo[0]->getHost();
$port = $endPointInfo[0]->getPort(); $port = $endPointInfo[0]->getPort();
} elseif($endPointInfo[0] instanceof IPEndPoint) { } elseif($endPointInfo[0] instanceof IpEndPoint) {
$host = $endPointInfo[0]->getAddress()->getCleanAddress(); $host = $endPointInfo[0]->getAddress()->getCleanAddress();
$port = $endPointInfo[0]->getPort(); $port = $endPointInfo[0]->getPort();
} else throw new InvalidArgumentException('One of the servers specified in $providerInfo is not a supported endpoint.'); } else throw new InvalidArgumentException('One of the servers specified in $providerInfo is not a supported endpoint.');

View file

@ -1,14 +1,14 @@
<?php <?php
// ValkeyProvider.php // ValkeyProvider.php
// Created: 2024-04-10 // Created: 2024-04-10
// Updated: 2024-08-04 // Updated: 2024-10-02
namespace Index\Cache\Valkey; namespace Index\Cache\Valkey;
use InvalidArgumentException; use InvalidArgumentException;
use Redis; use Redis;
use Index\Cache\ICacheProvider; use Index\Cache\ICacheProvider;
use Index\Net\{DnsEndPoint,IPEndPoint,UnixEndPoint}; use Index\Net\{DnsEndPoint,UnixEndPoint};
/** /**
* Valkey provider implementation. * Valkey provider implementation.

View file

@ -1,14 +1,14 @@
<?php <?php
// ValkeyProviderInfo.php // ValkeyProviderInfo.php
// Created: 2024-04-10 // Created: 2024-04-10
// Updated: 2024-04-10 // Updated: 2024-10-02
namespace Index\Cache\Valkey; namespace Index\Cache\Valkey;
use InvalidArgumentException; use InvalidArgumentException;
use RuntimeException; use RuntimeException;
use Index\Cache\ICacheProviderInfo; use Index\Cache\ICacheProviderInfo;
use Index\Net\{DnsEndPoint,EndPoint,IPEndPoint,UnixEndPoint}; use Index\Net\{DnsEndPoint,EndPoint,IpEndPoint,UnixEndPoint};
/** /**
* Represents Valkey provider info. * Represents Valkey provider info.
@ -43,7 +43,7 @@ class ValkeyProviderInfo implements ICacheProviderInfo {
return $this->endPoint->getPath(); return $this->endPoint->getPath();
if($this->endPoint instanceof DnsEndPoint) if($this->endPoint instanceof DnsEndPoint)
return $this->endPoint->getHost(); return $this->endPoint->getHost();
if($this->endPoint instanceof IPEndPoint) if($this->endPoint instanceof IpEndPoint)
return $this->endPoint->getAddress()->getCleanAddress(); return $this->endPoint->getAddress()->getCleanAddress();
throw new RuntimeException('EndPoint type is not supported.'); throw new RuntimeException('EndPoint type is not supported.');
@ -55,7 +55,7 @@ class ValkeyProviderInfo implements ICacheProviderInfo {
* @return int * @return int
*/ */
public function getServerPort(): int { public function getServerPort(): int {
if($this->endPoint instanceof DnsEndPoint || $this->endPoint instanceof IPEndPoint) if($this->endPoint instanceof DnsEndPoint || $this->endPoint instanceof IpEndPoint)
return $this->endPoint->getPort(); return $this->endPoint->getPort();
return 0; return 0;

View file

@ -1,7 +1,7 @@
<?php <?php
// Colour.php // Colour.php
// Created: 2023-01-02 // Created: 2023-01-02
// Updated: 2024-08-03 // Updated: 2024-10-02
namespace Index\Colour; namespace Index\Colour;
@ -122,7 +122,7 @@ abstract class Colour implements Stringable {
if($colour1->shouldInherit() || $colour2->shouldInherit()) if($colour1->shouldInherit() || $colour2->shouldInherit())
return self::none(); return self::none();
return new ColourRGB( return new ColourRgb(
(int)round(XNumber::weighted($colour2->getRed(), $colour1->getRed(), $weight)), (int)round(XNumber::weighted($colour2->getRed(), $colour1->getRed(), $weight)),
(int)round(XNumber::weighted($colour2->getGreen(), $colour1->getGreen(), $weight)), (int)round(XNumber::weighted($colour2->getGreen(), $colour1->getGreen(), $weight)),
(int)round(XNumber::weighted($colour2->getBlue(), $colour1->getBlue(), $weight)), (int)round(XNumber::weighted($colour2->getBlue(), $colour1->getBlue(), $weight)),
@ -136,7 +136,7 @@ abstract class Colour implements Stringable {
* Creates a Colour object from raw Misuzu format. * Creates a Colour object from raw Misuzu format.
* *
* If bit 31 is set the global instance of ColourNull will always be returned, * If bit 31 is set the global instance of ColourNull will always be returned,
* otherwise an instance of ColourRGB will be created using the fromRawRGB method (top 8 bits ignored). * otherwise an instance of ColourRgb will be created using the fromRawRgb method (top 8 bits ignored).
* *
* @param int $raw Raw RGB colour in Misuzu format. * @param int $raw Raw RGB colour in Misuzu format.
* @return Colour Colour instance representing the Misuzu colour. * @return Colour Colour instance representing the Misuzu colour.
@ -144,7 +144,7 @@ abstract class Colour implements Stringable {
public static function fromMisuzu(int $raw): Colour { public static function fromMisuzu(int $raw): Colour {
if($raw & self::MSZ_INHERIT) if($raw & self::MSZ_INHERIT)
return self::$none; return self::$none;
return ColourRGB::fromRawRGB($raw); return ColourRgb::fromRawRgb($raw);
} }
/** /**
@ -194,9 +194,9 @@ abstract class Colour implements Stringable {
} }
if($length === 6) if($length === 6)
return ColourRGB::fromRawRGB((int)hexdec($value)); return ColourRgb::fromRawRgb((int)hexdec($value));
if($length === 8) if($length === 8)
return ColourRGB::fromRawRGBA((int)hexdec($value)); return ColourRgb::fromRawRgba((int)hexdec($value));
} }
return self::$none; return self::$none;
@ -231,7 +231,7 @@ abstract class Colour implements Stringable {
]; ];
} }
return new ColourRGB(...$value); return new ColourRgb(...$value);
} }
if(str_starts_with($value, 'hsl(') || str_starts_with($value, 'hsla(')) { if(str_starts_with($value, 'hsl(') || str_starts_with($value, 'hsla(')) {
@ -297,7 +297,7 @@ abstract class Colour implements Stringable {
$alpha = (float)trim($alpha ?? '1'); $alpha = (float)trim($alpha ?? '1');
} }
return new ColourHSL($hue, $saturation, $lightness, $alpha); return new ColourHsl($hue, $saturation, $lightness, $alpha);
} }
return self::$none; return self::$none;

View file

@ -1,14 +1,14 @@
<?php <?php
// ColourHSL.php // ColourHsl.php
// Created: 2023-01-02 // Created: 2023-01-02
// Updated: 2024-08-01 // Updated: 2024-10-02
namespace Index\Colour; namespace Index\Colour;
/** /**
* Represents a colour using Hue, Saturation and Lightness. * Represents a colour using Hue, Saturation and Lightness.
*/ */
class ColourHSL extends Colour { class ColourHsl extends Colour {
private int $red; private int $red;
private int $green; private int $green;
private int $blue; private int $blue;
@ -121,13 +121,13 @@ class ColourHSL extends Colour {
} }
/** /**
* Converts any other colour to a ColourHSL. * Converts any other colour to a ColourHsl.
* *
* @param Colour $colour Original colour. * @param Colour $colour Original colour.
* @return ColourHSL Converted colour. * @return ColourHsl Converted colour.
*/ */
public static function convert(Colour $colour): ColourHSL { public static function convert(Colour $colour): ColourHsl {
if($colour instanceof ColourHSL) if($colour instanceof ColourHsl)
return $colour; return $colour;
$r = $colour->getRed() / 255.0; $r = $colour->getRed() / 255.0;
@ -155,7 +155,7 @@ class ColourHSL extends Colour {
} }
} }
return new ColourHSL( return new ColourHsl(
round($h, 3), round($h, 3),
round($s, 3), round($s, 3),
round($l, 3), round($l, 3),

View file

@ -1,14 +1,14 @@
<?php <?php
// ColourRGB.php // ColourRgb.php
// Created: 2023-01-02 // Created: 2023-01-02
// Updated: 2024-08-01 // Updated: 2024-10-02
namespace Index\Colour; namespace Index\Colour;
/** /**
* Represents an RGB colour. * Represents an RGB colour.
*/ */
class ColourRGB extends Colour { class ColourRgb extends Colour {
/** /**
* @param int $red Red property. * @param int $red Red property.
* @param int $green Green property. * @param int $green Green property.
@ -56,13 +56,13 @@ class ColourRGB extends Colour {
} }
/** /**
* Create a ColourRGB instance from a raw RGB value. * Create a ColourRgb instance from a raw RGB value.
* *
* @param int $raw A raw RGB colour in 0xRRGGBB format. * @param int $raw A raw RGB colour in 0xRRGGBB format.
* @return ColourRGB An instance of ColourRGB. * @return ColourRgb An instance of ColourRgb.
*/ */
public static function fromRawRGB(int $raw): ColourRGB { public static function fromRawRgb(int $raw): ColourRgb {
return new ColourRGB( return new ColourRgb(
(($raw >> 16) & 0xFF), (($raw >> 16) & 0xFF),
(($raw >> 8) & 0xFF), (($raw >> 8) & 0xFF),
($raw & 0xFF), ($raw & 0xFF),
@ -71,13 +71,13 @@ class ColourRGB extends Colour {
} }
/** /**
* Create a ColourRGB instance from a raw ARGB value. * Create a ColourRgb instance from a raw ARGB value.
* *
* @param int $raw A raw ARGB colour in 0xAARRGGBB format. * @param int $raw A raw ARGB colour in 0xAARRGGBB format.
* @return ColourRGB An instance of ColourRGB. * @return ColourRgb An instance of ColourRgb.
*/ */
public static function fromRawARGB(int $raw): ColourRGB { public static function fromRawArgb(int $raw): ColourRgb {
return new ColourRGB( return new ColourRgb(
(($raw >> 16) & 0xFF), (($raw >> 16) & 0xFF),
(($raw >> 8) & 0xFF), (($raw >> 8) & 0xFF),
($raw & 0xFF), ($raw & 0xFF),
@ -86,13 +86,13 @@ class ColourRGB extends Colour {
} }
/** /**
* Create a ColourRGB instance from a raw RGBA value. * Create a ColourRgb instance from a raw RGBA value.
* *
* @param int $raw A raw RGBA colour in 0xRRGGBBAA format. * @param int $raw A raw RGBA colour in 0xRRGGBBAA format.
* @return ColourRGB An instance of ColourRGB. * @return ColourRgb An instance of ColourRgb.
*/ */
public static function fromRawRGBA(int $raw): ColourRGB { public static function fromRawRgba(int $raw): ColourRgb {
return new ColourRGB( return new ColourRgb(
(($raw >> 24) & 0xFF), (($raw >> 24) & 0xFF),
(($raw >> 16) & 0xFF), (($raw >> 16) & 0xFF),
(($raw >> 8) & 0xFF), (($raw >> 8) & 0xFF),
@ -101,15 +101,15 @@ class ColourRGB extends Colour {
} }
/** /**
* Converts any other colour to a ColourRGB. * Converts any other colour to a ColourRgb.
* *
* @param Colour $colour Original colour. * @param Colour $colour Original colour.
* @return ColourRGB Converted colour. * @return ColourRgb Converted colour.
*/ */
public static function convert(Colour $colour): ColourRGB { public static function convert(Colour $colour): ColourRgb {
if($colour instanceof ColourRGB) if($colour instanceof ColourRgb)
return $colour; return $colour;
return new ColourRGB( return new ColourRgb(
$colour->getRed(), $colour->getRed(),
$colour->getGreen(), $colour->getGreen(),
$colour->getBlue(), $colour->getBlue(),

View file

@ -1,7 +1,7 @@
<?php <?php
// CSRFP.php // CsrfToken.php
// Created: 2021-06-11 // Created: 2021-06-11
// Updated: 2024-08-04 // Updated: 2024-10-02
namespace Index; namespace Index;
@ -10,7 +10,7 @@ use Index\UriBase64;
/** /**
* Contains a mechanism for validating requests. * Contains a mechanism for validating requests.
*/ */
class CSRFP { class CsrfToken {
private const TOLERANCE = 30 * 60; private const TOLERANCE = 30 * 60;
private const EPOCH = 1575158400; private const EPOCH = 1575158400;
private const HASH_ALGO = 'sha3-256'; private const HASH_ALGO = 'sha3-256';
@ -25,7 +25,7 @@ class CSRFP {
* @param string $secretKey Secret key for HMAC hashes. * @param string $secretKey Secret key for HMAC hashes.
* @param string $identity Unique identity component for these tokens. * @param string $identity Unique identity component for these tokens.
* @param int $tolerance Default amount of time a token should remain valid for. * @param int $tolerance Default amount of time a token should remain valid for.
* @return CSRFP New CSRFP instance. * @return CsrfToken New CsrfToken instance.
*/ */
public function __construct( public function __construct(
private string $secretKey, private string $secretKey,

View file

@ -1,7 +1,7 @@
<?php <?php
// DbTools.php // DbTools.php
// Created: 2021-05-02 // Created: 2021-05-02
// Updated: 2024-08-04 // Updated: 2024-10-02
namespace Index\Data; namespace Index\Data;
@ -19,18 +19,18 @@ use RuntimeException;
* *
* 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 IDbBackend, or any of these aliases:
* - `null`: maps to `NullDb\NullDbBackend` or `Index-Data-NullDb-NullDbBackend`, provides a fallback blackhole database backend. * - `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. * - `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. * - `sqlite`, `sqlite3`: maps to `Sqlite\SqliteBackend` or `Index-Data-Sqlite-SqliteBackend`, provides a backend based on the sqlite3 extension.
* *
* Short names are currently hardcoded and cannot be expanded. * Short names are currently hardcoded and cannot be expanded.
*/ */
final class DbTools { final class DbTools {
private const DB_PROTOS = [ private const DB_PROTOS = [
'null' => NullDb\NullDbBackend::class, 'null' => NullDb\NullDbBackend::class,
'mariadb' => MariaDB\MariaDBBackend::class, 'mariadb' => MariaDb\MariaDbBackend::class,
'mysql' => MariaDB\MariaDBBackend::class, 'mysql' => MariaDb\MariaDbBackend::class,
'sqlite' => SQLite\SQLiteBackend::class, 'sqlite' => Sqlite\SqliteBackend::class,
'sqlite3' => SQLite\SQLiteBackend::class, 'sqlite3' => Sqlite\SqliteBackend::class,
]; ];
/** @return array<string, string|int> */ /** @return array<string, string|int> */

View file

@ -1,12 +1,12 @@
<?php <?php
// IDbResult.php // IDbResult.php
// Created: 2021-05-02 // Created: 2021-05-02
// Updated: 2024-02-06 // Updated: 2024-10-02
namespace Index\Data; namespace Index\Data;
use Index\ICloseable; use Index\ICloseable;
use Index\IO\Stream; use Index\Io\Stream;
/** /**
* Represents a database result set. * Represents a database result set.

View file

@ -1,9 +1,9 @@
<?php <?php
// MariaDBBackend.php // MariaDBBackend.php
// Created: 2021-04-30 // Created: 2021-04-30
// Updated: 2024-08-03 // Updated: 2024-10-02
namespace Index\Data\MariaDB; namespace Index\Data\MariaDb;
use InvalidArgumentException; use InvalidArgumentException;
use Index\Data\{IDbBackend,IDbConnection,IDbConnectionInfo}; use Index\Data\{IDbBackend,IDbConnection,IDbConnectionInfo};
@ -12,7 +12,7 @@ use Index\Net\{EndPoint,UnixEndPoint};
/** /**
* Information about the MariaDB/MySQL database layer. * Information about the MariaDB/MySQL database layer.
*/ */
class MariaDBBackend implements IDbBackend { class MariaDbBackend implements IDbBackend {
public function isAvailable(): bool { public function isAvailable(): bool {
return extension_loaded('mysqli'); return extension_loaded('mysqli');
} }
@ -41,14 +41,14 @@ class MariaDBBackend implements IDbBackend {
/** /**
* Creates a connection with a MariaDB or MySQL server. * Creates a connection with a MariaDB or MySQL server.
* *
* @param MariaDBConnectionInfo $connectionInfo Object that describes the desired connection. * @param MariaDbConnectionInfo $connectionInfo Object that describes the desired connection.
* @return MariaDBConnection A connection with a MariaDB or MySQL server. * @return MariaDbConnection A connection with a MariaDB or MySQL server.
*/ */
public function createConnection(IDbConnectionInfo $connectionInfo): IDbConnection { public function createConnection(IDbConnectionInfo $connectionInfo): IDbConnection {
if(!($connectionInfo instanceof MariaDBConnectionInfo)) if(!($connectionInfo instanceof MariaDbConnectionInfo))
throw new InvalidArgumentException('$connectionInfo must by of type MariaDBConnectionInfo'); throw new InvalidArgumentException('$connectionInfo must by of type MariaDbConnectionInfo');
return new MariaDBConnection($connectionInfo); return new MariaDbConnection($connectionInfo);
} }
/** /**
@ -78,7 +78,7 @@ class MariaDBBackend implements IDbBackend {
* - `enc_verify=<anything>`: Enabled verification of server certificate. Replaced with `enc_no_verify` as it now defaults to on. * - `enc_verify=<anything>`: Enabled verification of server certificate. Replaced with `enc_no_verify` as it now defaults to on.
* *
* @param string|array<string, int|string> $dsn DSN with connection information. * @param string|array<string, int|string> $dsn DSN with connection information.
* @return MariaDBConnectionInfo MariaDB connection info. * @return MariaDbConnectionInfo MariaDB connection info.
*/ */
public function parseDsn(string|array $dsn): IDbConnectionInfo { public function parseDsn(string|array $dsn): IDbConnectionInfo {
if(is_string($dsn)) { if(is_string($dsn)) {
@ -141,7 +141,7 @@ class MariaDBBackend implements IDbBackend {
if($endPoint === null) if($endPoint === null)
throw new InvalidArgumentException('No end point could be determined from the provided DSN.'); throw new InvalidArgumentException('No end point could be determined from the provided DSN.');
return new MariaDBConnectionInfo( return new MariaDbConnectionInfo(
$endPoint, $user, $pass, $dbName, $endPoint, $user, $pass, $dbName,
$charSet, $initCommand, $keyPath, $certPath, $charSet, $initCommand, $keyPath, $certPath,
$certAuthPath, $trustedCertsPath, $cipherAlgos, $certAuthPath, $trustedCertsPath, $cipherAlgos,

View file

@ -1,21 +1,21 @@
<?php <?php
// MariaDBCharacterSetInfo.php // MariaDBCharacterSetInfo.php
// Created: 2021-05-02 // Created: 2021-05-02
// Updated: 2024-08-04 // Updated: 2024-10-02
namespace Index\Data\MariaDB; namespace Index\Data\MariaDb;
/** /**
* Contains information about the character set. * Contains information about the character set.
* *
* @see https://www.php.net/manual/en/mysqli.get-charset * @see https://www.php.net/manual/en/mysqli.get-charset
*/ */
class MariaDBCharacterSetInfo { class MariaDbCharacterSetInfo {
/** /**
* Creates a new character set info instance. * Creates a new character set info instance.
* *
* @param object $charSet Anonymous object containing the information. * @param object $charSet Anonymous object containing the information.
* @return MariaDBCharacterSetInfo Character set information class. * @return MariaDbCharacterSetInfo Character set information class.
*/ */
public function __construct( public function __construct(
private object $charSet private object $charSet

View file

@ -1,9 +1,9 @@
<?php <?php
// MariaDBConnection.php // MariaDBConnection.php
// Created: 2021-04-30 // Created: 2021-04-30
// Updated: 2024-09-13 // Updated: 2024-10-02
namespace Index\Data\MariaDB; namespace Index\Data\MariaDb;
use mysqli; use mysqli;
use mysqli_sql_exception; use mysqli_sql_exception;
@ -15,7 +15,7 @@ use Index\Data\{IDbConnection,IDbTransactions};
/** /**
* Represents a connection with a MariaDB or MySQL database server. * Represents a connection with a MariaDB or MySQL database server.
*/ */
class MariaDBConnection implements IDbConnection, IDbTransactions { class MariaDbConnection implements IDbConnection, IDbTransactions {
/** /**
* Refresh grant tables. * Refresh grant tables.
* *
@ -75,12 +75,12 @@ class MariaDBConnection implements IDbConnection, IDbTransactions {
private mysqli $connection; private mysqli $connection;
/** /**
* Creates a new instance of MariaDBConnection. * Creates a new instance of MariaDbConnection.
* *
* @param MariaDBConnectionInfo $connectionInfo Information about the connection. * @param MariaDbConnectionInfo $connectionInfo Information about the connection.
* @return MariaDBConnection A new instance of MariaDBConnection. * @return MariaDbConnection A new instance of MariaDbConnection.
*/ */
public function __construct(MariaDBConnectionInfo $connectionInfo) { public function __construct(MariaDbConnectionInfo $connectionInfo) {
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
// I'm not sure if calling "new mysqli" without arguments is equivalent to this // I'm not sure if calling "new mysqli" without arguments is equivalent to this
@ -173,10 +173,10 @@ class MariaDBConnection implements IDbConnection, IDbTransactions {
/** /**
* Returns info about the currently character set and collation. * Returns info about the currently character set and collation.
* *
* @return MariaDBCharacterSetInfo Information about the character set. * @return MariaDbCharacterSetInfo Information about the character set.
*/ */
public function getCharacterSetInfo(): MariaDBCharacterSetInfo { public function getCharacterSetInfo(): MariaDbCharacterSetInfo {
return new MariaDBCharacterSetInfo($this->connection->get_charset()); return new MariaDbCharacterSetInfo($this->connection->get_charset());
} }
/** /**
@ -209,7 +209,7 @@ class MariaDBConnection implements IDbConnection, IDbTransactions {
* @return string Version of the server. * @return string Version of the server.
*/ */
public function getServerVersion(): string { public function getServerVersion(): string {
return MariaDBBackend::intToVersion($this->connection->server_version); return MariaDbBackend::intToVersion($this->connection->server_version);
} }
/** /**
@ -242,13 +242,13 @@ class MariaDBConnection implements IDbConnection, IDbTransactions {
/** /**
* Gets a list of errors from the last command. * Gets a list of errors from the last command.
* *
* @return MariaDBWarning[] List of last errors. * @return MariaDbWarning[] List of last errors.
*/ */
public function getLastErrors(): array { public function getLastErrors(): array {
// imagine if stdlib stuff had type annotations, couldn't be me // imagine if stdlib stuff had type annotations, couldn't be me
/** @var array<int, array{errno: int, sqlstate: string, error: string}> */ /** @var array<int, array{errno: int, sqlstate: string, error: string}> */
$errorList = $this->connection->error_list; $errorList = $this->connection->error_list;
return MariaDBWarning::fromLastErrors($errorList); return MariaDbWarning::fromLastErrors($errorList);
} }
/** /**
@ -265,10 +265,10 @@ class MariaDBConnection implements IDbConnection, IDbTransactions {
* *
* The result of SHOW WARNINGS; * The result of SHOW WARNINGS;
* *
* @return MariaDBWarning[] List of warnings. * @return MariaDbWarning[] List of warnings.
*/ */
public function getWarnings(): array { public function getWarnings(): array {
return MariaDBWarning::fromGetWarnings($this->connection->get_warnings()); return MariaDbWarning::fromGetWarnings($this->connection->get_warnings());
} }
/** /**
@ -351,9 +351,9 @@ class MariaDBConnection implements IDbConnection, IDbTransactions {
} }
/** /**
* @return MariaDBStatement A database statement. * @return MariaDbStatement A database statement.
*/ */
public function prepare(string $query): MariaDBStatement { public function prepare(string $query): MariaDbStatement {
try { try {
$statement = $this->connection->prepare($query); $statement = $this->connection->prepare($query);
} catch(mysqli_sql_exception $ex) { } catch(mysqli_sql_exception $ex) {
@ -361,13 +361,13 @@ class MariaDBConnection implements IDbConnection, IDbTransactions {
} }
if($statement === false) if($statement === false)
throw new RuntimeException($this->getLastErrorString(), $this->getLastErrorCode()); throw new RuntimeException($this->getLastErrorString(), $this->getLastErrorCode());
return new MariaDBStatement($statement); return new MariaDbStatement($statement);
} }
/** /**
* @return MariaDBResult A database result. * @return MariaDbResult A database result.
*/ */
public function query(string $query): MariaDBResult { public function query(string $query): MariaDbResult {
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) {
@ -382,7 +382,7 @@ class MariaDBConnection implements IDbConnection, IDbTransactions {
throw new RuntimeException('Query succeeded but you should have use the execute method for that query.'); throw new RuntimeException('Query succeeded but you should have use the execute method for that query.');
// 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);
} }
public function execute(string $query): int|string { public function execute(string $query): int|string {

View file

@ -1,20 +1,20 @@
<?php <?php
// MariaDBConnectionInfo.php // MariaDBConnectionInfo.php
// Created: 2021-04-30 // Created: 2021-04-30
// Updated: 2024-08-01 // Updated: 2024-10-02
namespace Index\Data\MariaDB; namespace Index\Data\MariaDb;
use InvalidArgumentException; use InvalidArgumentException;
use Index\Data\IDbConnectionInfo; use Index\Data\IDbConnectionInfo;
use Index\Net\{EndPoint,DnsEndPoint,IPAddress,IPEndPoint,UnixEndPoint}; use Index\Net\{EndPoint,DnsEndPoint,IpEndPoint,UnixEndPoint};
/** /**
* Describes a MariaDB or MySQL connection. * Describes a MariaDB or MySQL connection.
*/ */
class MariaDBConnectionInfo implements IDbConnectionInfo { class MariaDbConnectionInfo implements IDbConnectionInfo {
/** /**
* Creates an instance of MariaDBConnectionInfo. * Creates an instance of MariaDbConnectionInfo.
* *
* @param EndPoint $endPoint End point at which the server can be found. * @param EndPoint $endPoint End point at which the server can be found.
* @param string $userName User name to use for the connection. * @param string $userName User name to use for the connection.
@ -29,7 +29,7 @@ class MariaDBConnectionInfo implements IDbConnectionInfo {
* @param string|null $cipherAlgos List of SSL encryption cipher that are allowed. * @param string|null $cipherAlgos List of SSL encryption cipher that are allowed.
* @param bool $verifyCert true if the client should verify the server's SSL certificate, false if not. * @param bool $verifyCert true if the client should verify the server's SSL certificate, false if not.
* @param bool $useCompression true if compression should be used, false if not. * @param bool $useCompression true if compression should be used, false if not.
* @return MariaDBConnectionInfo A connection info instance representing the given information. * @return MariaDbConnectionInfo A connection info instance representing the given information.
*/ */
public function __construct( public function __construct(
private EndPoint $endPoint, private EndPoint $endPoint,
@ -46,10 +46,10 @@ class MariaDBConnectionInfo implements IDbConnectionInfo {
private bool $verifyCert, private bool $verifyCert,
private bool $useCompression private bool $useCompression
) { ) {
if(!($endPoint instanceof IPEndPoint) if(!($endPoint instanceof IpEndPoint)
&& !($endPoint instanceof DnsEndPoint) && !($endPoint instanceof DnsEndPoint)
&& !($endPoint instanceof UnixEndPoint)) && !($endPoint instanceof UnixEndPoint))
throw new InvalidArgumentException('$endPoint must be of type IPEndPoint, DnsEndPoint or UnixEndPoint.'); throw new InvalidArgumentException('$endPoint must be of type IpEndPoint, DnsEndPoint or UnixEndPoint.');
if(empty($charSet)) if(empty($charSet))
$charSet = null; $charSet = null;
@ -95,7 +95,7 @@ class MariaDBConnectionInfo implements IDbConnectionInfo {
public function getHost(): string { public function getHost(): string {
if($this->endPoint instanceof DnsEndPoint) if($this->endPoint instanceof DnsEndPoint)
return $this->endPoint->getHost(); return $this->endPoint->getHost();
if($this->endPoint instanceof IPEndPoint) if($this->endPoint instanceof IpEndPoint)
return $this->endPoint->getAddress()->getCleanAddress(); return $this->endPoint->getAddress()->getCleanAddress();
return ''; return '';
} }
@ -108,7 +108,7 @@ class MariaDBConnectionInfo implements IDbConnectionInfo {
* @return int Target port number. * @return int Target port number.
*/ */
public function getPort(): int { public function getPort(): int {
if(($this->endPoint instanceof DnsEndPoint) || ($this->endPoint instanceof IPEndPoint)) { if(($this->endPoint instanceof DnsEndPoint) || ($this->endPoint instanceof IpEndPoint)) {
$port = $this->endPoint->getPort(); $port = $this->endPoint->getPort();
return $port < 1 ? 3306 : $port; return $port < 1 ? 3306 : $port;
} }
@ -283,7 +283,7 @@ class MariaDBConnectionInfo implements IDbConnectionInfo {
* @param string|null $cipherAlgos List of SSL encryption cipher that are allowed. * @param string|null $cipherAlgos List of SSL encryption cipher that are allowed.
* @param bool $verifyCert true if the client should verify the server's SSL certificate, false if not. * @param bool $verifyCert true if the client should verify the server's SSL certificate, false if not.
* @param bool $useCompression true if compression should be used, false if not. * @param bool $useCompression true if compression should be used, false if not.
* @return MariaDBConnectionInfo A connection info instance representing the given information. * @return MariaDbConnectionInfo A connection info instance representing the given information.
*/ */
public static function createHost( public static function createHost(
string $host, string $host,
@ -300,8 +300,8 @@ class MariaDBConnectionInfo implements IDbConnectionInfo {
string|null $cipherAlgos = null, string|null $cipherAlgos = null,
bool $verifyCert = false, bool $verifyCert = false,
bool $useCompression = false bool $useCompression = false
): MariaDBConnectionInfo { ): MariaDbConnectionInfo {
return new MariaDBConnectionInfo( return new MariaDbConnectionInfo(
new DnsEndPoint($host, $port), new DnsEndPoint($host, $port),
$userName, $userName,
$password, $password,
@ -334,7 +334,7 @@ class MariaDBConnectionInfo implements IDbConnectionInfo {
* @param string|null $cipherAlgos List of SSL encryption cipher that are allowed. * @param string|null $cipherAlgos List of SSL encryption cipher that are allowed.
* @param bool $verifyCert true if the client should verify the server's SSL certificate, false if not. * @param bool $verifyCert true if the client should verify the server's SSL certificate, false if not.
* @param bool $useCompression true if compression should be used, false if not. * @param bool $useCompression true if compression should be used, false if not.
* @return MariaDBConnectionInfo A connection info instance representing the given information. * @return MariaDbConnectionInfo A connection info instance representing the given information.
*/ */
public static function createUnix( public static function createUnix(
string $path, string $path,
@ -350,8 +350,8 @@ class MariaDBConnectionInfo implements IDbConnectionInfo {
string|null $cipherAlgos = null, string|null $cipherAlgos = null,
bool $verifyCert = false, bool $verifyCert = false,
bool $useCompression = false bool $useCompression = false
): MariaDBConnectionInfo { ): MariaDbConnectionInfo {
return new MariaDBConnectionInfo( return new MariaDbConnectionInfo(
UnixEndPoint::parse($path), UnixEndPoint::parse($path),
$userName, $userName,
$password, $password,
@ -386,7 +386,7 @@ class MariaDBConnectionInfo implements IDbConnectionInfo {
* @param string|null $cipherAlgos List of SSL encryption cipher that are allowed. * @param string|null $cipherAlgos List of SSL encryption cipher that are allowed.
* @param bool $verifyCert true if the client should verify the server's SSL certificate, false if not. * @param bool $verifyCert true if the client should verify the server's SSL certificate, false if not.
* @param bool $useCompression true if compression should be used, false if not. * @param bool $useCompression true if compression should be used, false if not.
* @return MariaDBConnectionInfo A connection info instance representing the given information. * @return MariaDbConnectionInfo A connection info instance representing the given information.
*/ */
public static function create( public static function create(
string $endPoint, string $endPoint,
@ -402,8 +402,8 @@ class MariaDBConnectionInfo implements IDbConnectionInfo {
string|null $cipherAlgos = null, string|null $cipherAlgos = null,
bool $verifyCert = false, bool $verifyCert = false,
bool $useCompression = false bool $useCompression = false
): MariaDBConnectionInfo { ): MariaDbConnectionInfo {
return new MariaDBConnectionInfo( return new MariaDbConnectionInfo(
EndPoint::parse($endPoint), EndPoint::parse($endPoint),
$userName, $userName,
$password, $password,

View file

@ -1,23 +1,23 @@
<?php <?php
// MariaDBParameter.php // MariaDBParameter.php
// Created: 2021-05-02 // Created: 2021-05-02
// Updated: 2024-08-01 // Updated: 2024-10-02
namespace Index\Data\MariaDB; namespace Index\Data\MariaDb;
use Index\Data\{DbTools,DbType}; use Index\Data\{DbTools,DbType};
/** /**
* Represents a bound parameter. * Represents a bound parameter.
*/ */
class MariaDBParameter { class MariaDbParameter {
/** /**
* Create a new MariaDBParameter. * Create a new MariaDbParameter.
* *
* @param int $ordinal Parameter number. * @param int $ordinal Parameter number.
* @param int $type DbType number. * @param int $type DbType number.
* @param mixed $value Value to bind. * @param mixed $value Value to bind.
* @return MariaDBParameter A new parameter instance. * @return MariaDbParameter A new parameter instance.
*/ */
public function __construct( public function __construct(
private int $ordinal, private int $ordinal,

View file

@ -1,30 +1,30 @@
<?php <?php
// MariaDBResult.php // MariaDBResult.php
// Created: 2021-05-02 // Created: 2021-05-02
// Updated: 2024-08-03 // Updated: 2024-10-02
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,IDbResult}; use Index\Data\{DbResultTrait,IDbResult};
use Index\IO\{Stream,TempFileStream}; use Index\Io\{Stream,TempFileStream};
/** /**
* Represents a MariaDB/MySQL database result. * Represents a MariaDB/MySQL database result.
*/ */
abstract class MariaDBResult implements IDbResult { abstract class MariaDbResult implements IDbResult {
use DbResultTrait; use DbResultTrait;
/** @var array<int|string, mixed> */ /** @var array<int|string, mixed> */
protected array $currentRow = []; protected array $currentRow = [];
/** /**
* Creates a new MariaDBResult instance. * Creates a new MariaDbResult instance.
* *
* @param mysqli_stmt|mysqli_result $result A result to work with. * @param mysqli_stmt|mysqli_result $result A result to work with.
* @return MariaDBResult A result instance. * @return MariaDbResult A result instance.
*/ */
public function __construct( public function __construct(
protected mysqli_stmt|mysqli_result $result protected mysqli_stmt|mysqli_result $result

View file

@ -1,19 +1,19 @@
<?php <?php
// MariaDBResultLib.php // MariaDBResultLib.php
// Created: 2021-05-02 // Created: 2021-05-02
// Updated: 2024-08-03 // Updated: 2024-10-02
namespace Index\Data\MariaDB; namespace Index\Data\MariaDb;
use mysqli_stmt; use mysqli_stmt;
use RuntimeException; use RuntimeException;
/** /**
* Implementation of MariaDBResult for libmysql. * Implementation of MariaDbResult for libmysql.
* *
* @internal * @internal
*/ */
class MariaDBResultLib extends MariaDBResult { class MariaDbResultLib extends MariaDbResult {
/** @var mixed[] */ /** @var mixed[] */
private array $fields = []; private array $fields = [];

View file

@ -1,20 +1,20 @@
<?php <?php
// MariaDBResultNative.php // MariaDBResultNative.php
// Created: 2021-05-02 // Created: 2021-05-02
// Updated: 2024-08-18 // Updated: 2024-10-02
namespace Index\Data\MariaDB; namespace Index\Data\MariaDb;
use mysqli_result; use mysqli_result;
use mysqli_stmt; use mysqli_stmt;
use RuntimeException; use RuntimeException;
/** /**
* Implementation of MariaDBResult for mysqlnd. * Implementation of MariaDbResult for mysqlnd.
* *
* @internal * @internal
*/ */
class MariaDBResultNative extends MariaDBResult { class MariaDbResultNative extends MariaDbResult {
public function __construct(mysqli_stmt|mysqli_result $result) { public function __construct(mysqli_stmt|mysqli_result $result) {
if($result instanceof mysqli_stmt) { if($result instanceof mysqli_stmt) {
$_result = $result->get_result(); $_result = $result->get_result();

View file

@ -1,28 +1,28 @@
<?php <?php
// MariaDBStatement.php // MariaDBStatement.php
// Created: 2021-05-02 // Created: 2021-05-02
// Updated: 2024-09-13 // Updated: 2024-10-02
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,IDbStatement}; use Index\Data\{DbType,IDbStatement};
use Index\IO\Stream; use Index\Io\Stream;
/** /**
* Represents a MariaDB/MySQL prepared statement. * Represents a MariaDB/MySQL prepared statement.
*/ */
class MariaDBStatement implements IDbStatement { class MariaDbStatement implements IDbStatement {
/** @var array<int, MariaDBParameter> */ /** @var array<int, MariaDbParameter> */
private array $params = []; private array $params = [];
/** /**
* Creates a MariaDBStatement. * Creates a MariaDbStatement.
* *
* @param mysqli_stmt $statement Underlying statement object. * @param mysqli_stmt $statement Underlying statement object.
* @return MariaDBStatement A new statement instance. * @return MariaDbStatement A new statement instance.
*/ */
public function __construct( public function __construct(
private mysqli_stmt $statement private mysqli_stmt $statement
@ -30,11 +30,11 @@ class MariaDBStatement implements IDbStatement {
private static bool $constructed = false; private static bool $constructed = false;
/** @var class-string<MariaDBResult> */ /** @var class-string<MariaDbResult> */
private static string $resultImplementation; private static string $resultImplementation;
/** /**
* Determines which MariaDBResult implementation should be used. * Determines which MariaDbResult implementation should be used.
* *
* @internal * @internal
*/ */
@ -43,8 +43,8 @@ class MariaDBStatement implements IDbStatement {
throw new RuntimeException('Static constructor was already called.'); throw new RuntimeException('Static constructor was already called.');
self::$constructed = true; self::$constructed = true;
self::$resultImplementation = function_exists('mysqli_stmt_get_result') self::$resultImplementation = function_exists('mysqli_stmt_get_result')
? MariaDBResultNative::class ? MariaDbResultNative::class
: MariaDBResultLib::class; : MariaDbResultLib::class;
} }
public function getParameterCount(): int { public function getParameterCount(): int {
@ -55,7 +55,7 @@ class MariaDBStatement implements IDbStatement {
if($ordinal < 1 || $ordinal > $this->getParameterCount()) if($ordinal < 1 || $ordinal > $this->getParameterCount())
throw new InvalidArgumentException('$ordinal is not a valid parameter number.'); throw new InvalidArgumentException('$ordinal is not a valid parameter number.');
$this->params[$ordinal - 1] = new MariaDBParameter($ordinal, $type, $value); $this->params[$ordinal - 1] = new MariaDbParameter($ordinal, $type, $value);
} }
public function nextParameter(mixed $value, int $type = DbType::AUTO): void { public function nextParameter(mixed $value, int $type = DbType::AUTO): void {
@ -63,7 +63,7 @@ class MariaDBStatement implements IDbStatement {
if($nextIndex >= $this->getParameterCount()) if($nextIndex >= $this->getParameterCount())
throw new RuntimeException('Attempted to specify too many parameters.'); throw new RuntimeException('Attempted to specify too many parameters.');
$this->params[$nextIndex] = new MariaDBParameter($nextIndex + 1, $type, $value); $this->params[$nextIndex] = new MariaDbParameter($nextIndex + 1, $type, $value);
} }
/** /**
@ -96,10 +96,10 @@ class MariaDBStatement implements IDbStatement {
/** /**
* Gets a list of errors from the last command. * Gets a list of errors from the last command.
* *
* @return MariaDBWarning[] List of last errors. * @return MariaDbWarning[] List of last errors.
*/ */
public function getLastErrors(): array { public function getLastErrors(): array {
return MariaDBWarning::fromLastErrors($this->statement->error_list); return MariaDbWarning::fromLastErrors($this->statement->error_list);
} }
/** /**
@ -107,13 +107,13 @@ class MariaDBStatement implements IDbStatement {
* *
* The result of SHOW WARNINGS; * The result of SHOW WARNINGS;
* *
* @return MariaDBWarning[] List of warnings. * @return MariaDbWarning[] List of warnings.
*/ */
public function getWarnings(): array { public function getWarnings(): array {
return MariaDBWarning::fromGetWarnings($this->statement->get_warnings()); return MariaDbWarning::fromGetWarnings($this->statement->get_warnings());
} }
public function getResult(): MariaDBResult { public function getResult(): MariaDbResult {
return new self::$resultImplementation($this->statement); return new self::$resultImplementation($this->statement);
} }
@ -173,4 +173,4 @@ class MariaDBStatement implements IDbStatement {
} }
} }
MariaDBStatement::construct(); MariaDbStatement::construct();

View file

@ -1,9 +1,9 @@
<?php <?php
// MariaDBWarning.php // MariaDBWarning.php
// Created: 2021-05-02 // Created: 2021-05-02
// Updated: 2024-08-03 // Updated: 2024-10-02
namespace Index\Data\MariaDB; namespace Index\Data\MariaDb;
use mysqli_warning; use mysqli_warning;
use Stringable; use Stringable;
@ -12,14 +12,14 @@ use Index\XArray;
/** /**
* Represents a MariaDB/MySQL warning. * Represents a MariaDB/MySQL warning.
*/ */
class MariaDBWarning implements Stringable { class MariaDbWarning implements Stringable {
/** /**
* Creates a new MariaDBWarning object. * Creates a new MariaDbWarning object.
* *
* @param string $message Warning message string. * @param string $message Warning message string.
* @param string $sqlState SQL State of the warning. * @param string $sqlState SQL State of the warning.
* @param int $code Error code of the warning. * @param int $code Error code of the warning.
* @return MariaDBWarning A new warning instance. * @return MariaDbWarning A new warning instance.
*/ */
public function __construct( public function __construct(
private string $message, private string $message,
@ -62,24 +62,24 @@ class MariaDBWarning implements Stringable {
* Creates an array of warning objects from the output of $last_errors. * Creates an array of warning objects from the output of $last_errors.
* *
* @param array<int, array{errno: int, sqlstate: string, error: string}> $errors Array of warning arrays. * @param array<int, array{errno: int, sqlstate: string, error: string}> $errors Array of warning arrays.
* @return MariaDBWarning[] Array of warnings objects. * @return MariaDbWarning[] Array of warnings objects.
*/ */
public static function fromLastErrors(array $errors): array { public static function fromLastErrors(array $errors): array {
return XArray::select($errors, fn($error) => new MariaDBWarning($error['error'], $error['sqlstate'], $error['errno'])); return XArray::select($errors, fn($error) => new MariaDbWarning($error['error'], $error['sqlstate'], $error['errno']));
} }
/** /**
* Creates an array of warning objects from a mysqli_warning instance. * Creates an array of warning objects from a mysqli_warning instance.
* *
* @param mysqli_warning|false $warnings Warning object. * @param mysqli_warning|false $warnings Warning object.
* @return MariaDBWarning[] Array of warning objects. * @return MariaDbWarning[] Array of warning objects.
*/ */
public static function fromGetWarnings(mysqli_warning|false $warnings): array { public static function fromGetWarnings(mysqli_warning|false $warnings): array {
$array = []; $array = [];
if($warnings !== false) if($warnings !== false)
do { do {
$array[] = new MariaDBWarning( $array[] = new MariaDbWarning(
$warnings->message, $warnings->message,
$warnings->sqlstate, $warnings->sqlstate,
$warnings->errno $warnings->errno

View file

@ -1,7 +1,7 @@
<?php <?php
// DbMigrationManager.php // DbMigrationManager.php
// Created: 2023-01-07 // Created: 2023-01-07
// Updated: 2024-08-04 // Updated: 2024-10-02
namespace Index\Data\Migration; namespace Index\Data\Migration;
@ -12,7 +12,7 @@ use InvalidArgumentException;
use RuntimeException; use RuntimeException;
use Index\XDateTime; use Index\XDateTime;
use Index\Data\{IDbConnection,IDbStatement,DbType}; use Index\Data\{IDbConnection,IDbStatement,DbType};
use Index\Data\SQLite\SQLiteConnection; use Index\Data\Sqlite\SqliteConnection;
/** /**
* Provides a common interface for database migrations. * Provides a common interface for database migrations.
@ -62,7 +62,8 @@ EOF;
*/ */
public function createTrackingTable(): void { public function createTrackingTable(): void {
// HACK: this is not ok but it works for now, there should probably be a generic type bag alias thing // HACK: this is not ok but it works for now, there should probably be a generic type bag alias thing
$nameType = $this->conn instanceof SQLiteConnection ? 'TEXT' : 'VARCHAR(255)'; // TODO: ACTUALLY get rid of this
$nameType = $this->conn instanceof SqliteConnection ? 'TEXT' : 'VARCHAR(255)';
$this->conn->execute(sprintf(self::CREATE_TRACK_TABLE, $this->tableName, $nameType)); $this->conn->execute(sprintf(self::CREATE_TRACK_TABLE, $this->tableName, $nameType));
$this->conn->execute(sprintf(self::CREATE_TRACK_INDEX, $this->tableName)); $this->conn->execute(sprintf(self::CREATE_TRACK_INDEX, $this->tableName));
@ -120,7 +121,7 @@ EOF;
if($this->insertStmt === null) if($this->insertStmt === null)
throw new RuntimeException('Database migration manager has not been initialised.'); throw new RuntimeException('Database migration manager has not been initialised.');
$dateTime = XDateTime::toISO8601String($dateTime); $dateTime = XDateTime::toIso8601String($dateTime);
$this->insertStmt->reset(); $this->insertStmt->reset();
$this->insertStmt->addParameter(1, $name, DbType::STRING); $this->insertStmt->addParameter(1, $name, DbType::STRING);

View file

@ -1,12 +1,12 @@
<?php <?php
// NullDbResult.php // NullDbResult.php
// Created: 2021-05-02 // Created: 2021-05-02
// Updated: 2024-08-01 // Updated: 2024-10-02
namespace Index\Data\NullDb; namespace Index\Data\NullDb;
use Index\Data\{IDbResult,DbResultIterator}; use Index\Data\{IDbResult,DbResultIterator};
use Index\IO\Stream; use Index\Io\Stream;
/** /**
* Represents a dummy database result. * Represents a dummy database result.

View file

@ -1,9 +1,9 @@
<?php <?php
// SQLiteBackend.php // SqliteBackend.php
// Created: 2021-05-02 // Created: 2021-05-02
// Updated: 2024-08-04 // Updated: 2024-10-02
namespace Index\Data\SQLite; namespace Index\Data\Sqlite;
use SQLite3; use SQLite3;
use InvalidArgumentException; use InvalidArgumentException;
@ -12,7 +12,7 @@ use Index\Data\{IDbBackend,IDbConnection,IDbConnectionInfo};
/** /**
* Information about the SQLite 3 database layer. * Information about the SQLite 3 database layer.
*/ */
class SQLiteBackend implements IDbBackend { class SqliteBackend implements IDbBackend {
public function isAvailable(): bool { public function isAvailable(): bool {
return extension_loaded('sqlite3'); return extension_loaded('sqlite3');
} }
@ -31,14 +31,14 @@ class SQLiteBackend implements IDbBackend {
/** /**
* Creates a new SQLite client. * Creates a new SQLite client.
* *
* @param SQLiteConnectionInfo $connectionInfo Object that describes the desired connection. * @param SqliteConnectionInfo $connectionInfo Object that describes the desired connection.
* @return SQLiteConnection A client for an SQLite database. * @return SqliteConnection A client for an SQLite database.
*/ */
public function createConnection(IDbConnectionInfo $connectionInfo): IDbConnection { public function createConnection(IDbConnectionInfo $connectionInfo): IDbConnection {
if(!($connectionInfo instanceof SQLiteConnectionInfo)) if(!($connectionInfo instanceof SqliteConnectionInfo))
throw new InvalidArgumentException('$connectionInfo must by of type SQLiteConnectionInfo'); throw new InvalidArgumentException('$connectionInfo must by of type SqliteConnectionInfo');
return new SQLiteConnection($connectionInfo); return new SqliteConnection($connectionInfo);
} }
/** /**
@ -54,7 +54,7 @@ class SQLiteBackend implements IDbBackend {
* - `openOnly` to prevent a new file from being created if the specified path does not exist. * - `openOnly` to prevent a new file from being created if the specified path does not exist.
* *
* @param string|array<string, int|string> $dsn DSN with connection information. * @param string|array<string, int|string> $dsn DSN with connection information.
* @return SQLiteConnectionInfo SQLite connection info. * @return SqliteConnectionInfo SQLite connection info.
*/ */
public function parseDsn(string|array $dsn): IDbConnectionInfo { public function parseDsn(string|array $dsn): IDbConnectionInfo {
if(is_string($dsn)) { if(is_string($dsn)) {
@ -78,6 +78,6 @@ class SQLiteBackend implements IDbBackend {
$readOnly = isset($query['readOnly']); $readOnly = isset($query['readOnly']);
$create = !isset($query['openOnly']); $create = !isset($query['openOnly']);
return new SQLiteConnectionInfo($path, $encKey, $readOnly, $create); return new SqliteConnectionInfo($path, $encKey, $readOnly, $create);
} }
} }

View file

@ -1,19 +1,19 @@
<?php <?php
// SQLiteConnection.php // SqliteConnection.php
// Created: 2021-05-02 // Created: 2021-05-02
// Updated: 2024-09-13 // Updated: 2024-10-02
namespace Index\Data\SQLite; namespace Index\Data\Sqlite;
use RuntimeException; use RuntimeException;
use SQLite3; use SQLite3;
use Index\Data\{IDbConnection,IDbTransactions,IDbStatement,IDbResult}; use Index\Data\{IDbConnection,IDbTransactions,IDbStatement,IDbResult};
use Index\IO\{GenericStream,Stream}; use Index\Io\{GenericStream,Stream};
/** /**
* Represents a client for an SQLite database. * Represents a client for an SQLite database.
*/ */
class SQLiteConnection implements IDbConnection, IDbTransactions { class SqliteConnection implements IDbConnection, IDbTransactions {
/** /**
* CREATE INDEX authorizer. * CREATE INDEX authorizer.
* *
@ -358,10 +358,10 @@ class SQLiteConnection implements IDbConnection, IDbTransactions {
/** /**
* Creates a new SQLite client. * Creates a new SQLite client.
* *
* @param SQLiteConnectionInfo $connectionInfo Information about the client. * @param SqliteConnectionInfo $connectionInfo Information about the client.
* @return SQLiteConnection A new SQLite client. * @return SqliteConnection A new SQLite client.
*/ */
public function __construct(SQLiteConnectionInfo $connectionInfo) { public function __construct(SqliteConnectionInfo $connectionInfo) {
$flags = 0; $flags = 0;
if($connectionInfo->shouldReadOnly()) if($connectionInfo->shouldReadOnly())
$flags |= SQLITE3_OPEN_READONLY; $flags |= SQLITE3_OPEN_READONLY;
@ -460,7 +460,7 @@ class SQLiteConnection implements IDbConnection, IDbTransactions {
/** /**
* Opens a BLOB field as a Stream. * Opens a BLOB field as a Stream.
* *
* To be used instead of getStream on SQLiteResult. * To be used instead of getStream on SqliteResult.
* *
* @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.
@ -484,14 +484,14 @@ class SQLiteConnection implements IDbConnection, IDbTransactions {
$statement = $this->connection->prepare($query); $statement = $this->connection->prepare($query);
if($statement === false) if($statement === false)
throw new RuntimeException((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 RuntimeException($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 {

View file

@ -1,24 +1,24 @@
<?php <?php
// SQLiteConnectionInfo.php // SqliteConnectionInfo.php
// Created: 2021-05-02 // Created: 2021-05-02
// Updated: 2024-08-01 // Updated: 2024-10-02
namespace Index\Data\SQLite; namespace Index\Data\Sqlite;
use Index\Data\IDbConnectionInfo; use Index\Data\IDbConnectionInfo;
/** /**
* Represents information about a SQLite Client. * Represents information about a SQLite Client.
*/ */
class SQLiteConnectionInfo implements IDbConnectionInfo { class SqliteConnectionInfo implements IDbConnectionInfo {
/** /**
* Creates a new SQLiteConnectionInfo instance. * Creates a new SqliteConnectionInfo instance.
* *
* @param string $fileName Path to the SQLite database. * @param string $fileName Path to the SQLite database.
* @param string $encryptionKey Key to encrypt the database with. * @param string $encryptionKey Key to encrypt the database with.
* @param bool $readOnly Set to true if the database should be opened read-only. * @param bool $readOnly Set to true if the database should be opened read-only.
* @param bool $create Set to true to create the database if it does not exist. * @param bool $create Set to true to create the database if it does not exist.
* @return SQLiteConnectionInfo Information to create an SQLite database client. * @return SqliteConnectionInfo Information to create an SQLite database client.
*/ */
public function __construct( public function __construct(
private string $fileName, private string $fileName,
@ -68,15 +68,15 @@ class SQLiteConnectionInfo implements IDbConnectionInfo {
* @param string $encryptionKey Key to encrypt the database with. * @param string $encryptionKey Key to encrypt the database with.
* @param bool $readOnly Set to true if the database should be opened read-only. * @param bool $readOnly Set to true if the database should be opened read-only.
* @param bool $create Set to true to create the database if it does not exist. * @param bool $create Set to true to create the database if it does not exist.
* @return SQLiteConnectionInfo Information to create an SQLite database client. * @return SqliteConnectionInfo Information to create an SQLite database client.
*/ */
public static function createPath( public static function createPath(
string $path, string $path,
string $encryptionKey = '', string $encryptionKey = '',
bool $readOnly = false, bool $readOnly = false,
bool $create = true bool $create = true
): SQLiteConnectionInfo { ): SqliteConnectionInfo {
return new SQLiteConnectionInfo( return new SqliteConnectionInfo(
$path, $path,
$encryptionKey, $encryptionKey,
$readOnly, $readOnly,
@ -88,19 +88,19 @@ class SQLiteConnectionInfo implements IDbConnectionInfo {
* Creates a connection info instance for an in-memory database. * Creates a connection info instance for an in-memory database.
* *
* @param string $encryptionKey Key to encrypt the database with. * @param string $encryptionKey Key to encrypt the database with.
* @return SQLiteConnectionInfo Information to create an SQLite database client. * @return SqliteConnectionInfo Information to create an SQLite database client.
*/ */
public static function createMemory(string $encryptionKey = ''): SQLiteConnectionInfo { public static function createMemory(string $encryptionKey = ''): SqliteConnectionInfo {
return new SQLiteConnectionInfo(':memory:', $encryptionKey, false, true); return new SqliteConnectionInfo(':memory:', $encryptionKey, false, true);
} }
/** /**
* Creates a connection info instance for a database stored in a temporary file. * Creates a connection info instance for a database stored in a temporary file.
* *
* @param string $encryptionKey Key to encrypt the database with. * @param string $encryptionKey Key to encrypt the database with.
* @return SQLiteConnectionInfo Information to create an SQLite database client. * @return SqliteConnectionInfo Information to create an SQLite database client.
*/ */
public static function createTemp(string $encryptionKey = ''): SQLiteConnectionInfo { public static function createTemp(string $encryptionKey = ''): SqliteConnectionInfo {
return new SQLiteConnectionInfo('', $encryptionKey, false, true); return new SqliteConnectionInfo('', $encryptionKey, false, true);
} }
} }

View file

@ -1,29 +1,29 @@
<?php <?php
// SQLiteResult.php // SqliteResult.php
// Created: 2021-05-02 // Created: 2021-05-02
// Updated: 2024-08-03 // Updated: 2024-10-02
namespace Index\Data\SQLite; namespace Index\Data\Sqlite;
use SQLite3Result; use SQLite3Result;
use InvalidArgumentException; use InvalidArgumentException;
use Index\Data\{DbResultTrait,IDbResult}; use Index\Data\{DbResultTrait,IDbResult};
use Index\IO\{Stream,TempFileStream}; use Index\Io\{Stream,TempFileStream};
/** /**
* Represents an SQLite result set. * Represents an SQLite result set.
*/ */
class SQLiteResult implements IDbResult { class SqliteResult implements IDbResult {
use DbResultTrait; use DbResultTrait;
/** @var array<int|string, mixed> */ /** @var array<int|string, mixed> */
private array $currentRow = []; private array $currentRow = [];
/** /**
* Creates a new instance of SQLiteResult. * Creates a new instance of SqliteResult.
* *
* @param SQLite3Result $result Raw underlying result class. * @param SQLite3Result $result Raw underlying result class.
* @return SQLiteResult A new SQLiteResult instance. * @return SqliteResult A new SqliteResult instance.
*/ */
public function __construct( public function __construct(
private SQLite3Result $result private SQLite3Result $result
@ -56,7 +56,7 @@ class SQLiteResult implements IDbResult {
/** /**
* Gets the value from the target index as a Stream. * Gets the value from the target index as a Stream.
* If you're aware that you're using SQLite it may make more sense to use SQLiteConnection::getBlobStream instead. * If you're aware that you're using SQLite it may make more sense to use SqliteConnection::getBlobStream instead.
*/ */
public function getStream(int|string $index): ?Stream { public function getStream(int|string $index): ?Stream {
if($this->isNull($index)) if($this->isNull($index))

View file

@ -1,33 +1,33 @@
<?php <?php
// SQLiteStatement.php // SqliteStatement.php
// Created: 2021-05-02 // Created: 2021-05-02
// Updated: 2024-09-13 // Updated: 2024-10-02
namespace Index\Data\SQLite; namespace Index\Data\Sqlite;
use SQLite3Result; use SQLite3Result;
use SQLite3Stmt; use SQLite3Stmt;
use InvalidArgumentException; use InvalidArgumentException;
use RuntimeException; use RuntimeException;
use Index\Data\{DbTools,DbType,IDbStatement,IDbResult}; use Index\Data\{DbTools,DbType,IDbStatement,IDbResult};
use Index\IO\Stream; use Index\Io\Stream;
/** /**
* Represents a prepared SQLite SQL statement. * Represents a prepared SQLite SQL statement.
*/ */
class SQLiteStatement implements IDbStatement { class SqliteStatement implements IDbStatement {
private ?SQLite3Result $result = null; private ?SQLite3Result $result = null;
private int $lastOrdinal = 1; private int $lastOrdinal = 1;
/** /**
* Creates a new SQLiteStatement instance. * Creates a new SqliteStatement instance.
* *
* @param SQLiteConnection $connection A reference to the connection which creates this statement. * @param SqliteConnection $connection A reference to the connection which creates this statement.
* @param SQLite3Stmt $statement The raw statement instance. * @param SQLite3Stmt $statement The raw statement instance.
* @return SQLiteStatement A new statement instance. * @return SqliteStatement A new statement instance.
*/ */
public function __construct( public function __construct(
private SQLiteConnection $connection, private SqliteConnection $connection,
private SQLite3Stmt $statement private SQLite3Stmt $statement
) {} ) {}
@ -76,7 +76,7 @@ class SQLiteStatement implements IDbStatement {
public function getResult(): IDbResult { public function getResult(): IDbResult {
if($this->result === null) if($this->result === null)
throw new RuntimeException('No result is available.'); throw new RuntimeException('No result is available.');
return new SQLiteResult($this->result); return new SqliteResult($this->result);
} }
public function getLastInsertId(): int|string { public function getLastInsertId(): int|string {

View file

@ -1,12 +1,12 @@
<?php <?php
// BencodedContent.php // BencodedContent.php
// Created: 2022-02-10 // Created: 2022-02-10
// Updated: 2024-08-01 // Updated: 2024-10-02
namespace Index\Http\Content; namespace Index\Http\Content;
use Index\Bencode\{Bencode,IBencodeSerialisable}; use Index\Bencode\{Bencode,IBencodeSerialisable};
use Index\IO\{Stream,FileStream}; use Index\Io\{Stream,FileStream};
/** /**
* Represents Bencoded body content for a HTTP message. * Represents Bencoded body content for a HTTP message.

View file

@ -1,7 +1,7 @@
<?php <?php
// FormContent.php // FormContent.php
// Created: 2022-02-10 // Created: 2022-02-10
// Updated: 2024-08-04 // Updated: 2024-10-02
namespace Index\Http\Content; namespace Index\Http\Content;
@ -100,7 +100,7 @@ class FormContent implements IHttpContent {
public static function fromRaw(array $post, array $files): FormContent { public static function fromRaw(array $post, array $files): FormContent {
return new FormContent( return new FormContent(
$post, $post,
HttpUploadedFile::createFromFILES($files) HttpUploadedFile::createFromPhpFiles($files)
); );
} }

View file

@ -1,12 +1,12 @@
<?php <?php
// JsonContent.php // JsonContent.php
// Created: 2022-02-10 // Created: 2022-02-10
// Updated: 2024-08-03 // Updated: 2024-10-02
namespace Index\Http\Content; namespace Index\Http\Content;
use JsonSerializable; use JsonSerializable;
use Index\IO\{Stream,FileStream}; use Index\Io\{Stream,FileStream};
/** /**
* Represents JSON body content for a HTTP message. * Represents JSON body content for a HTTP message.

View file

@ -1,11 +1,11 @@
<?php <?php
// StreamContent.php // StreamContent.php
// Created: 2022-02-10 // Created: 2022-02-10
// Updated: 2024-08-01 // Updated: 2024-10-02
namespace Index\Http\Content; namespace Index\Http\Content;
use Index\IO\{Stream,FileStream}; use Index\Io\{Stream,FileStream};
/** /**
* Represents Stream body content for a HTTP message. * Represents Stream body content for a HTTP message.

View file

@ -1,13 +1,13 @@
<?php <?php
// StreamContentHandler.php // StreamContentHandler.php
// Created: 2024-03-28 // Created: 2024-03-28
// Updated: 2024-08-03 // Updated: 2024-10-02
namespace Index\Http\ContentHandling; namespace Index\Http\ContentHandling;
use Index\Http\HttpResponseBuilder; use Index\Http\HttpResponseBuilder;
use Index\Http\Content\StreamContent; use Index\Http\Content\StreamContent;
use Index\IO\Stream; use Index\Io\Stream;
/** /**
* Represents a Stream content handler for building HTTP response messages. * Represents a Stream content handler for building HTTP response messages.

View file

@ -1,7 +1,7 @@
<?php <?php
// HtmlErrorHandler.php // HtmlErrorHandler.php
// Created: 2024-03-28 // Created: 2024-03-28
// Updated: 2024-08-03 // Updated: 2024-10-02
namespace Index\Http\ErrorHandling; namespace Index\Http\ErrorHandling;
@ -27,7 +27,7 @@ class HtmlErrorHandler implements IErrorHandler {
HTML; HTML;
public function handle(HttpResponseBuilder $response, HttpRequest $request, int $code, string $message): void { public function handle(HttpResponseBuilder $response, HttpRequest $request, int $code, string $message): void {
$response->setTypeHTML(); $response->setTypeHtml();
$charSet = mb_preferred_mime_name(mb_internal_encoding()); $charSet = mb_preferred_mime_name(mb_internal_encoding());
if($charSet === false) if($charSet === false)

View file

@ -1,12 +1,12 @@
<?php <?php
// HttpMessage.php // HttpMessage.php
// Created: 2022-02-08 // Created: 2022-02-08
// Updated: 2024-08-01 // Updated: 2024-10-02
namespace Index\Http; namespace Index\Http;
use RuntimeException; use RuntimeException;
use Index\IO\Stream; use Index\Io\Stream;
use Index\Http\Content\{IHttpContent,BencodedContent,FormContent,JsonContent,StreamContent,StringContent}; use Index\Http\Content\{IHttpContent,BencodedContent,FormContent,JsonContent,StreamContent,StringContent};
/** /**

View file

@ -1,11 +1,11 @@
<?php <?php
// HttpMessageBuilder.php // HttpMessageBuilder.php
// Created: 2022-02-08 // Created: 2022-02-08
// Updated: 2024-08-03 // Updated: 2024-10-02
namespace Index\Http; namespace Index\Http;
use Index\IO\Stream; use Index\Io\Stream;
use Index\Http\Content\{IHttpContent,StreamContent,StringContent}; use Index\Http\Content\{IHttpContent,StreamContent,StringContent};
/** /**

View file

@ -1,7 +1,7 @@
<?php <?php
// HttpResponseBuilder.php // HttpResponseBuilder.php
// Created: 2022-02-08 // Created: 2022-02-08
// Updated: 2024-08-04 // Updated: 2024-10-02
namespace Index\Http; namespace Index\Http;
@ -248,7 +248,7 @@ class HttpResponseBuilder extends HttpMessageBuilder {
* *
* @param string $charset Character set. * @param string $charset Character set.
*/ */
public function setTypeHTML(string $charset = 'utf-8'): void { public function setTypeHtml(string $charset = 'utf-8'): void {
$this->setContentType('text/html; charset=' . $charset); $this->setContentType('text/html; charset=' . $charset);
} }
@ -266,7 +266,7 @@ class HttpResponseBuilder extends HttpMessageBuilder {
* *
* @param string $charset Character set. * @param string $charset Character set.
*/ */
public function setTypeXML(string $charset = 'utf-8'): void { public function setTypeXml(string $charset = 'utf-8'): void {
$this->setContentType('application/xml; charset=' . $charset); $this->setContentType('application/xml; charset=' . $charset);
} }
@ -275,7 +275,7 @@ class HttpResponseBuilder extends HttpMessageBuilder {
* *
* @param string $charset Character set. * @param string $charset Character set.
*/ */
public function setTypeCSS(string $charset = 'utf-8'): void { public function setTypeCss(string $charset = 'utf-8'): void {
$this->setContentType('text/css; charset=' . $charset); $this->setContentType('text/css; charset=' . $charset);
} }
@ -284,7 +284,7 @@ class HttpResponseBuilder extends HttpMessageBuilder {
* *
* @param string $charset Character set. * @param string $charset Character set.
*/ */
public function setTypeJS(string $charset = 'utf-8'): void { public function setTypeJs(string $charset = 'utf-8'): void {
$this->setContentType('application/javascript; charset=' . $charset); $this->setContentType('application/javascript; charset=' . $charset);
} }

View file

@ -1,14 +1,14 @@
<?php <?php
// HttpUploadedFile.php // HttpUploadedFile.php
// Created: 2022-02-10 // Created: 2022-02-10
// Updated: 2024-08-04 // Updated: 2024-10-02
namespace Index\Http; namespace Index\Http;
use InvalidArgumentException; use InvalidArgumentException;
use RuntimeException; use RuntimeException;
use Index\{MediaType,ICloseable}; use Index\{MediaType,ICloseable};
use Index\IO\{Stream,FileStream}; 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.
@ -166,7 +166,7 @@ class HttpUploadedFile implements ICloseable {
* @param array<string, int|string> $file File info array. * @param array<string, int|string> $file File info array.
* @return HttpUploadedFile Uploaded file info. * @return HttpUploadedFile Uploaded file info.
*/ */
public static function createFromFILE(array $file): self { public static function createFromPhpFilesEntry(array $file): self {
return new HttpUploadedFile( return new HttpUploadedFile(
(int)($file['error'] ?? UPLOAD_ERR_NO_FILE), (int)($file['error'] ?? UPLOAD_ERR_NO_FILE),
(int)($file['size'] ?? -1), (int)($file['size'] ?? -1),
@ -182,18 +182,18 @@ class HttpUploadedFile implements ICloseable {
* @param array<string, mixed> $files Value of a $_FILES superglobal. * @param array<string, mixed> $files Value of a $_FILES superglobal.
* @return array<string, HttpUploadedFile|array<string, mixed>> Uploaded files. * @return array<string, HttpUploadedFile|array<string, mixed>> Uploaded files.
*/ */
public static function createFromFILES(array $files): array { public static function createFromPhpFiles(array $files): array {
if(empty($files)) if(empty($files))
return []; return [];
return self::createObjectInstances(self::normalizeFILES($files)); return self::createObjectInstances(self::normalizePhpFiles($files));
} }
/** /**
* @param array<string, mixed> $files * @param array<string, mixed> $files
* @return array<string, mixed> * @return array<string, mixed>
*/ */
private static function traverseFILES(array $files, string $keyName): array { private static function traversePhpFiles(array $files, string $keyName): array {
$arr = []; $arr = [];
foreach($files as $key => $val) { foreach($files as $key => $val) {
@ -201,7 +201,7 @@ class HttpUploadedFile implements ICloseable {
if(is_array($val)) { if(is_array($val)) {
/** @var array<string, mixed> $val */ /** @var array<string, mixed> $val */
$arr[$key] = self::traverseFILES($val, $keyName); $arr[$key] = self::traversePhpFiles($val, $keyName);
} else { } else {
$arr[$key][$keyName] = $val; $arr[$key][$keyName] = $val;
} }
@ -214,7 +214,7 @@ class HttpUploadedFile implements ICloseable {
* @param array<string, mixed> $files * @param array<string, mixed> $files
* @return array<string, mixed> * @return array<string, mixed>
*/ */
private static function normalizeFILES(array $files): array { private static function normalizePhpFiles(array $files): array {
$out = []; $out = [];
foreach($files as $key => $arr) { foreach($files as $key => $arr) {
@ -240,7 +240,7 @@ class HttpUploadedFile implements ICloseable {
$mergeWith = $out[$key] ?? []; $mergeWith = $out[$key] ?? [];
/** @var array<string, mixed> $source */ /** @var array<string, mixed> $source */
$out[$key] = array_merge_recursive($mergeWith, self::traverseFILES($source, (string)$keyName)); $out[$key] = array_merge_recursive($mergeWith, self::traversePhpFiles($source, (string)$keyName));
} }
continue; continue;
} }
@ -264,7 +264,7 @@ class HttpUploadedFile implements ICloseable {
if(isset($val['error'])) if(isset($val['error']))
/** @var array<string, int|string> $val */ /** @var array<string, int|string> $val */
$coll[$key] = self::createFromFILE($val); $coll[$key] = self::createFromPhpFilesEntry($val);
else else
/** @var array<string, mixed> $val */ /** @var array<string, mixed> $val */
$coll[$key] = self::createObjectInstances($val); $coll[$key] = self::createObjectInstances($val);

View file

@ -1,7 +1,7 @@
<?php <?php
// HttpRouter.php // HttpRouter.php
// Created: 2024-03-28 // Created: 2024-03-28
// Updated: 2024-08-18 // Updated: 2024-10-02
namespace Index\Http\Routing; namespace Index\Http\Routing;
@ -295,7 +295,7 @@ class HttpRouter implements IRouter {
if(!$response->hasContentType()) { if(!$response->hasContentType()) {
if(strtolower(substr($result, 0, 14)) === '<!doctype html') if(strtolower(substr($result, 0, 14)) === '<!doctype html')
$response->setTypeHTML($this->getCharSet()); $response->setTypeHtml($this->getCharSet());
else { else {
$charset = mb_detect_encoding($result); $charset = mb_detect_encoding($result);
if($charset !== false) if($charset !== false)
@ -303,7 +303,7 @@ class HttpRouter implements IRouter {
$charset = $charset === false ? 'utf-8' : strtolower($charset); $charset = $charset === false ? 'utf-8' : strtolower($charset);
if(strtolower(substr($result, 0, 5)) === '<?xml') if(strtolower(substr($result, 0, 5)) === '<?xml')
$response->setTypeXML($charset); $response->setTypeXml($charset);
else else
$response->setTypePlain($charset); $response->setTypePlain($charset);
} }

View file

@ -1,9 +1,9 @@
<?php <?php
// FileStream.php // FileStream.php
// Created: 2021-04-30 // Created: 2021-04-30
// Updated: 2024-08-01 // Updated: 2024-10-02
namespace Index\IO; namespace Index\Io;
use ErrorException; use ErrorException;
use RuntimeException; use RuntimeException;

View file

@ -1,9 +1,9 @@
<?php <?php
// GenericStream.php // GenericStream.php
// Created: 2021-04-30 // Created: 2021-04-30
// Updated: 2024-08-03 // Updated: 2024-10-02
namespace Index\IO; namespace Index\Io;
use InvalidArgumentException; use InvalidArgumentException;
use RuntimeException; use RuntimeException;

View file

@ -1,9 +1,9 @@
<?php <?php
// MemoryStream.php // MemoryStream.php
// Created: 2021-05-02 // Created: 2021-05-02
// Updated: 2024-08-03 // Updated: 2024-10-02
namespace Index\IO; namespace Index\Io;
use RuntimeException; use RuntimeException;

View file

@ -1,13 +1,13 @@
<?php <?php
// NetworkStream.php // NetworkStream.php
// Created: 2021-04-30 // Created: 2021-04-30
// Updated: 2024-08-01 // Updated: 2024-10-02
namespace Index\IO; namespace Index\Io;
use ErrorException; use ErrorException;
use RuntimeException; use RuntimeException;
use Index\Net\{IPAddress,EndPoint}; use Index\Net\{IpAddress,EndPoint};
/** /**
* Represents a network socket stream. * Represents a network socket stream.
@ -105,35 +105,35 @@ class NetworkStream extends GenericStream {
} }
/** /**
* Opens a network socket stream to an endpoint represented by an Index IPAddress instance and port. * Opens a network socket stream to an endpoint represented by an Index IpAddress instance and port.
* *
* @param IPAddress $address Address to connect to. * @param IpAddress $address Address 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.
*/ */
public static function openAddress(IPAddress $address, int $port, float|null $timeout = null): NetworkStream { public static function openAddress(IpAddress $address, int $port, float|null $timeout = null): NetworkStream {
return new NetworkStream($address->getAddress(), $port, $timeout); return new NetworkStream($address->getAddress(), $port, $timeout);
} }
/** /**
* Opens an SSL network socket stream to an endpoint represented by an Index IPAddress instance and port. * Opens an SSL network socket stream to an endpoint represented by an Index IpAddress instance and port.
* *
* @param IPAddress $address Address to connect to. * @param IpAddress $address Address 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.
*/ */
public static function openAddressSSL(IPAddress $address, int $port, float|null $timeout = null): NetworkStream { public static function openAddressSSL(IpAddress $address, int $port, float|null $timeout = null): NetworkStream {
return new NetworkStream('ssl://' . $address->getAddress(), $port, $timeout); return new NetworkStream('ssl://' . $address->getAddress(), $port, $timeout);
} }
/** /**
* Opens a TLS network socket stream to an endpoint represented by an Index IPAddress instance and port. * Opens a TLS network socket stream to an endpoint represented by an Index IpAddress instance and port.
* *
* @param IPAddress $address Address to connect to. * @param IpAddress $address Address 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.
*/ */
public static function openAddressTLS(IPAddress $address, int $port, float|null $timeout = null): NetworkStream { public static function openAddressTLS(IpAddress $address, int $port, float|null $timeout = null): NetworkStream {
return new NetworkStream('tls://' . $address->getAddress(), $port, $timeout); return new NetworkStream('tls://' . $address->getAddress(), $port, $timeout);
} }

View file

@ -1,9 +1,9 @@
<?php <?php
// ProcessStream.php // ProcessStream.php
// Created: 2023-01-25 // Created: 2023-01-25
// Updated: 2024-08-03 // Updated: 2024-10-02
namespace Index\IO; namespace Index\Io;
use InvalidArgumentException; use InvalidArgumentException;
use RuntimeException; use RuntimeException;

View file

@ -1,9 +1,9 @@
<?php <?php
// Stream.php // Stream.php
// Created: 2021-04-30 // Created: 2021-04-30
// Updated: 2024-08-03 // Updated: 2024-10-02
namespace Index\IO; namespace Index\Io;
use RuntimeException; use RuntimeException;
use Stringable; use Stringable;

View file

@ -1,9 +1,9 @@
<?php <?php
// TempFileStream.php // TempFileStream.php
// Created: 2021-05-02 // Created: 2021-05-02
// Updated: 2024-08-03 // Updated: 2024-10-02
namespace Index\IO; namespace Index\Io;
use RuntimeException; use RuntimeException;

View file

@ -1,7 +1,7 @@
<?php <?php
// EndPoint.php // EndPoint.php
// Created: 2021-04-30 // Created: 2021-04-30
// Updated: 2024-08-01 // Updated: 2024-10-02
namespace Index\Net; namespace Index\Net;
@ -38,14 +38,14 @@ abstract class EndPoint implements JsonSerializable, Stringable, IEquatable {
$endPoint = UnixEndPoint::parse($string); $endPoint = UnixEndPoint::parse($string);
elseif($firstChar === '[') { // IPv6 elseif($firstChar === '[') { // IPv6
if(str_contains($string, ']:')) if(str_contains($string, ']:'))
$endPoint = IPEndPoint::parse($string); $endPoint = IpEndPoint::parse($string);
else else
$endPoint = new IPEndPoint(IPAddress::parse(trim($string, '[]')), 0); $endPoint = new IpEndPoint(IpAddress::parse(trim($string, '[]')), 0);
} elseif(is_numeric($firstChar)) { // IPv4 } elseif(is_numeric($firstChar)) { // IPv4
if(str_contains($string, ':')) if(str_contains($string, ':'))
$endPoint = IPEndPoint::parse($string); $endPoint = IpEndPoint::parse($string);
else else
$endPoint = new IPEndPoint(IPAddress::parse($string), 0); $endPoint = new IpEndPoint(IpAddress::parse($string), 0);
} else { // DNS } else { // DNS
if(str_contains($string, ':')) if(str_contains($string, ':'))
$endPoint = DnsEndPoint::parse($string); $endPoint = DnsEndPoint::parse($string);

View file

@ -1,7 +1,7 @@
<?php <?php
// IPAddress.php // IpAddress.php
// Created: 2021-04-26 // Created: 2021-04-26
// Updated: 2024-08-03 // Updated: 2024-10-02
namespace Index\Net; namespace Index\Net;
@ -13,7 +13,7 @@ use Index\IEquatable;
/** /**
* Represents an IP address. * Represents an IP address.
*/ */
final class IPAddress implements JsonSerializable, Stringable, IEquatable { final class IpAddress implements JsonSerializable, Stringable, IEquatable {
/** /**
* Unknown IP version. * Unknown IP version.
* *
@ -128,7 +128,7 @@ final class IPAddress implements JsonSerializable, Stringable, IEquatable {
} }
public function equals(mixed $other): bool { public function equals(mixed $other): bool {
return $other instanceof IPAddress && $this->getRaw() === $other->getRaw(); return $other instanceof IpAddress && $this->getRaw() === $other->getRaw();
} }
#[\Override] #[\Override]
@ -151,7 +151,7 @@ final class IPAddress implements JsonSerializable, Stringable, IEquatable {
* *
* @param string $string String to parse. * @param string $string String to parse.
* @throws InvalidArgumentException If $string does not contain a valid IP address string. * @throws InvalidArgumentException If $string does not contain a valid IP address string.
* @return IPAddress Representation of the given string. * @return IpAddress Representation of the given string.
*/ */
public static function parse(string $string): self { public static function parse(string $string): self {
$parsed = inet_pton($string); $parsed = inet_pton($string);

View file

@ -1,7 +1,7 @@
<?php <?php
// IPAddressRange.php // IpAddressRange.php
// Created: 2021-04-26 // Created: 2021-04-26
// Updated: 2024-08-03 // Updated: 2024-10-02
namespace Index\Net; namespace Index\Net;
@ -13,22 +13,22 @@ use Index\IEquatable;
/** /**
* Represents a CIDR range of IP addresses. * Represents a CIDR range of IP addresses.
*/ */
final class IPAddressRange implements JsonSerializable, Stringable, IEquatable { final class IpAddressRange implements JsonSerializable, Stringable, IEquatable {
/** /**
* @param IPAddress $base Base IP address. * @param IpAddress $base Base IP address.
* @param int $mask CIDR mask. * @param int $mask CIDR mask.
*/ */
public function __construct( public function __construct(
private IPAddress $base, private IpAddress $base,
private int $mask private int $mask
) {} ) {}
/** /**
* Retrieves the base IP address. * Retrieves the base IP address.
* *
* @return IPAddress Base IP address. * @return IpAddress Base IP address.
*/ */
public function getBaseAddress(): IPAddress { public function getBaseAddress(): IpAddress {
return $this->base; return $this->base;
} }
@ -55,7 +55,7 @@ final class IPAddressRange implements JsonSerializable, Stringable, IEquatable {
} }
public function equals(mixed $other): bool { public function equals(mixed $other): bool {
return $other instanceof IPAddressRange return $other instanceof IpAddressRange
&& $this->mask === $other->mask && $this->mask === $other->mask
&& $this->base->equals($other->base); && $this->base->equals($other->base);
} }
@ -63,10 +63,10 @@ final class IPAddressRange implements JsonSerializable, Stringable, IEquatable {
/** /**
* Checks if a given IP address matches with this range. * Checks if a given IP address matches with this range.
* *
* @param IPAddress $address IP address to check. * @param IpAddress $address IP address to check.
* @return bool true if the address matches. * @return bool true if the address matches.
*/ */
public function match(IPAddress $address): bool { public function match(IpAddress $address): bool {
$width = $this->base->getWidth(); $width = $this->base->getWidth();
if($address->getWidth() !== $width) if($address->getWidth() !== $width)
return false; return false;
@ -111,7 +111,7 @@ final class IPAddressRange implements JsonSerializable, Stringable, IEquatable {
/** @param array{b: string, m: int} $serialized */ /** @param array{b: string, m: int} $serialized */
public function __unserialize(array $serialized): void { public function __unserialize(array $serialized): void {
$this->base = new IPAddress($serialized['b']); $this->base = new IpAddress($serialized['b']);
$this->mask = $serialized['m']; $this->mask = $serialized['m'];
} }
@ -120,12 +120,12 @@ final class IPAddressRange implements JsonSerializable, Stringable, IEquatable {
* *
* @param string $string String to parse. * @param string $string String to parse.
* @throws InvalidArgumentException If $string does not contain a valid CIDR range string. * @throws InvalidArgumentException If $string does not contain a valid CIDR range string.
* @return IPAddressRange Representation of the given string. * @return IpAddressRange Representation of the given string.
*/ */
public static function parse(string $string): IPAddressRange { public static function parse(string $string): IpAddressRange {
$parts = explode('/', $string, 2); $parts = explode('/', $string, 2);
if(empty($parts[0]) || empty($parts[1])) if(empty($parts[0]) || empty($parts[1]))
throw new InvalidArgumentException('$string is not a valid CIDR range.'); throw new InvalidArgumentException('$string is not a valid CIDR range.');
return new static(IPAddress::parse($parts[0]), (int)$parts[1]); return new static(IpAddress::parse($parts[0]), (int)$parts[1]);
} }
} }

View file

@ -1,7 +1,7 @@
<?php <?php
// IPEndPoint.php // IpEndPoint.php
// Created: 2021-04-30 // Created: 2021-04-30
// Updated: 2024-08-03 // Updated: 2024-10-02
namespace Index\Net; namespace Index\Net;
@ -11,14 +11,14 @@ use Index\XString;
/** /**
* Represents an IP address end point. * Represents an IP address end point.
*/ */
class IPEndPoint extends EndPoint { class IpEndPoint extends EndPoint {
/** /**
* @param IPAddress $address IP address. * @param IpAddress $address IP address.
* @param int $port Network port, 0 to leave default. * @param int $port Network port, 0 to leave default.
* @throws InvalidArgumentException If $port is less than 0 or greater than 65535. * @throws InvalidArgumentException If $port is less than 0 or greater than 65535.
*/ */
public function __construct( public function __construct(
private IPAddress $address, private IpAddress $address,
private int $port private int $port
) { ) {
if($port < 0 || $port > 0xFFFF) if($port < 0 || $port > 0xFFFF)
@ -28,9 +28,9 @@ class IPEndPoint extends EndPoint {
/** /**
* Returns the IP address. * Returns the IP address.
* *
* @return IPAddress IP address. * @return IpAddress IP address.
*/ */
public function getAddress(): IPAddress { public function getAddress(): IpAddress {
return $this->address; return $this->address;
} }
@ -56,14 +56,14 @@ class IPEndPoint extends EndPoint {
return [$this->address, $this->port]; return [$this->address, $this->port];
} }
/** @param array{IPAddress, int} $serialized */ /** @param array{IpAddress, int} $serialized */
public function __unserialize(array $serialized): void { public function __unserialize(array $serialized): void {
$this->address = $serialized[0]; $this->address = $serialized[0];
$this->port = $serialized[1]; $this->port = $serialized[1];
} }
public function equals(mixed $other): bool { public function equals(mixed $other): bool {
return $other instanceof IPEndPoint return $other instanceof IpEndPoint
&& $this->port === $other->port && $this->port === $other->port
&& $this->address->equals($other->address); && $this->address->equals($other->address);
} }
@ -73,9 +73,9 @@ class IPEndPoint extends EndPoint {
* *
* @param string $string String to parse. * @param string $string String to parse.
* @throws InvalidArgumentException If $string does not contain a valid IP end point string. * @throws InvalidArgumentException If $string does not contain a valid IP end point string.
* @return IPEndPoint Representation of the given string. * @return IpEndPoint Representation of the given string.
*/ */
public static function parse(string $string): IPEndPoint { public static function parse(string $string): IpEndPoint {
if(str_starts_with($string, '[')) { // IPv6 if(str_starts_with($string, '[')) { // IPv6
$closing = strpos($string, ']'); $closing = strpos($string, ']');
if($closing === false) if($closing === false)
@ -90,7 +90,7 @@ class IPEndPoint extends EndPoint {
$port = (int)$parts[1]; $port = (int)$parts[1];
} }
return new IPEndPoint(IPAddress::parse($ip), $port); return new IpEndPoint(IpAddress::parse($ip), $port);
} }
public function __toString(): string { public function __toString(): string {

View file

@ -1,7 +1,7 @@
<?php <?php
// XDateTime.php // XDateTime.php
// Created: 2024-07-31 // Created: 2024-07-31
// Updated: 2024-08-03 // Updated: 2024-10-02
namespace Index; namespace Index;
@ -143,7 +143,7 @@ final class XDateTime {
* @param DateTimeInterface|string|int|null $dt Date time to format, null for now. * @param DateTimeInterface|string|int|null $dt Date time to format, null for now.
* @return string ISO-8601 date time string. * @return string ISO-8601 date time string.
*/ */
public static function toISO8601String(DateTimeInterface|string|int|null $dt): string { public static function toIso8601String(DateTimeInterface|string|int|null $dt): string {
return self::format($dt, DateTimeInterface::ATOM); return self::format($dt, DateTimeInterface::ATOM);
} }
@ -163,7 +163,7 @@ final class XDateTime {
* @param DateTimeInterface|string|int|null $dt Date time to format, null for now. * @param DateTimeInterface|string|int|null $dt Date time to format, null for now.
* @return string RFC 822 date time string. * @return string RFC 822 date time string.
*/ */
public static function toRFC822String(DateTimeInterface|string|int|null $dt): string { public static function toRfc822String(DateTimeInterface|string|int|null $dt): string {
return self::format($dt, DateTimeInterface::RFC822); return self::format($dt, DateTimeInterface::RFC822);
} }
} }

View file

@ -1,7 +1,7 @@
<?php <?php
// CacheToolsTest.php // CacheToolsTest.php
// Created: 2024-04-10 // Created: 2024-04-10
// Updated: 2024-08-01 // Updated: 2024-10-02
declare(strict_types=1); declare(strict_types=1);
@ -11,7 +11,7 @@ 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;
use Index\Cache\Valkey\ValkeyBackend; use Index\Cache\Valkey\ValkeyBackend;
use Index\Net\{DnsEndPoint,IPEndPoint,UnixEndPoint}; use Index\Net\{DnsEndPoint,IpEndPoint,UnixEndPoint};
#[CoversClass(CacheTools::class)] #[CoversClass(CacheTools::class)]
#[CoversClass(ArrayCacheBackend::class)] #[CoversClass(ArrayCacheBackend::class)]
@ -19,7 +19,7 @@ use Index\Net\{DnsEndPoint,IPEndPoint,UnixEndPoint};
#[CoversClass(MemcachedBackend::class)] #[CoversClass(MemcachedBackend::class)]
#[CoversClass(ValkeyBackend::class)] #[CoversClass(ValkeyBackend::class)]
#[UsesClass(DnsEndPoint::class)] #[UsesClass(DnsEndPoint::class)]
#[UsesClass(IPEndPoint::class)] #[UsesClass(IpEndPoint::class)]
#[UsesClass(UnixEndPoint::class)] #[UsesClass(UnixEndPoint::class)]
final class CacheToolsTest extends TestCase { final class CacheToolsTest extends TestCase {
public function testBasicDSN(): void { public function testBasicDSN(): void {
@ -53,7 +53,7 @@ final class CacheToolsTest extends TestCase {
$endPoints = $info->getEndPoints(); $endPoints = $info->getEndPoints();
$this->assertEquals(1, count($endPoints)); $this->assertEquals(1, count($endPoints));
$this->assertInstanceOf(IPEndPoint::class, $endPoints[0][0]); $this->assertInstanceOf(IpEndPoint::class, $endPoints[0][0]);
$this->assertEquals('127.0.0.1', (string)$endPoints[0][0]->getAddress()); $this->assertEquals('127.0.0.1', (string)$endPoints[0][0]->getAddress());
$this->assertEquals(0, $endPoints[0][0]->getPort()); $this->assertEquals(0, $endPoints[0][0]->getPort());
$this->assertEquals(0, $endPoints[0][1]); $this->assertEquals(0, $endPoints[0][1]);
@ -69,7 +69,7 @@ final class CacheToolsTest extends TestCase {
$endPoints = $info->getEndPoints(); $endPoints = $info->getEndPoints();
$this->assertEquals(1, count($endPoints)); $this->assertEquals(1, count($endPoints));
$this->assertInstanceOf(IPEndPoint::class, $endPoints[0][0]); $this->assertInstanceOf(IpEndPoint::class, $endPoints[0][0]);
$this->assertEquals('::1', (string)$endPoints[0][0]->getAddress()); $this->assertEquals('::1', (string)$endPoints[0][0]->getAddress());
$this->assertEquals(9001, $endPoints[0][0]->getPort()); $this->assertEquals(9001, $endPoints[0][0]->getPort());
$this->assertEquals(0, $endPoints[0][1]); $this->assertEquals(0, $endPoints[0][1]);
@ -106,12 +106,12 @@ final class CacheToolsTest extends TestCase {
$this->assertEquals('/var/run/memcached.sock', $endPoints[0][0]->getPath()); $this->assertEquals('/var/run/memcached.sock', $endPoints[0][0]->getPath());
$this->assertEquals(20, $endPoints[0][1]); $this->assertEquals(20, $endPoints[0][1]);
$this->assertInstanceOf(IPEndPoint::class, $endPoints[1][0]); $this->assertInstanceOf(IpEndPoint::class, $endPoints[1][0]);
$this->assertEquals('127.0.0.1', (string)$endPoints[1][0]->getAddress()); $this->assertEquals('127.0.0.1', (string)$endPoints[1][0]->getAddress());
$this->assertEquals(0, $endPoints[1][0]->getPort()); $this->assertEquals(0, $endPoints[1][0]->getPort());
$this->assertEquals(10, $endPoints[1][1]); $this->assertEquals(10, $endPoints[1][1]);
$this->assertInstanceOf(IPEndPoint::class, $endPoints[2][0]); $this->assertInstanceOf(IpEndPoint::class, $endPoints[2][0]);
$this->assertEquals('::1', (string)$endPoints[2][0]->getAddress()); $this->assertEquals('::1', (string)$endPoints[2][0]->getAddress());
$this->assertEquals(9001, $endPoints[2][0]->getPort()); $this->assertEquals(9001, $endPoints[2][0]->getPort());
$this->assertEquals(5, $endPoints[2][1]); $this->assertEquals(5, $endPoints[2][1]);
@ -150,7 +150,7 @@ final class CacheToolsTest extends TestCase {
// ipv4 // ipv4
$info = $valkey->parseDsn('keydb://password@127.0.0.1:6379?db=123'); $info = $valkey->parseDsn('keydb://password@127.0.0.1:6379?db=123');
$this->assertInstanceOf(IPEndPoint::class, $info->getEndPoint()); $this->assertInstanceOf(IpEndPoint::class, $info->getEndPoint());
$this->assertEquals('127.0.0.1', $info->getServerHost()); $this->assertEquals('127.0.0.1', $info->getServerHost());
$this->assertEquals(6379, $info->getServerPort()); $this->assertEquals(6379, $info->getServerPort());
$this->assertEmpty($info->getPrefix()); $this->assertEmpty($info->getPrefix());
@ -165,7 +165,7 @@ final class CacheToolsTest extends TestCase {
// ipv6 // ipv6
$info = $valkey->parseDsn('redis://username:password@[::1]/?persist&db=1'); $info = $valkey->parseDsn('redis://username:password@[::1]/?persist&db=1');
$this->assertInstanceOf(IPEndPoint::class, $info->getEndPoint()); $this->assertInstanceOf(IpEndPoint::class, $info->getEndPoint());
$this->assertEquals('::1', $info->getServerHost()); $this->assertEquals('::1', $info->getServerHost());
$this->assertEquals(0, $info->getServerPort()); $this->assertEquals(0, $info->getServerPort());
$this->assertEmpty($info->getPrefix()); $this->assertEmpty($info->getPrefix());

View file

@ -1,19 +1,19 @@
<?php <?php
// ColourTest.php // ColourTest.php
// Created: 2023-01-02 // Created: 2023-01-02
// Updated: 2024-08-01 // Updated: 2024-10-02
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,ColourHSL,ColourNamed,ColourNull,ColourRGB}; use Index\Colour\{Colour,ColourHsl,ColourNamed,ColourNull,ColourRgb};
#[CoversClass(Colour::class)] #[CoversClass(Colour::class)]
#[CoversClass(ColourHSL::class)] #[CoversClass(ColourHsl::class)]
#[CoversClass(ColourNamed::class)] #[CoversClass(ColourNamed::class)]
#[CoversClass(ColourNull::class)] #[CoversClass(ColourNull::class)]
#[CoversClass(ColourRGB::class)] #[CoversClass(ColourRgb::class)]
final class ColourTest extends TestCase { final class ColourTest extends TestCase {
public function testNone(): void { public function testNone(): void {
$none = Colour::none(); $none = Colour::none();
@ -25,14 +25,14 @@ final class ColourTest extends TestCase {
public function testLuminance(): void { public function testLuminance(): void {
for($i = 0; $i < 0xB; ++$i) { for($i = 0; $i < 0xB; ++$i) {
$num = ($i << 4) | $i; $num = ($i << 4) | $i;
$colour = new ColourRGB($num, $num, $num, 1); $colour = new ColourRgb($num, $num, $num, 1);
$this->assertTrue($colour->isDark()); $this->assertTrue($colour->isDark());
$this->assertFalse($colour->isLight()); $this->assertFalse($colour->isLight());
} }
for($i = 0xB; $i < 0x10; ++$i) { for($i = 0xB; $i < 0x10; ++$i) {
$num = ($i << 4) | $i; $num = ($i << 4) | $i;
$colour = new ColourRGB($num, $num, $num, 1); $colour = new ColourRgb($num, $num, $num, 1);
$this->assertFalse($colour->isDark()); $this->assertFalse($colour->isDark());
$this->assertTrue($colour->isLight()); $this->assertTrue($colour->isLight());
} }
@ -70,45 +70,45 @@ final class ColourTest extends TestCase {
} }
public function testRGB(): void { public function testRGB(): void {
$colour = new ColourRGB(31, 120, 50, 1.0); $colour = new ColourRgb(31, 120, 50, 1.0);
$this->assertEquals(31, $colour->getRed()); $this->assertEquals(31, $colour->getRed());
$this->assertEquals(120, $colour->getGreen()); $this->assertEquals(120, $colour->getGreen());
$this->assertEquals(50, $colour->getBlue()); $this->assertEquals(50, $colour->getBlue());
$this->assertEquals(1.0, $colour->getAlpha()); $this->assertEquals(1.0, $colour->getAlpha());
$this->assertInstanceOf(ColourRGB::class, $colour); $this->assertInstanceOf(ColourRgb::class, $colour);
$this->assertFalse($colour->shouldInherit()); $this->assertFalse($colour->shouldInherit());
$this->assertFalse($colour->isLight()); $this->assertFalse($colour->isLight());
$this->assertTrue($colour->isDark()); $this->assertTrue($colour->isDark());
$this->assertEquals('#1f7832', $colour); $this->assertEquals('#1f7832', $colour);
$colour = ColourRGB::fromRawARGB(0xCCFF7A7F); $colour = ColourRgb::fromRawArgb(0xCCFF7A7F);
$this->assertEquals(255, $colour->getRed()); $this->assertEquals(255, $colour->getRed());
$this->assertEquals(122, $colour->getGreen()); $this->assertEquals(122, $colour->getGreen());
$this->assertEquals(127, $colour->getBlue()); $this->assertEquals(127, $colour->getBlue());
$this->assertEquals(.8, $colour->getAlpha()); $this->assertEquals(.8, $colour->getAlpha());
$this->assertInstanceOf(ColourRGB::class, $colour); $this->assertInstanceOf(ColourRgb::class, $colour);
$this->assertFalse($colour->shouldInherit()); $this->assertFalse($colour->shouldInherit());
$this->assertFalse($colour->isLight()); $this->assertFalse($colour->isLight());
$this->assertTrue($colour->isDark()); $this->assertTrue($colour->isDark());
$this->assertEquals('rgba(255, 122, 127, 0.8)', $colour); $this->assertEquals('rgba(255, 122, 127, 0.8)', $colour);
$colour = ColourRGB::fromRawRGB(0x4D3380); $colour = ColourRgb::fromRawRgb(0x4D3380);
$this->assertEquals(77, $colour->getRed()); $this->assertEquals(77, $colour->getRed());
$this->assertEquals(51, $colour->getGreen()); $this->assertEquals(51, $colour->getGreen());
$this->assertEquals(128, $colour->getBlue()); $this->assertEquals(128, $colour->getBlue());
$this->assertEquals(1.0, $colour->getAlpha()); $this->assertEquals(1.0, $colour->getAlpha());
$this->assertInstanceOf(ColourRGB::class, $colour); $this->assertInstanceOf(ColourRgb::class, $colour);
$this->assertFalse($colour->shouldInherit()); $this->assertFalse($colour->shouldInherit());
$this->assertFalse($colour->isLight()); $this->assertFalse($colour->isLight());
$this->assertTrue($colour->isDark()); $this->assertTrue($colour->isDark());
$this->assertEquals('#4d3380', $colour); $this->assertEquals('#4d3380', $colour);
$colour = ColourRGB::fromRawRGBA(0xFF7A7F33); $colour = ColourRgb::fromRawRgba(0xFF7A7F33);
$this->assertEquals(255, $colour->getRed()); $this->assertEquals(255, $colour->getRed());
$this->assertEquals(122, $colour->getGreen()); $this->assertEquals(122, $colour->getGreen());
$this->assertEquals(127, $colour->getBlue()); $this->assertEquals(127, $colour->getBlue());
$this->assertEquals(.2, $colour->getAlpha()); $this->assertEquals(.2, $colour->getAlpha());
$this->assertInstanceOf(ColourRGB::class, $colour); $this->assertInstanceOf(ColourRgb::class, $colour);
$this->assertFalse($colour->shouldInherit()); $this->assertFalse($colour->shouldInherit());
$this->assertFalse($colour->isLight()); $this->assertFalse($colour->isLight());
$this->assertTrue($colour->isDark()); $this->assertTrue($colour->isDark());
@ -116,41 +116,41 @@ final class ColourTest extends TestCase {
} }
public function testConvertToRGB(): void { public function testConvertToRGB(): void {
$colourA = new ColourRGB(31, 120, 50, 1.0); $colourA = new ColourRgb(31, 120, 50, 1.0);
$colourB = ColourRGB::convert($colourA); $colourB = ColourRgb::convert($colourA);
$this->assertSame($colourA, $colourB); // converting to the same type should passthru $this->assertSame($colourA, $colourB); // converting to the same type should passthru
$colourA = Colour::none(); $colourA = Colour::none();
$colourB = ColourRGB::convert($colourA); // converting none to RGB makes very little sense, but you can do it if you want... $colourB = ColourRgb::convert($colourA); // converting none to RGB makes very little sense, but you can do it if you want...
$this->assertEquals(0, $colourB->getRed()); $this->assertEquals(0, $colourB->getRed());
$this->assertEquals(0, $colourB->getGreen()); $this->assertEquals(0, $colourB->getGreen());
$this->assertEquals(0, $colourB->getBlue()); $this->assertEquals(0, $colourB->getBlue());
$this->assertEquals(1.0, $colourB->getAlpha()); $this->assertEquals(1.0, $colourB->getAlpha());
$this->assertInstanceOf(ColourRGB::class, $colourB); $this->assertInstanceOf(ColourRgb::class, $colourB);
$this->assertFalse($colourB->shouldInherit()); // it does lose the inherit flag, which is intentional $this->assertFalse($colourB->shouldInherit()); // it does lose the inherit flag, which is intentional
$this->assertFalse($colourB->isLight()); $this->assertFalse($colourB->isLight());
$this->assertTrue($colourB->isDark()); $this->assertTrue($colourB->isDark());
$this->assertEquals('#000000', $colourB); $this->assertEquals('#000000', $colourB);
$colourA = new ColourNamed('steelblue'); $colourA = new ColourNamed('steelblue');
$colourB = ColourRGB::convert($colourA); $colourB = ColourRgb::convert($colourA);
$this->assertEquals(0x46, $colourB->getRed()); $this->assertEquals(0x46, $colourB->getRed());
$this->assertEquals(0x82, $colourB->getGreen()); $this->assertEquals(0x82, $colourB->getGreen());
$this->assertEquals(0xB4, $colourB->getBlue()); $this->assertEquals(0xB4, $colourB->getBlue());
$this->assertEquals(1.0, $colourB->getAlpha()); $this->assertEquals(1.0, $colourB->getAlpha());
$this->assertInstanceOf(ColourRGB::class, $colourB); $this->assertInstanceOf(ColourRgb::class, $colourB);
$this->assertFalse($colourB->shouldInherit()); $this->assertFalse($colourB->shouldInherit());
$this->assertFalse($colourB->isLight()); $this->assertFalse($colourB->isLight());
$this->assertTrue($colourB->isDark()); $this->assertTrue($colourB->isDark());
$this->assertEquals('#4682b4', $colourB); $this->assertEquals('#4682b4', $colourB);
$colourA = new ColourHSL(50, .8, .4, 1.0); $colourA = new ColourHsl(50, .8, .4, 1.0);
$colourB = ColourRGB::convert($colourA); $colourB = ColourRgb::convert($colourA);
$this->assertEquals(0xB8, $colourB->getRed()); $this->assertEquals(0xB8, $colourB->getRed());
$this->assertEquals(0x9C, $colourB->getGreen()); $this->assertEquals(0x9C, $colourB->getGreen());
$this->assertEquals(0x14, $colourB->getBlue()); $this->assertEquals(0x14, $colourB->getBlue());
$this->assertEquals(1.0, $colourB->getAlpha()); $this->assertEquals(1.0, $colourB->getAlpha());
$this->assertInstanceOf(ColourRGB::class, $colourB); $this->assertInstanceOf(ColourRgb::class, $colourB);
$this->assertFalse($colourB->shouldInherit()); $this->assertFalse($colourB->shouldInherit());
$this->assertFalse($colourB->isLight()); $this->assertFalse($colourB->isLight());
$this->assertTrue($colourB->isDark()); $this->assertTrue($colourB->isDark());
@ -158,7 +158,7 @@ final class ColourTest extends TestCase {
} }
public function testHSL(): void { public function testHSL(): void {
$colour = new ColourHSL(50, .8, .4, 1.0); $colour = new ColourHsl(50, .8, .4, 1.0);
$this->assertEquals(50, $colour->getHue()); $this->assertEquals(50, $colour->getHue());
$this->assertEquals(.8, $colour->getSaturation()); $this->assertEquals(.8, $colour->getSaturation());
$this->assertEquals(.4, $colour->getLightness()); $this->assertEquals(.4, $colour->getLightness());
@ -166,13 +166,13 @@ final class ColourTest extends TestCase {
$this->assertEquals(0x9C, $colour->getGreen()); $this->assertEquals(0x9C, $colour->getGreen());
$this->assertEquals(0x14, $colour->getBlue()); $this->assertEquals(0x14, $colour->getBlue());
$this->assertEquals(1.0, $colour->getAlpha()); $this->assertEquals(1.0, $colour->getAlpha());
$this->assertInstanceOf(ColourHSL::class, $colour); $this->assertInstanceOf(ColourHsl::class, $colour);
$this->assertFalse($colour->shouldInherit()); $this->assertFalse($colour->shouldInherit());
$this->assertFalse($colour->isLight()); $this->assertFalse($colour->isLight());
$this->assertTrue($colour->isDark()); $this->assertTrue($colour->isDark());
$this->assertEquals('hsl(50deg, 80%, 40%)', $colour); $this->assertEquals('hsl(50deg, 80%, 40%)', $colour);
$colour = new ColourHSL(150, .3, .6, 1.0); $colour = new ColourHsl(150, .3, .6, 1.0);
$this->assertEquals(150, $colour->getHue()); $this->assertEquals(150, $colour->getHue());
$this->assertEquals(.3, $colour->getSaturation()); $this->assertEquals(.3, $colour->getSaturation());
$this->assertEquals(.6, $colour->getLightness()); $this->assertEquals(.6, $colour->getLightness());
@ -180,13 +180,13 @@ final class ColourTest extends TestCase {
$this->assertEquals(0xB8, $colour->getGreen()); $this->assertEquals(0xB8, $colour->getGreen());
$this->assertEquals(0x99, $colour->getBlue()); $this->assertEquals(0x99, $colour->getBlue());
$this->assertEquals(1.0, $colour->getAlpha()); $this->assertEquals(1.0, $colour->getAlpha());
$this->assertInstanceOf(ColourHSL::class, $colour); $this->assertInstanceOf(ColourHsl::class, $colour);
$this->assertFalse($colour->shouldInherit()); $this->assertFalse($colour->shouldInherit());
$this->assertFalse($colour->isLight()); $this->assertFalse($colour->isLight());
$this->assertTrue($colour->isDark()); $this->assertTrue($colour->isDark());
$this->assertEquals('hsl(150deg, 30%, 60%)', $colour); $this->assertEquals('hsl(150deg, 30%, 60%)', $colour);
$colour = new ColourHSL(108, .6, .45, .7); $colour = new ColourHsl(108, .6, .45, .7);
$this->assertEquals(108, $colour->getHue()); $this->assertEquals(108, $colour->getHue());
$this->assertEquals(.6, $colour->getSaturation()); $this->assertEquals(.6, $colour->getSaturation());
$this->assertEquals(.45, $colour->getLightness()); $this->assertEquals(.45, $colour->getLightness());
@ -194,13 +194,13 @@ final class ColourTest extends TestCase {
$this->assertEquals(0xB8, $colour->getGreen()); $this->assertEquals(0xB8, $colour->getGreen());
$this->assertEquals(0x2E, $colour->getBlue()); $this->assertEquals(0x2E, $colour->getBlue());
$this->assertEquals(.7, $colour->getAlpha()); $this->assertEquals(.7, $colour->getAlpha());
$this->assertInstanceOf(ColourHSL::class, $colour); $this->assertInstanceOf(ColourHsl::class, $colour);
$this->assertFalse($colour->shouldInherit()); $this->assertFalse($colour->shouldInherit());
$this->assertFalse($colour->isLight()); $this->assertFalse($colour->isLight());
$this->assertTrue($colour->isDark()); $this->assertTrue($colour->isDark());
$this->assertEquals('hsla(108deg, 60%, 45%, 0.7)', $colour); $this->assertEquals('hsla(108deg, 60%, 45%, 0.7)', $colour);
$colour = new ColourHSL(0, .8, .5, .25); $colour = new ColourHsl(0, .8, .5, .25);
$this->assertEquals(0, $colour->getHue()); $this->assertEquals(0, $colour->getHue());
$this->assertEquals(.8, $colour->getSaturation()); $this->assertEquals(.8, $colour->getSaturation());
$this->assertEquals(.5, $colour->getLightness()); $this->assertEquals(.5, $colour->getLightness());
@ -208,7 +208,7 @@ final class ColourTest extends TestCase {
$this->assertEquals(0x1A, $colour->getGreen()); $this->assertEquals(0x1A, $colour->getGreen());
$this->assertEquals(0x1A, $colour->getBlue()); $this->assertEquals(0x1A, $colour->getBlue());
$this->assertEquals(.25, $colour->getAlpha()); $this->assertEquals(.25, $colour->getAlpha());
$this->assertInstanceOf(ColourHSL::class, $colour); $this->assertInstanceOf(ColourHsl::class, $colour);
$this->assertFalse($colour->shouldInherit()); $this->assertFalse($colour->shouldInherit());
$this->assertFalse($colour->isLight()); $this->assertFalse($colour->isLight());
$this->assertTrue($colour->isDark()); $this->assertTrue($colour->isDark());
@ -216,12 +216,12 @@ final class ColourTest extends TestCase {
} }
public function testConvertToHSL(): void { public function testConvertToHSL(): void {
$colourA = new ColourHSL(50, .8, .4, 1.0); $colourA = new ColourHsl(50, .8, .4, 1.0);
$colourB = ColourHSL::convert($colourA); $colourB = ColourHsl::convert($colourA);
$this->assertSame($colourA, $colourB); // converting to the same type should passthru $this->assertSame($colourA, $colourB); // converting to the same type should passthru
$colourA = Colour::none(); $colourA = Colour::none();
$colourB = ColourHSL::convert($colourA); // converting none to HSL makes very little sense, but you can do it if you want... $colourB = ColourHsl::convert($colourA); // converting none to HSL makes very little sense, but you can do it if you want...
$this->assertEquals(0, $colourB->getHue()); $this->assertEquals(0, $colourB->getHue());
$this->assertEquals(0, $colourB->getSaturation()); $this->assertEquals(0, $colourB->getSaturation());
$this->assertEquals(0, $colourB->getLightness()); $this->assertEquals(0, $colourB->getLightness());
@ -229,14 +229,14 @@ final class ColourTest extends TestCase {
$this->assertEquals(0, $colourB->getGreen()); $this->assertEquals(0, $colourB->getGreen());
$this->assertEquals(0, $colourB->getBlue()); $this->assertEquals(0, $colourB->getBlue());
$this->assertEquals(1.0, $colourB->getAlpha()); $this->assertEquals(1.0, $colourB->getAlpha());
$this->assertInstanceOf(ColourHSL::class, $colourB); $this->assertInstanceOf(ColourHsl::class, $colourB);
$this->assertFalse($colourB->shouldInherit()); // it does lose the inherit flag, which is intentional $this->assertFalse($colourB->shouldInherit()); // it does lose the inherit flag, which is intentional
$this->assertFalse($colourB->isLight()); $this->assertFalse($colourB->isLight());
$this->assertTrue($colourB->isDark()); $this->assertTrue($colourB->isDark());
$this->assertEquals('hsl(0deg, 0%, 0%)', $colourB); $this->assertEquals('hsl(0deg, 0%, 0%)', $colourB);
$colourA = new ColourNamed('yellowgreen'); $colourA = new ColourNamed('yellowgreen');
$colourB = ColourHSL::convert($colourA); $colourB = ColourHsl::convert($colourA);
$this->assertEquals(79.742, $colourB->getHue()); $this->assertEquals(79.742, $colourB->getHue());
$this->assertEquals(.608, $colourB->getSaturation()); $this->assertEquals(.608, $colourB->getSaturation());
$this->assertEquals(.5, $colourB->getLightness()); $this->assertEquals(.5, $colourB->getLightness());
@ -244,14 +244,14 @@ final class ColourTest extends TestCase {
$this->assertEquals(0xCD, $colourB->getGreen()); $this->assertEquals(0xCD, $colourB->getGreen());
$this->assertEquals(0x32, $colourB->getBlue()); $this->assertEquals(0x32, $colourB->getBlue());
$this->assertEquals(1.0, $colourB->getAlpha()); $this->assertEquals(1.0, $colourB->getAlpha());
$this->assertInstanceOf(ColourHSL::class, $colourB); $this->assertInstanceOf(ColourHsl::class, $colourB);
$this->assertFalse($colourB->shouldInherit()); $this->assertFalse($colourB->shouldInherit());
$this->assertFalse($colourB->isLight()); $this->assertFalse($colourB->isLight());
$this->assertTrue($colourB->isDark()); $this->assertTrue($colourB->isDark());
$this->assertEquals('hsl(79.74deg, 61%, 50%)', $colourB); $this->assertEquals('hsl(79.74deg, 61%, 50%)', $colourB);
$colourA = new ColourRGB(31, 120, 50, 1.0); $colourA = new ColourRgb(31, 120, 50, 1.0);
$colourB = ColourHSL::convert($colourA); $colourB = ColourHsl::convert($colourA);
$this->assertEquals(132.809, $colourB->getHue()); $this->assertEquals(132.809, $colourB->getHue());
$this->assertEquals(.589, $colourB->getSaturation()); $this->assertEquals(.589, $colourB->getSaturation());
$this->assertEquals(.296, $colourB->getLightness()); $this->assertEquals(.296, $colourB->getLightness());
@ -259,7 +259,7 @@ final class ColourTest extends TestCase {
$this->assertEquals(0x78, $colourB->getGreen()); $this->assertEquals(0x78, $colourB->getGreen());
$this->assertEquals(0x32, $colourB->getBlue()); $this->assertEquals(0x32, $colourB->getBlue());
$this->assertEquals(1.0, $colourB->getAlpha()); $this->assertEquals(1.0, $colourB->getAlpha());
$this->assertInstanceOf(ColourHSL::class, $colourB); $this->assertInstanceOf(ColourHsl::class, $colourB);
$this->assertFalse($colourB->shouldInherit()); $this->assertFalse($colourB->shouldInherit());
$this->assertFalse($colourB->isLight()); $this->assertFalse($colourB->isLight());
$this->assertTrue($colourB->isDark()); $this->assertTrue($colourB->isDark());
@ -278,7 +278,7 @@ final class ColourTest extends TestCase {
$this->assertEquals(0xBB, $colour->getGreen()); $this->assertEquals(0xBB, $colour->getGreen());
$this->assertEquals(0xCC, $colour->getBlue()); $this->assertEquals(0xCC, $colour->getBlue());
$this->assertEquals(1.0, $colour->getAlpha()); $this->assertEquals(1.0, $colour->getAlpha());
$this->assertInstanceOf(ColourRGB::class, $colour); $this->assertInstanceOf(ColourRgb::class, $colour);
$this->assertFalse($colour->shouldInherit()); $this->assertFalse($colour->shouldInherit());
$this->assertFalse($colour->isLight()); $this->assertFalse($colour->isLight());
$this->assertTrue($colour->isDark()); $this->assertTrue($colour->isDark());
@ -290,7 +290,7 @@ final class ColourTest extends TestCase {
$this->assertEquals(0xD7, $colour->getGreen()); $this->assertEquals(0xD7, $colour->getGreen());
$this->assertEquals(0x19, $colour->getBlue()); $this->assertEquals(0x19, $colour->getBlue());
$this->assertEquals(1.0, $colour->getAlpha()); $this->assertEquals(1.0, $colour->getAlpha());
$this->assertInstanceOf(ColourRGB::class, $colour); $this->assertInstanceOf(ColourRgb::class, $colour);
$this->assertFalse($colour->shouldInherit()); $this->assertFalse($colour->shouldInherit());
$this->assertFalse($colour->isLight()); $this->assertFalse($colour->isLight());
$this->assertTrue($colour->isDark()); $this->assertTrue($colour->isDark());
@ -302,7 +302,7 @@ final class ColourTest extends TestCase {
$this->assertEquals(0, $colour->getGreen()); $this->assertEquals(0, $colour->getGreen());
$this->assertEquals(0, $colour->getBlue()); $this->assertEquals(0, $colour->getBlue());
$this->assertEquals(1.0, $colour->getAlpha()); $this->assertEquals(1.0, $colour->getAlpha());
$this->assertInstanceOf(ColourRGB::class, $colour); $this->assertInstanceOf(ColourRgb::class, $colour);
$this->assertFalse($colour->shouldInherit()); $this->assertFalse($colour->shouldInherit());
$this->assertFalse($colour->isLight()); $this->assertFalse($colour->isLight());
$this->assertTrue($colour->isDark()); $this->assertTrue($colour->isDark());
@ -314,7 +314,7 @@ final class ColourTest extends TestCase {
$this->assertEquals(0x53, $colour->getGreen()); $this->assertEquals(0x53, $colour->getGreen());
$this->assertEquals(0xC4, $colour->getBlue()); $this->assertEquals(0xC4, $colour->getBlue());
$this->assertEquals(1.0, $colour->getAlpha()); $this->assertEquals(1.0, $colour->getAlpha());
$this->assertInstanceOf(ColourRGB::class, $colour); $this->assertInstanceOf(ColourRgb::class, $colour);
$this->assertFalse($colour->shouldInherit()); $this->assertFalse($colour->shouldInherit());
$this->assertFalse($colour->isLight()); $this->assertFalse($colour->isLight());
$this->assertTrue($colour->isDark()); $this->assertTrue($colour->isDark());
@ -365,7 +365,7 @@ final class ColourTest extends TestCase {
$colour = Colour::parse('#123'); $colour = Colour::parse('#123');
$this->assertInstanceOf(ColourRGB::class, $colour); $this->assertInstanceOf(ColourRgb::class, $colour);
$this->assertFalse($colour->shouldInherit()); $this->assertFalse($colour->shouldInherit());
$this->assertEquals('#112233', $colour); $this->assertEquals('#112233', $colour);
$this->assertEquals(1, $colour->getAlpha()); $this->assertEquals(1, $colour->getAlpha());
@ -374,7 +374,7 @@ final class ColourTest extends TestCase {
$this->assertEquals(0x33, $colour->getBlue()); $this->assertEquals(0x33, $colour->getBlue());
$colour = Colour::parse('#3456'); $colour = Colour::parse('#3456');
$this->assertInstanceOf(ColourRGB::class, $colour); $this->assertInstanceOf(ColourRgb::class, $colour);
$this->assertFalse($colour->shouldInherit()); $this->assertFalse($colour->shouldInherit());
$this->assertEquals('rgba(51, 68, 85, 0.4)', $colour); $this->assertEquals('rgba(51, 68, 85, 0.4)', $colour);
$this->assertEquals(0.4, $colour->getAlpha()); $this->assertEquals(0.4, $colour->getAlpha());
@ -383,7 +383,7 @@ final class ColourTest extends TestCase {
$this->assertEquals(0x55, $colour->getBlue()); $this->assertEquals(0x55, $colour->getBlue());
$colour = Colour::parse('#9475b2'); $colour = Colour::parse('#9475b2');
$this->assertInstanceOf(ColourRGB::class, $colour); $this->assertInstanceOf(ColourRgb::class, $colour);
$this->assertFalse($colour->shouldInherit()); $this->assertFalse($colour->shouldInherit());
$this->assertEquals('#9475b2', $colour); $this->assertEquals('#9475b2', $colour);
$this->assertEquals(1, $colour->getAlpha()); $this->assertEquals(1, $colour->getAlpha());
@ -392,7 +392,7 @@ final class ColourTest extends TestCase {
$this->assertEquals(0xB2, $colour->getBlue()); $this->assertEquals(0xB2, $colour->getBlue());
$colour = Colour::parse('#8559A5b3'); $colour = Colour::parse('#8559A5b3');
$this->assertInstanceOf(ColourRGB::class, $colour); $this->assertInstanceOf(ColourRgb::class, $colour);
$this->assertFalse($colour->shouldInherit()); $this->assertFalse($colour->shouldInherit());
$this->assertEquals('rgba(133, 89, 165, 0.702)', $colour); $this->assertEquals('rgba(133, 89, 165, 0.702)', $colour);
$this->assertEquals(0.702, round($colour->getAlpha(), 3)); $this->assertEquals(0.702, round($colour->getAlpha(), 3));
@ -402,7 +402,7 @@ final class ColourTest extends TestCase {
$colour = Colour::parse('rgb( 17 , 34 , 51)'); $colour = Colour::parse('rgb( 17 , 34 , 51)');
$this->assertInstanceOf(ColourRGB::class, $colour); $this->assertInstanceOf(ColourRgb::class, $colour);
$this->assertFalse($colour->shouldInherit()); $this->assertFalse($colour->shouldInherit());
$this->assertEquals('#112233', $colour); $this->assertEquals('#112233', $colour);
$this->assertEquals(1, $colour->getAlpha()); $this->assertEquals(1, $colour->getAlpha());
@ -411,7 +411,7 @@ final class ColourTest extends TestCase {
$this->assertEquals(0x33, $colour->getBlue()); $this->assertEquals(0x33, $colour->getBlue());
$colour = Colour::parse('rgba(51 , 68, 85 ,0.4 )'); $colour = Colour::parse('rgba(51 , 68, 85 ,0.4 )');
$this->assertInstanceOf(ColourRGB::class, $colour); $this->assertInstanceOf(ColourRgb::class, $colour);
$this->assertFalse($colour->shouldInherit()); $this->assertFalse($colour->shouldInherit());
$this->assertEquals('rgba(51, 68, 85, 0.4)', $colour); $this->assertEquals('rgba(51, 68, 85, 0.4)', $colour);
$this->assertEquals(0.4, $colour->getAlpha()); $this->assertEquals(0.4, $colour->getAlpha());
@ -420,7 +420,7 @@ final class ColourTest extends TestCase {
$this->assertEquals(0x55, $colour->getBlue()); $this->assertEquals(0x55, $colour->getBlue());
$colour = Colour::parse('rgba( 148,117,178 )'); $colour = Colour::parse('rgba( 148,117,178 )');
$this->assertInstanceOf(ColourRGB::class, $colour); $this->assertInstanceOf(ColourRgb::class, $colour);
$this->assertFalse($colour->shouldInherit()); $this->assertFalse($colour->shouldInherit());
$this->assertEquals('#9475b2', $colour); $this->assertEquals('#9475b2', $colour);
$this->assertEquals(1, $colour->getAlpha()); $this->assertEquals(1, $colour->getAlpha());
@ -429,7 +429,7 @@ final class ColourTest extends TestCase {
$this->assertEquals(0xB2, $colour->getBlue()); $this->assertEquals(0xB2, $colour->getBlue());
$colour = Colour::parse('rgb(133 ,89,165,.700)'); $colour = Colour::parse('rgb(133 ,89,165,.700)');
$this->assertInstanceOf(ColourRGB::class, $colour); $this->assertInstanceOf(ColourRgb::class, $colour);
$this->assertFalse($colour->shouldInherit()); $this->assertFalse($colour->shouldInherit());
$this->assertEquals('rgba(133, 89, 165, 0.7)', $colour); $this->assertEquals('rgba(133, 89, 165, 0.7)', $colour);
$this->assertEquals(0.7, $colour->getAlpha()); $this->assertEquals(0.7, $colour->getAlpha());
@ -443,7 +443,7 @@ final class ColourTest extends TestCase {
// but should definitely be reviewed in the future // but should definitely be reviewed in the future
$colour = Colour::parse('hsla( 210 , 50 , 13 )'); $colour = Colour::parse('hsla( 210 , 50 , 13 )');
$this->assertInstanceOf(ColourHSL::class, $colour); $this->assertInstanceOf(ColourHsl::class, $colour);
$this->assertFalse($colour->shouldInherit()); $this->assertFalse($colour->shouldInherit());
$this->assertEquals('hsl(210deg, 50%, 13%)', $colour); $this->assertEquals('hsl(210deg, 50%, 13%)', $colour);
$this->assertEquals(1, $colour->getAlpha()); $this->assertEquals(1, $colour->getAlpha());
@ -455,7 +455,7 @@ final class ColourTest extends TestCase {
$this->assertEquals(50, $colour->getBlue()); $this->assertEquals(50, $colour->getBlue());
$colour = Colour::parse('hsl(210deg ,25%, 27% ,.6)'); $colour = Colour::parse('hsl(210deg ,25%, 27% ,.6)');
$this->assertInstanceOf(ColourHSL::class, $colour); $this->assertInstanceOf(ColourHsl::class, $colour);
$this->assertFalse($colour->shouldInherit()); $this->assertFalse($colour->shouldInherit());
$this->assertEquals('hsla(210deg, 25%, 27%, 0.6)', $colour); $this->assertEquals('hsla(210deg, 25%, 27%, 0.6)', $colour);
$this->assertEquals(.6, $colour->getAlpha()); $this->assertEquals(.6, $colour->getAlpha());
@ -467,7 +467,7 @@ final class ColourTest extends TestCase {
$this->assertEquals(86, $colour->getBlue()); $this->assertEquals(86, $colour->getBlue());
$colour = Colour::parse('hsl(300grad,28%,58)'); $colour = Colour::parse('hsl(300grad,28%,58)');
$this->assertInstanceOf(ColourHSL::class, $colour); $this->assertInstanceOf(ColourHsl::class, $colour);
$this->assertFalse($colour->shouldInherit()); $this->assertFalse($colour->shouldInherit());
$this->assertEquals('hsl(270deg, 28%, 58%)', $colour); $this->assertEquals('hsl(270deg, 28%, 58%)', $colour);
$this->assertEquals(1.0, $colour->getAlpha()); $this->assertEquals(1.0, $colour->getAlpha());
@ -479,7 +479,7 @@ final class ColourTest extends TestCase {
$this->assertEquals(178, $colour->getBlue()); $this->assertEquals(178, $colour->getBlue());
$colour = Colour::parse('hsl( 4.799rad ,30 , 50%)'); $colour = Colour::parse('hsl( 4.799rad ,30 , 50%)');
$this->assertInstanceOf(ColourHSL::class, $colour); $this->assertInstanceOf(ColourHsl::class, $colour);
$this->assertFalse($colour->shouldInherit()); $this->assertFalse($colour->shouldInherit());
$this->assertEquals('hsl(275deg, 30%, 50%)', $colour); $this->assertEquals('hsl(275deg, 30%, 50%)', $colour);
$this->assertEquals(1.0, $colour->getAlpha()); $this->assertEquals(1.0, $colour->getAlpha());
@ -491,7 +491,7 @@ final class ColourTest extends TestCase {
$this->assertEquals(166, $colour->getBlue()); $this->assertEquals(166, $colour->getBlue());
$colour = Colour::parse('hsl( .775turn , 13,60, .54)'); $colour = Colour::parse('hsl( .775turn , 13,60, .54)');
$this->assertInstanceOf(ColourHSL::class, $colour); $this->assertInstanceOf(ColourHsl::class, $colour);
$this->assertFalse($colour->shouldInherit()); $this->assertFalse($colour->shouldInherit());
$this->assertEquals('hsla(279deg, 13%, 60%, 0.54)', $colour); $this->assertEquals('hsla(279deg, 13%, 60%, 0.54)', $colour);
$this->assertEquals(0.54, $colour->getAlpha()); $this->assertEquals(0.54, $colour->getAlpha());
@ -517,7 +517,7 @@ final class ColourTest extends TestCase {
$this->assertFalse($mixed->shouldInherit()); $this->assertFalse($mixed->shouldInherit());
// probably a pretty naive test but its better than nothing // probably a pretty naive test but its better than nothing
$mixed = Colour::mix(new ColourRGB(0, 100, 50), new ColourRGB(100, 0, 50), 0.5); $mixed = Colour::mix(new ColourRgb(0, 100, 50), new ColourRgb(100, 0, 50), 0.5);
$this->assertEquals(50, $mixed->getRed()); $this->assertEquals(50, $mixed->getRed());
$this->assertEquals(50, $mixed->getGreen()); $this->assertEquals(50, $mixed->getGreen());
$this->assertEquals(50, $mixed->getBlue()); $this->assertEquals(50, $mixed->getBlue());

View file

@ -1,16 +1,16 @@
<?php <?php
// CSRFPTest.php // CsrfTokenTest.php
// Created: 2021-06-11 // Created: 2021-06-11
// Updated: 2024-07-31 // Updated: 2024-10-02
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\CSRFP; use Index\CsrfToken;
#[CoversClass(CSRFP::class)] #[CoversClass(CsrfToken::class)]
final class CSRFPTest extends TestCase { final class CsrfTokenTest extends TestCase {
private const SECRET_1 = 'oCtBmR7XS1dLOnGVoVi0wXwTLk7Ursn4'; private const SECRET_1 = 'oCtBmR7XS1dLOnGVoVi0wXwTLk7Ursn4';
private const SECRET_2 = 'v6H37MPa8NHmxVvL4AzNSxrWLVkiTfPHouyTto1LXOfOyoqSU7EaSorjdM4gXlq3'; private const SECRET_2 = 'v6H37MPa8NHmxVvL4AzNSxrWLVkiTfPHouyTto1LXOfOyoqSU7EaSorjdM4gXlq3';
@ -25,9 +25,9 @@ final class CSRFPTest extends TestCase {
private const P5M30S = (5 * 60) + 30; private const P5M30S = (5 * 60) + 30;
private const P29M59S = (29 * 60) + 59; private const P29M59S = (29 * 60) + 59;
public function testCSRFP(): void { public function testCsrfToken(): void {
$csrfp1 = new CSRFP(self::SECRET_1, '8.8.8.8!12345'); $csrfp1 = new CsrfToken(self::SECRET_1, '8.8.8.8!12345');
$csrfp2 = new CSRFP(self::SECRET_2, '127.0.0.1'); $csrfp2 = new CsrfToken(self::SECRET_2, '127.0.0.1');
$token1 = $csrfp1->createToken(self::TIMESTAMP_1); $token1 = $csrfp1->createToken(self::TIMESTAMP_1);
$token2 = $csrfp2->createToken(self::TIMESTAMP_1); $token2 = $csrfp2->createToken(self::TIMESTAMP_1);

View file

@ -1,23 +1,23 @@
<?php <?php
// DbToolsTest.php // DbToolsTest.php
// Created: 2021-04-28 // Created: 2021-04-28
// Updated: 2024-08-01 // Updated: 2024-10-02
declare(strict_types=1); declare(strict_types=1);
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\{CoversClass,UsesClass}; use PHPUnit\Framework\Attributes\{CoversClass,UsesClass};
use Index\Data\{DbTools,DbType}; use Index\Data\{DbTools,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;
use Index\IO\MemoryStream; use Index\Io\MemoryStream;
#[CoversClass(DbTools::class)] #[CoversClass(DbTools::class)]
#[CoversClass(DbType::class)] #[CoversClass(DbType::class)]
#[CoversClass(NullDbConnection::class)] #[CoversClass(NullDbConnection::class)]
#[CoversClass(MariaDBBackend::class)] #[CoversClass(MariaDbBackend::class)]
#[CoversClass(SQLiteBackend::class)] #[CoversClass(SqliteBackend::class)]
#[UsesClass(MemoryStream::class)] #[UsesClass(MemoryStream::class)]
final class DbToolsTest extends TestCase { final class DbToolsTest extends TestCase {
public function testDetectType(): void { public function testDetectType(): void {
@ -35,8 +35,8 @@ final class DbToolsTest extends TestCase {
$nullDbConn2 = DbTools::create('Index-Data-NullDb-NullDbBackend:'); $nullDbConn2 = DbTools::create('Index-Data-NullDb-NullDbBackend:');
$this->assertInstanceOf(NullDbConnection::class, $nullDbConn2); $this->assertInstanceOf(NullDbConnection::class, $nullDbConn2);
$maria = new MariaDBBackend; $maria = new MariaDbBackend;
$sqlite = new SQLiteBackend; $sqlite = new SqliteBackend;
// flashii style misuzu connections details // flashii style misuzu connections details
$mci1 = $maria->parseDsn('mariadb://flashii:TiFGzCTxzx0n2HYzmNZpa98j255X7W4B@:unix:/flashii/misuzu?socket=/var/run/mysqld/mysqld.sock&charset=utf8mb4&init=SET SESSION time_zone = \'+00:00\', sql_mode = \'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION\''); $mci1 = $maria->parseDsn('mariadb://flashii:TiFGzCTxzx0n2HYzmNZpa98j255X7W4B@:unix:/flashii/misuzu?socket=/var/run/mysqld/mysqld.sock&charset=utf8mb4&init=SET SESSION time_zone = \'+00:00\', sql_mode = \'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION\'');

View file

@ -1,41 +1,41 @@
<?php <?php
// IPAddressRangeTest.php // IpAddressRangeTest.php
// Created: 2021-04-27 // Created: 2021-04-27
// Updated: 2024-08-01 // Updated: 2024-10-02
declare(strict_types=1); declare(strict_types=1);
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\{CoversClass,UsesClass}; use PHPUnit\Framework\Attributes\{CoversClass,UsesClass};
use Index\Net\{IPAddress,IPAddressRange}; use Index\Net\{IpAddress,IpAddressRange};
#[CoversClass(IPAddressRange::class)] #[CoversClass(IpAddressRange::class)]
#[UsesClass(IPAddress::class)] #[UsesClass(IpAddress::class)]
final class IPAddressRangeTest extends TestCase { final class IpAddressRangeTest extends TestCase {
public function testParsing(): void { public function testParsing(): void {
$v4 = IPAddressRange::parse('127.0.0.1/23'); $v4 = IpAddressRange::parse('127.0.0.1/23');
$v6 = IPAddressRange::parse('::1/128'); $v6 = IpAddressRange::parse('::1/128');
$this->expectException(InvalidArgumentException::class); $this->expectException(InvalidArgumentException::class);
$v0 = IPAddressRange::parse('12.4:424::1/128'); $v0 = IpAddressRange::parse('12.4:424::1/128');
} }
public function testToString(): void { public function testToString(): void {
$v4 = IPAddressRange::parse('53.64.123.86/18'); $v4 = IpAddressRange::parse('53.64.123.86/18');
$this->assertEquals('53.64.123.86/18', (string)$v4); $this->assertEquals('53.64.123.86/18', (string)$v4);
$v6 = IPAddressRange::parse('abcd:1234::43:211a/86'); $v6 = IpAddressRange::parse('abcd:1234::43:211a/86');
$this->assertEquals('abcd:1234::43:211a/86', (string)$v6); $this->assertEquals('abcd:1234::43:211a/86', (string)$v6);
} }
public function testMatch(): void { public function testMatch(): void {
$v41 = IPAddress::parse('53.64.123.86'); $v41 = IpAddress::parse('53.64.123.86');
$v42 = IPAddress::parse('53.64.130.86'); $v42 = IpAddress::parse('53.64.130.86');
$v61 = IPAddress::parse('abcd:1234::43:211a'); $v61 = IpAddress::parse('abcd:1234::43:211a');
$v62 = IPAddress::parse('bbce:1535::73:212a'); $v62 = IpAddress::parse('bbce:1535::73:212a');
$r4 = IPAddressRange::parse('53.64.123.0/22'); $r4 = IpAddressRange::parse('53.64.123.0/22');
$r6 = IPAddressRange::parse('abcd:1234::43:211a/86'); $r6 = IpAddressRange::parse('abcd:1234::43:211a/86');
$this->assertTrue($r4->match($v41)); $this->assertTrue($r4->match($v41));
$this->assertFalse($r4->match($v42)); $this->assertFalse($r4->match($v42));
@ -51,7 +51,7 @@ final class IPAddressRangeTest extends TestCase {
]; ];
foreach($cidrs as $cidr) { foreach($cidrs as $cidr) {
$obj = IPAddressRange::parse($cidr); $obj = IpAddressRange::parse($cidr);
$ser = serialize($obj); $ser = serialize($obj);
$unser = unserialize($ser); $unser = unserialize($ser);
$this->assertTrue($obj->equals($unser)); $this->assertTrue($obj->equals($unser));

View file

@ -1,34 +1,34 @@
<?php <?php
// IPAddressTest.php // IpAddressTest.php
// Created: 2021-04-26 // Created: 2021-04-26
// Updated: 2024-07-31 // Updated: 2024-10-02
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\Net\IPAddress; use Index\Net\IpAddress;
#[CoversClass(IPAddress::class)] #[CoversClass(IpAddress::class)]
final class IPAddressTest extends TestCase { final class IpAddressTest extends TestCase {
public function testParsing(): void { public function testParsing(): void {
$v4 = IPAddress::parse('127.0.0.1'); $v4 = IpAddress::parse('127.0.0.1');
$this->assertEquals('127.0.0.1', $v4->getAddress()); $this->assertEquals('127.0.0.1', $v4->getAddress());
$v6 = IPAddress::parse('::1'); $v6 = IpAddress::parse('::1');
$this->assertEquals('[::1]', $v6->getAddress()); $this->assertEquals('[::1]', $v6->getAddress());
$this->expectException(InvalidArgumentException::class); $this->expectException(InvalidArgumentException::class);
$v0 = IPAddress::parse('12.4:424'); $v0 = IpAddress::parse('12.4:424');
} }
public function testVersion(): void { public function testVersion(): void {
$v4 = IPAddress::parse('123.53.65.34'); $v4 = IpAddress::parse('123.53.65.34');
$this->assertEquals(4, $v4->getVersion()); $this->assertEquals(4, $v4->getVersion());
$this->assertEquals(4, $v4->getWidth()); $this->assertEquals(4, $v4->getWidth());
$this->assertTrue($v4->isV4()); $this->assertTrue($v4->isV4());
$this->assertFalse($v4->isV6()); $this->assertFalse($v4->isV6());
$v6 = IPAddress::parse('23cd::43c4:2342:acde'); $v6 = IpAddress::parse('23cd::43c4:2342:acde');
$this->assertEquals(6, $v6->getVersion()); $this->assertEquals(6, $v6->getVersion());
$this->assertEquals(16, $v6->getWidth()); $this->assertEquals(16, $v6->getWidth());
$this->assertTrue($v6->isV6()); $this->assertTrue($v6->isV6());
@ -36,18 +36,18 @@ final class IPAddressTest extends TestCase {
} }
public function testToString(): void { public function testToString(): void {
$v4 = IPAddress::parse('53.64.123.86'); $v4 = IpAddress::parse('53.64.123.86');
$this->assertEquals('53.64.123.86', (string)$v4); $this->assertEquals('53.64.123.86', (string)$v4);
$v6 = IPAddress::parse('abcd:1234::43:211a'); $v6 = IpAddress::parse('abcd:1234::43:211a');
$this->assertEquals('abcd:1234::43:211a', (string)$v6); $this->assertEquals('abcd:1234::43:211a', (string)$v6);
} }
public function testEquals(): void { public function testEquals(): void {
$v41 = IPAddress::parse('53.64.123.86'); $v41 = IpAddress::parse('53.64.123.86');
$v42 = IPAddress::parse('123.53.65.34'); $v42 = IpAddress::parse('123.53.65.34');
$v61 = IPAddress::parse('abcd:1234::43:211a'); $v61 = IpAddress::parse('abcd:1234::43:211a');
$v62 = IPAddress::parse('23cd::43c4:2342:acde'); $v62 = IpAddress::parse('23cd::43c4:2342:acde');
$this->assertTrue($v41->equals($v41)); $this->assertTrue($v41->equals($v41));
$this->assertFalse($v42->equals($v41)); $this->assertFalse($v42->equals($v41));
@ -64,7 +64,7 @@ final class IPAddressTest extends TestCase {
]; ];
foreach($addrs as $addr) foreach($addrs as $addr)
$this->assertEquals(json_encode($addr), json_encode(IPAddress::parse($addr))); $this->assertEquals(json_encode($addr), json_encode(IpAddress::parse($addr)));
} }
public function testSerializable(): void { public function testSerializable(): void {
@ -76,7 +76,7 @@ final class IPAddressTest extends TestCase {
]; ];
foreach($addrs as $addr) { foreach($addrs as $addr) {
$obj = IPAddress::parse($addr); $obj = IpAddress::parse($addr);
$ser = serialize($obj); $ser = serialize($obj);
$unser = unserialize($ser); $unser = unserialize($ser);
$this->assertTrue($obj->equals($unser)); $this->assertTrue($obj->equals($unser));

View file

@ -1,7 +1,7 @@
<?php <?php
// XDateTimeTest.php // XDateTimeTest.php
// Created: 2021-06-14 // Created: 2021-06-14
// Updated: 2024-07-31 // Updated: 2024-10-02
declare(strict_types=1); declare(strict_types=1);
@ -13,22 +13,22 @@ use Index\XDateTime;
final class XDateTimeTest extends TestCase { final class XDateTimeTest extends TestCase {
public function testToString(): void { public function testToString(): void {
$dateTime = new DateTime('2013-01-27T23:14:44', new DateTimeZone('Europe/Amsterdam')); $dateTime = new DateTime('2013-01-27T23:14:44', new DateTimeZone('Europe/Amsterdam'));
$this->assertEquals(XDateTime::toISO8601String($dateTime), '2013-01-27T23:14:44+01:00'); $this->assertEquals(XDateTime::toIso8601String($dateTime), '2013-01-27T23:14:44+01:00');
$this->assertEquals(XDateTime::toCookieString($dateTime), 'Sunday, 27-Jan-2013 23:14:44 CET'); $this->assertEquals(XDateTime::toCookieString($dateTime), 'Sunday, 27-Jan-2013 23:14:44 CET');
$this->assertEquals(XDateTime::toRFC822String($dateTime), 'Sun, 27 Jan 13 23:14:44 +0100'); $this->assertEquals(XDateTime::toRfc822String($dateTime), 'Sun, 27 Jan 13 23:14:44 +0100');
$dateTime = $dateTime->setTimezone(new DateTimeZone('UTC')); $dateTime = $dateTime->setTimezone(new DateTimeZone('UTC'));
$this->assertEquals(XDateTime::toISO8601String($dateTime), '2013-01-27T22:14:44+00:00'); $this->assertEquals(XDateTime::toIso8601String($dateTime), '2013-01-27T22:14:44+00:00');
$this->assertEquals(XDateTime::toCookieString($dateTime), 'Sunday, 27-Jan-2013 22:14:44 UTC'); $this->assertEquals(XDateTime::toCookieString($dateTime), 'Sunday, 27-Jan-2013 22:14:44 UTC');
$this->assertEquals(XDateTime::toRFC822String($dateTime), 'Sun, 27 Jan 13 22:14:44 +0000'); $this->assertEquals(XDateTime::toRfc822String($dateTime), 'Sun, 27 Jan 13 22:14:44 +0000');
$this->assertEquals(XDateTime::toISO8601String(1359324884), '2013-01-27T22:14:44+00:00'); $this->assertEquals(XDateTime::toIso8601String(1359324884), '2013-01-27T22:14:44+00:00');
$this->assertEquals(XDateTime::toCookieString(1359324884), 'Sunday, 27-Jan-2013 22:14:44 GMT'); $this->assertEquals(XDateTime::toCookieString(1359324884), 'Sunday, 27-Jan-2013 22:14:44 GMT');
$this->assertEquals(XDateTime::toRFC822String(1359324884), 'Sun, 27 Jan 13 22:14:44 +0000'); $this->assertEquals(XDateTime::toRfc822String(1359324884), 'Sun, 27 Jan 13 22:14:44 +0000');
$this->assertEquals(XDateTime::toISO8601String('January 27th 2013 22:14:44 UTC'), '2013-01-27T22:14:44+00:00'); $this->assertEquals(XDateTime::toIso8601String('January 27th 2013 22:14:44 UTC'), '2013-01-27T22:14:44+00:00');
$this->assertEquals(XDateTime::toCookieString('January 27th 2013 22:14:44 UTC'), 'Sunday, 27-Jan-2013 22:14:44 GMT'); $this->assertEquals(XDateTime::toCookieString('January 27th 2013 22:14:44 UTC'), 'Sunday, 27-Jan-2013 22:14:44 GMT');
$this->assertEquals(XDateTime::toRFC822String('January 27th 2013 22:14:44 UTC'), 'Sun, 27 Jan 13 22:14:44 +0000'); $this->assertEquals(XDateTime::toRfc822String('January 27th 2013 22:14:44 UTC'), 'Sun, 27 Jan 13 22:14:44 +0000');
} }
public function testCompare(): void { public function testCompare(): void {