Updated to PHP 8.3 and latest Index.

This commit is contained in:
flash 2024-08-04 01:07:23 +00:00
parent 954a07b951
commit 129a46c0d9
12 changed files with 354 additions and 338 deletions

View file

@ -1 +1 @@
1.1.0-dev 1.2.0

View file

@ -4,15 +4,13 @@
"type": "library", "type": "library",
"homepage": "https://railgun.sh/syokuhou", "homepage": "https://railgun.sh/syokuhou",
"license": "bsd-3-clause-clear", "license": "bsd-3-clause-clear",
"minimum-stability": "dev",
"prefer-stable": true,
"require": { "require": {
"php": ">=8.2", "php": ">=8.3",
"flashwave/index": "dev-master" "flashwave/index": "^0.2408.40014"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^10.4", "phpunit/phpunit": "^11.2",
"phpstan/phpstan": "^1.10" "phpstan/phpstan": "^1.11"
}, },
"authors": [ "authors": [
{ {

523
composer.lock generated

File diff suppressed because it is too large Load diff

34
src/Syokuhou.php Normal file
View file

@ -0,0 +1,34 @@
<?php
// SyokuhouInfo.php
// Created: 2023-10-20
// Updated: 2023-10-20
namespace Syokuhou;
/**
* Provides information about the Syokuhou library.
*/
final class Syokuhou {
public const PATH_SOURCE = __DIR__;
public const PATH_ROOT = self::PATH_SOURCE . DIRECTORY_SEPARATOR . '..';
public const PATH_VERSION = self::PATH_ROOT . DIRECTORY_SEPARATOR . 'VERSION';
/**
* Gets the current version of the Syokuhou library.
*
* Reads the VERSION file in the root of the Syokuhou directory.
* Returns 0.0.0 if reading the file failed for any reason.
*
* @return string Current version string.
*/
public static function version(): string {
if(!is_file(self::PATH_VERSION))
return '0.0.0';
$version = file_get_contents(self::PATH_VERSION);
if($version === false)
return '0.0.0';
return trim($version);
}
}

View file

@ -1,45 +0,0 @@
<?php
// SyokuhouInfo.php
// Created: 2023-10-20
// Updated: 2023-10-20
namespace Syokuhou;
use UnexpectedValueException;
use Index\Version;
/**
* Retrieves library info.
*/
final class SyokuhouInfo {
private static ?string $versionString = null;
private static ?Version $version = null;
/**
* Returns the current version of the library.
*
* @return Version
*/
public static function getVersion(): Version {
if(self::$version === null)
self::$version = Version::parse(self::getVersionString());
return self::$version;
}
/**
* Returns the current version of the library as a string.
*
* @return string
*/
public static function getVersionString(): string {
if(self::$versionString === null) {
$body = file_get_contents(__DIR__ . '/../VERSION');
if($body === false)
throw new UnexpectedValueException('Was unable to read VERSION file.');
self::$versionString = trim($body);
}
return self::$versionString;
}
}

View file

@ -6,14 +6,13 @@
declare(strict_types=1); declare(strict_types=1);
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;
/** #[CoversClass(Syokuhou\DbConfigTest::class)]
* @covers \Syokuhou\DbConfigTest #[CoversClass(Syokuhou\DbConfigValueInfo::class)]
* @covers \Syokuhou\DbConfigValueInfo #[CoversClass(Syokuhou\MutableConfigTrait::class)]
* @covers \Syokuhou\MutableConfigTrait #[CoversClass(Syokuhou\GetValueInfoTrait::class)]
* @covers \Syokuhou\GetValueInfoTrait #[CoversClass(Syokuhou\GetValuesTrait::class)]
* @covers \Syokuhou\GetValuesTrait
*/
final class DbConfigTest extends TestCase { final class DbConfigTest extends TestCase {
private \Index\Data\IDbConnection $dbConn; private \Index\Data\IDbConnection $dbConn;
private \Syokuhou\DbConfig $config; private \Syokuhou\DbConfig $config;

View file

@ -6,15 +6,14 @@
declare(strict_types=1); declare(strict_types=1);
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;
/** #[CoversClass(Syokuhou\FileConfig::class)]
* @covers \Syokuhou\FileConfig #[CoversClass(Syokuhou\FileConfigValueInfo::class)]
* @covers \Syokuhou\FileConfigValueInfo #[CoversClass(Syokuhou\ImmutableConfigTrait::class)]
* @covers \Syokuhou\ImmutableConfigTrait #[CoversClass(Syokuhou\GetValueInfoTrait::class)]
* @covers \Syokuhou\GetValueInfoTrait #[CoversClass(Syokuhou\GetValuesTrait::class)]
* @covers \Syokuhou\GetValuesTrait #[CoversClass(Syokuhou\SharpConfig::class)]
* @covers \Syokuhou\SharpConfig
*/
final class FileConfigTest extends TestCase { final class FileConfigTest extends TestCase {
public function testImmutableRemove(): void { public function testImmutableRemove(): void {
$this->expectException(\RuntimeException::class); $this->expectException(\RuntimeException::class);

View file

@ -6,11 +6,10 @@
declare(strict_types=1); declare(strict_types=1);
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;
/** #[CoversClass(Syokuhou\NullConfig::class)]
* @covers \Syokuhou\NullConfig #[CoversClass(Syokuhou\GetValuesTrait::class)]
* @covers \Syokuhou\GetValuesTrait
*/
final class NullConfigTest extends TestCase { final class NullConfigTest extends TestCase {
public function testNullConfig(): void { public function testNullConfig(): void {
$config = new \Syokuhou\NullConfig; $config = new \Syokuhou\NullConfig;

View file

@ -6,14 +6,12 @@
declare(strict_types=1); declare(strict_types=1);
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;
/** #[CoversClass(Syokuhou\Syokuhou::class)]
* @covers \Syokuhou\SyokuhouInfo
*/
final class SyokuhouTest extends TestCase { final class SyokuhouTest extends TestCase {
public function testVersionDecode(): void { public function testVersionDecode(): void {
$expected = trim(file_get_contents(__DIR__ . '/../VERSION')); $expected = trim(file_get_contents(__DIR__ . '/../VERSION'));
$this->assertEquals($expected, \Syokuhou\SyokuhouInfo::getVersionString()); $this->assertEquals($expected, \Syokuhou\Syokuhou::version());
$this->assertEquals($expected, (string)\Syokuhou\SyokuhouInfo::getVersion());
} }
} }

30
tools/create-tag Executable file
View file

@ -0,0 +1,30 @@
#!/usr/bin/env php
<?php
$path = (function($path) {
if(!str_starts_with($path, '/'))
die('Cannot be bothered to support non-UNIX style paths, sorry!' . PHP_EOL);
while($path !== '/') {
$vPath = $path . DIRECTORY_SEPARATOR . 'VERSION';
if(is_file($vPath))
return $vPath;
$path = dirname($path);
}
})(__DIR__);
$version = file_get_contents($path);
if($version === false)
die('Failed to read VERSION file.' . PHP_EOL);
$version = trim($version);
$workingDir = getcwd();
try {
chdir(dirname($path));
echo shell_exec(sprintf('git tag v%s', $version));
echo shell_exec(sprintf('git push origin v%s', $version));
} finally {
chdir($workingDir);
}
echo $version . PHP_EOL;

View file

@ -1,8 +1,8 @@
#!/bin/bash #!/usr/bin/env bash
pushd . pushd .
cd $(dirname "$0") cd $(dirname "$0")
php update-headers.php ./update-headers
popd popd

1
tools/update-headers.php → tools/update-headers Normal file → Executable file
View file

@ -1,3 +1,4 @@
#!/usr/bin/env php
<?php <?php
// the point of index was so that i wouldn't have to copy things between projects // the point of index was so that i wouldn't have to copy things between projects
// here i am copying things from index // here i am copying things from index