Updated to PHP 8.3 and added cache provider requirements to the README.

This commit is contained in:
flash 2024-07-31 18:12:46 +00:00
parent e4c8ed711e
commit 3952dd96e8
21 changed files with 356 additions and 332 deletions

View file

@ -2,16 +2,29 @@
Index is a common library for my PHP projects. Index is a common library for my PHP projects.
It provides a number of components that I would otherwise copy between projects (and thus become out-of-sync) as well as a number of quality of life things on top of standard PHP stdlib functionality such as abstractions of arrays and strings as objects inspired by .NET's standard library. It provides a number of components that I would otherwise copy between projects (and thus become out-of-sync) as well as a number of quality of life things on top of standard PHP stdlib functionality.
## Requirements and Dependencies ## Requirements and Dependencies
Index currently targets **PHP 8.2** with the `mbstring` extension installed. Index currently targets **PHP 8.3** with the `mbstring` extension installed.
### `Index\Cache\Memcached`
Requires either the `memcached` or `memcache` extension, if both are installed the `memcached` based implementation will be used.
For full functionality you will want the `memcached` implementation.
The way each implementation stores data is NOT guaranteed to be compatible, please do not mix them.
### `Index\Cache\Valkey`
Requires the `redis` extension.
Valkey is the name of the Linux Foundation's fork of Redis.
### `Index\Data\MariaDB` ### `Index\Data\MariaDB`
Requires the `mysqli` extension. `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. Requires the `mysqli` extension.
`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.
### `Index\Data\SQLite` ### `Index\Data\SQLite`

View file

@ -1 +1 @@
0.2404.102340 0.2407.311805

View file

@ -5,12 +5,12 @@
"homepage": "https://railgun.sh/index", "homepage": "https://railgun.sh/index",
"license": "bsd-3-clause-clear", "license": "bsd-3-clause-clear",
"require": { "require": {
"php": ">=8.1", "php": ">=8.3",
"ext-mbstring": "*" "ext-mbstring": "*"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^10.2", "phpunit/phpunit": "^11.2",
"phpstan/phpstan": "^1.10" "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).",

503
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,16 +1,15 @@
<?php <?php
// Base32Test.php // Base32Test.php
// Created: 2021-04-28 // Created: 2021-04-28
// Updated: 2023-07-21 // Updated: 2024-07-31
declare(strict_types=1); declare(strict_types=1);
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use Index\Serialisation\Base32; use Index\Serialisation\Base32;
/** #[CoversClass(Base32::class)]
* @covers Base32
*/
final class Base32Test extends TestCase { final class Base32Test extends TestCase {
public const TESTS = [ public const TESTS = [
'A' => '', 'A' => '',

View file

@ -1,16 +1,15 @@
<?php <?php
// Base62Test.php // Base62Test.php
// Created: 2022-01-28 // Created: 2022-01-28
// Updated: 2023-07-21 // Updated: 2024-07-31
declare(strict_types=1); declare(strict_types=1);
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use Index\Serialisation\Base62; use Index\Serialisation\Base62;
/** #[CoversClass(Base62::class)]
* @covers Base62
*/
final class Base62Test extends TestCase { final class Base62Test extends TestCase {
public const TESTS = [ public const TESTS = [
['aaaaaa', 9311514030], ['aaaaaa', 9311514030],

View file

@ -1,16 +1,15 @@
<?php <?php
// BencodeTest.php // BencodeTest.php
// Created: 2023-07-21 // Created: 2023-07-21
// Updated: 2023-07-21 // Updated: 2024-07-31
declare(strict_types=1); declare(strict_types=1);
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use Index\Serialisation\Bencode; use Index\Serialisation\Bencode;
/** #[CoversClass(Bencode::class)]
* @covers Bencode
*/
final class BencodeTest extends TestCase { final class BencodeTest extends TestCase {
public const TORRENT = 'ZDg6YW5ub3VuY2U0NTpodHRwczovL3RyYWNrZXIuZmxhc2hpaS5uZXQvYW5ub3VuY2UucGhwL21lb3c3OmNvbW1lbnQyNjp0aGlzIGlzIHRoZSBjb21tZW50cyBmaWVsZDEwOmNyZWF0ZWQgYnkxODpxQml0dG9ycmVudCB2NC41LjQxMzpjcmVhdGlvbiBkYXRlaTE2ODk5NzM2NjRlNDppbmZvZDY6bGVuZ3RoaTM5NDg4ZTQ6bmFtZTEwOmF1dGlzbS5qcGcxMjpwaWVjZSBsZW5ndGhpMTYzODRlNjpwaWVjZXM2MDpJCQyONUjTseqtXs9g1xIC+yWtTGjuWTho+hSXmOUkSAiKnD4vs5E9QewQ1NrXvVeg2xCRHYD/HL9RNRc3OnByaXZhdGVpMWVlZQ'; public const TORRENT = 'ZDg6YW5ub3VuY2U0NTpodHRwczovL3RyYWNrZXIuZmxhc2hpaS5uZXQvYW5ub3VuY2UucGhwL21lb3c3OmNvbW1lbnQyNjp0aGlzIGlzIHRoZSBjb21tZW50cyBmaWVsZDEwOmNyZWF0ZWQgYnkxODpxQml0dG9ycmVudCB2NC41LjQxMzpjcmVhdGlvbiBkYXRlaTE2ODk5NzM2NjRlNDppbmZvZDY6bGVuZ3RoaTM5NDg4ZTQ6bmFtZTEwOmF1dGlzbS5qcGcxMjpwaWVjZSBsZW5ndGhpMTYzODRlNjpwaWVjZXM2MDpJCQyONUjTseqtXs9g1xIC+yWtTGjuWTho+hSXmOUkSAiKnD4vs5E9QewQ1NrXvVeg2xCRHYD/HL9RNRc3OnByaXZhdGVpMWVlZQ';

View file

@ -1,16 +1,15 @@
<?php <?php
// ByteFormatTest.php // ByteFormatTest.php
// Created: 2023-07-05 // Created: 2023-07-05
// Updated: 2023-07-05 // Updated: 2024-07-31
declare(strict_types=1); declare(strict_types=1);
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use Index\ByteFormat; use Index\ByteFormat;
/** #[CoversClass(ByteFormat::class)]
* @covers ByteFormat
*/
final class ByteFormatTest extends TestCase { final class ByteFormatTest extends TestCase {
public function testFormat(): void { public function testFormat(): void {
$this->assertEquals(ByteFormat::formatDecimal(0), 'Zero Bytes'); $this->assertEquals(ByteFormat::formatDecimal(0), 'Zero Bytes');

View file

@ -1,16 +1,15 @@
<?php <?php
// CSRFPTest.php // CSRFPTest.php
// Created: 2021-06-11 // Created: 2021-06-11
// Updated: 2023-07-11 // Updated: 2024-07-31
declare(strict_types=1); declare(strict_types=1);
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use Index\Security\CSRFP; use Index\Security\CSRFP;
/** #[CoversClass(CSRFP::class)]
* @covers CSRFP
*/
final class CSRFPTest extends TestCase { final class CSRFPTest extends TestCase {
private const SECRET_1 = 'oCtBmR7XS1dLOnGVoVi0wXwTLk7Ursn4'; private const SECRET_1 = 'oCtBmR7XS1dLOnGVoVi0wXwTLk7Ursn4';
private const SECRET_2 = 'v6H37MPa8NHmxVvL4AzNSxrWLVkiTfPHouyTto1LXOfOyoqSU7EaSorjdM4gXlq3'; private const SECRET_2 = 'v6H37MPa8NHmxVvL4AzNSxrWLVkiTfPHouyTto1LXOfOyoqSU7EaSorjdM4gXlq3';

View file

@ -1,20 +1,27 @@
<?php <?php
// CacheToolsTest.php // CacheToolsTest.php
// Created: 2024-04-10 // Created: 2024-04-10
// Updated: 2024-04-10 // Updated: 2024-07-31
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\UsesClass;
use Index\Cache\CacheTools; use Index\Cache\CacheTools;
use Index\Cache\ArrayCache\{ArrayCacheBackend,ArrayCacheProvider}; use Index\Cache\ArrayCache\{ArrayCacheBackend,ArrayCacheProvider};
use Index\Cache\Memcached\MemcachedBackend; use Index\Cache\Memcached\MemcachedBackend;
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)]
* @covers CacheTools #[CoversClass(ArrayCacheBackend::class)]
*/ #[CoversClass(ArrayCacheProvider::class)]
#[CoversClass(MemcachedBackend::class)]
#[CoversClass(ValkeyBackend::class)]
#[UsesClass(DnsEndPoint::class)]
#[UsesClass(IPEndPoint::class)]
#[UsesClass(UnixEndPoint::class)]
final class CacheToolsTest extends TestCase { final class CacheToolsTest extends TestCase {
public function testBasicDSN(): void { public function testBasicDSN(): void {
$arrayCache = CacheTools::create('array:'); $arrayCache = CacheTools::create('array:');

View file

@ -1,24 +1,23 @@
<?php <?php
// ColourTest.php // ColourTest.php
// Created: 2023-01-02 // Created: 2023-01-02
// Updated: 2023-09-15 // Updated: 2024-07-31
declare(strict_types=1); declare(strict_types=1);
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use Index\Colour\Colour; use Index\Colour\Colour;
use Index\Colour\ColourHSL; use Index\Colour\ColourHSL;
use Index\Colour\ColourNamed; use Index\Colour\ColourNamed;
use Index\Colour\ColourNull; use Index\Colour\ColourNull;
use Index\Colour\ColourRGB; use Index\Colour\ColourRGB;
/** #[CoversClass(Colour::class)]
* @covers Colour #[CoversClass(ColourHSL::class)]
* @covers ColourHSL #[CoversClass(ColourNamed::class)]
* @covers ColourNamed #[CoversClass(ColourNull::class)]
* @covers ColourNull #[CoversClass(ColourRGB::class)]
* @covers ColourRGB
*/
final class ColourTest extends TestCase { final class ColourTest extends TestCase {
public function testNone(): void { public function testNone(): void {
$none = Colour::none(); $none = Colour::none();

View file

@ -1,20 +1,19 @@
<?php <?php
// DateTimeTest.php // DateTimeTest.php
// Created: 2021-06-14 // Created: 2021-06-14
// Updated: 2022-02-27 // Updated: 2024-07-31
declare(strict_types=1); declare(strict_types=1);
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use Index\DateTime; use Index\DateTime;
use Index\TimeSpan; use Index\TimeSpan;
use Index\TimeZoneInfo; use Index\TimeZoneInfo;
/** #[CoversClass(DateTime::class)]
* @covers DateTime #[CoversClass(TimeSpan::class)]
* @covers TimeSpan #[CoversClass(TimeZoneInfo::class)]
* @covers TimeZoneInfo
*/
final class DateTimeTest extends TestCase { final class DateTimeTest extends TestCase {
public function testAttributes(): void { public function testAttributes(): void {
$index = new DateTime('2021-06-14T21:07:14.359324 CEST'); $index = new DateTime('2021-06-14T21:07:14.359324 CEST');

View file

@ -1,22 +1,26 @@
<?php <?php
// DbToolsTest.php // DbToolsTest.php
// Created: 2021-04-28 // Created: 2021-04-28
// Updated: 2024-04-10 // Updated: 2024-07-31
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\UsesClass;
use Index\Data\DbTools; use Index\Data\DbTools;
use Index\Data\DbType; use Index\Data\DbType;
use Index\Data\MariaDB\MariaDBBackend; use Index\Data\MariaDB\MariaDBBackend;
use Index\Data\NullDb\NullDbConnection; use Index\Data\NullDb\NullDbConnection;
use Index\Data\SQLite\SQLiteBackend; use Index\Data\SQLite\SQLiteBackend;
use Index\IO\MemoryStream; use Index\IO\MemoryStream;
use Index\Net\UnixEndPoint;
/** #[CoversClass(DbTools::class)]
* @covers DbTools #[CoversClass(DbType::class)]
*/ #[CoversClass(NullDbConnection::class)]
#[CoversClass(MariaDBBackend::class)]
#[CoversClass(SQLiteBackend::class)]
#[UsesClass(MemoryStream::class)]
final class DbToolsTest extends TestCase { final class DbToolsTest extends TestCase {
public function testDetectType(): void { public function testDetectType(): void {
$this->assertEquals(DbType::NULL, DbTools::detectType(null)); $this->assertEquals(DbType::NULL, DbTools::detectType(null));

View file

@ -1,17 +1,18 @@
<?php <?php
// EnvironmentTest.php // EnvironmentTest.php
// Created: 2021-05-02 // Created: 2021-05-02
// Updated: 2023-11-09 // Updated: 2024-07-31
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\UsesClass;
use Index\Environment; use Index\Environment;
use Index\Version; use Index\Version;
/** #[CoversClass(Environment::class)]
* @covers Environment #[UsesClass(Version::class)]
*/
final class EnvironmentTest extends TestCase { final class EnvironmentTest extends TestCase {
public function testEnvVars(): void { public function testEnvVars(): void {
$varName = 'NDX_TEST_VAR_DO_NOT_DEFINE'; $varName = 'NDX_TEST_VAR_DO_NOT_DEFINE';

View file

@ -1,17 +1,18 @@
<?php <?php
// IPAddressRangeTest.php // IPAddressRangeTest.php
// Created: 2021-04-27 // Created: 2021-04-27
// Updated: 2022-02-03 // Updated: 2024-07-31
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\UsesClass;
use Index\Net\IPAddress; use Index\Net\IPAddress;
use Index\Net\IPAddressRange; use Index\Net\IPAddressRange;
/** #[CoversClass(IPAddressRange::class)]
* @covers IPAddressRange #[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');

View file

@ -1,16 +1,15 @@
<?php <?php
// IPAddressTest.php // IPAddressTest.php
// Created: 2021-04-26 // Created: 2021-04-26
// Updated: 2022-02-03 // Updated: 2024-07-31
declare(strict_types=1); declare(strict_types=1);
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use Index\Net\IPAddress; use Index\Net\IPAddress;
/** #[CoversClass(IPAddress::class)]
* @covers IPAddress
*/
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');

View file

@ -1,21 +1,24 @@
<?php <?php
// RouterTest.php // RouterTest.php
// Created: 2022-01-20 // Created: 2022-01-20
// Updated: 2024-04-02 // Updated: 2024-07-31
declare(strict_types=1); declare(strict_types=1);
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Index\Routing\Route; use PHPUnit\Framework\Attributes\CoversClass;
use Index\Routing\Router;
use Index\Http\Routing\{HttpGet,HttpMiddleware,HttpPost,HttpPut,HttpRouter,RouteHandler}; use Index\Http\Routing\{HttpGet,HttpMiddleware,HttpPost,HttpPut,HttpRouter,RouteHandler};
/** /**
* This test isn't super representative of the current functionality * This test isn't super representative of the current functionality
* it mostly just does the same tests that were done against the previous implementation * it mostly just does the same tests that were done against the previous implementation
*
* @covers HttpRouter
*/ */
#[CoversClass(HttpGet::class)]
#[CoversClass(HttpMiddleware::class)]
#[CoversClass(HttpPost::class)]
#[CoversClass(HttpPut::class)]
#[CoversClass(HttpRouter::class)]
#[CoversClass(RouteHandler::class)]
final class RouterTest extends TestCase { final class RouterTest extends TestCase {
public function testRouter(): void { public function testRouter(): void {
$router1 = new HttpRouter; $router1 = new HttpRouter;

View file

@ -1,17 +1,18 @@
<?php <?php
// VersionTest.php // VersionTest.php
// Created: 2021-04-30 // Created: 2021-04-30
// Updated: 2022-02-03 // Updated: 2024-07-31
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\UsesClass;
use Index\Version; use Index\Version;
use Index\XArray; use Index\XArray;
/** #[CoversClass(Version::class)]
* @covers Version #[UsesClass(XArray::class)]
*/
final class VersionTest extends TestCase { final class VersionTest extends TestCase {
public function testParse(): void { public function testParse(): void {
$tests = [ $tests = [

View file

@ -1,16 +1,15 @@
<?php <?php
// WStringTest.php // WStringTest.php
// Created: 2021-04-26 // Created: 2021-04-26
// Updated: 2024-01-04 // Updated: 2024-07-31
declare(strict_types=1); declare(strict_types=1);
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use Index\WString; use Index\WString;
/** #[CoversClass(WString::class)]
* @covers WString
*/
final class WStringTest extends TestCase { final class WStringTest extends TestCase {
public function testStartsWith(): void { public function testStartsWith(): void {
$this->assertTrue(WString::startsWith('君は実にバカだな', '君は')); $this->assertTrue(WString::startsWith('君は実にバカだな', '君は'));

View file

@ -1,16 +1,15 @@
<?php <?php
// XArrayTest.php // XArrayTest.php
// Created: 2021-04-26 // Created: 2021-04-26
// Updated: 2024-01-04 // Updated: 2024-07-31
declare(strict_types=1); declare(strict_types=1);
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use Index\XArray; use Index\XArray;
/** #[CoversClass(XArray::class)]
* @covers XArray
*/
final class XArrayTest extends TestCase { final class XArrayTest extends TestCase {
public function testCountEmpty(): void { public function testCountEmpty(): void {
$array = []; $array = [];

View file

@ -1,16 +1,15 @@
<?php <?php
// XStringTest.php // XStringTest.php
// Created: 2021-04-26 // Created: 2021-04-26
// Updated: 2024-01-04 // Updated: 2024-07-31
declare(strict_types=1); declare(strict_types=1);
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use Index\XString; use Index\XString;
/** #[CoversClass(XString::class)]
* @covers XString
*/
final class XStringTest extends TestCase { final class XStringTest extends TestCase {
public function testEscape(): void { public function testEscape(): void {
$dirty = '<img onerror="alert(\'xss\')">'; $dirty = '<img onerror="alert(\'xss\')">';