Allow including Index through Composer.

index.php automatically detects if the Composer autoloader exists and doesn't initialise its own autoloader.
Also including phpunit and phpstan through it instead of including the phars, probably makes more sense to do it the other way but they're Big.
This commit is contained in:
flash 2023-07-21 18:04:29 +00:00
parent ccf75ede4a
commit 5150f0cb56
11 changed files with 1786 additions and 101058 deletions

1
.gitignore vendored
View File

@ -7,3 +7,4 @@
docs/html/
.phpdoc*
.phpunit*
vendor/

41
LICENCE
View File

@ -1,25 +1,30 @@
BSD 2-Clause License
Copyright (c) 2021-2023, flashwave <me@flash.moe>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
modification, are permitted (subject to the limitations in the disclaimer
below) provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

View File

@ -1 +1 @@
0.2307.171901
0.2307.211801

35
composer.json Normal file
View File

@ -0,0 +1,35 @@
{
"name": "flashwave/index",
"description": "Composer package for the common library for my projects.",
"type": "library",
"homepage": "https://railgun.sh/index",
"licence": "bsd-3-clause-clear",
"require": {
"php": ">=8.1",
"ext-mbstring": "*"
},
"require-dev": {
"phpunit/phpunit": "^10.2",
"phpstan/phpstan": "^1.10"
},
"suggest": {
"ext-mysqli": "Support for the Index\\Data\\MariaDB namespace (both mysqlnd and libmysql are supported).",
"ext-sqlite3": "Support for the Index\\Data\\SQLite namespace."
},
"authors": [
{
"name": "flashwave",
"email": "packagist@flash.moe",
"homepage": "https://flash.moe",
"role": "mom"
}
],
"autoload": {
"psr-4": {
"Index\\": "src"
},
"files": [
"index.php"
]
}
}

1692
composer.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,17 +1,20 @@
<?php
// index.php
// Created: 2021-04-26
// Updated: 2021-05-04
// Updated: 2023-07-21
namespace Index;
define('NDX_ROOT', __DIR__);
define('NDX_DIR_SRC', NDX_ROOT . DIRECTORY_SEPARATOR . 'src');
require_once NDX_DIR_SRC . DIRECTORY_SEPARATOR . 'Autoloader.php';
// Only initialise the autoloader if Composer's autoloader doesn't exist yet
if(!class_exists(\Composer\Autoload\ClassLoader::class)) {
require_once NDX_DIR_SRC . DIRECTORY_SEPARATOR . 'Autoloader.php';
Autoloader::addNamespace(__NAMESPACE__, NDX_DIR_SRC);
Autoloader::register();
Autoloader::addNamespace(__NAMESPACE__, NDX_DIR_SRC);
Autoloader::register();
}
// currently phpstan sucks and relies on error suppression, luckily it leaves a constant!
if(!defined('__PHPSTAN_RUNNING__')) {

View File

@ -1,27 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
bootstrap="index.php"
colors="true"
cacheResultFile=".phpunit.cache/test-results"
executionOrder="depends,defects"
forceCoversAnnotation="true"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
failOnRisky="true"
failOnWarning="true"
verbose="true">
<testsuites>
<testsuite name="default">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>
<coverage cacheDirectory=".phpunit.cache/code-coverage"
processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd"
bootstrap="index.php"
colors="true"
executionOrder="depends,defects"
beStrictAboutOutputDuringTests="true"
failOnRisky="true"
failOnWarning="true"
cacheDirectory=".phpunit.cache"
requireCoverageMetadata="true"
beStrictAboutCoverageMetadata="true">
<testsuites>
<testsuite name="default">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>
<coverage/>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>

View File

@ -1,7 +1,7 @@
<?php
// MediaType.php
// Created: 2022-02-10
// Updated: 2023-02-01
// Updated: 2023-07-21
namespace Index;
@ -133,10 +133,10 @@ class MediaType implements Stringable, IComparable, IEquatable {
}
public static function parse(string $mediaTypeStr): MediaType {
$parts = explode(';', $mediaTypeStr);
if(empty($parts))
if(empty($mediaTypeStr))
throw new InvalidArgumentException('Invalid media type supplied.');
$parts = explode(';', $mediaTypeStr);
$mediaTypeStr = array_shift($parts);
$mediaTypeParts = explode('/', $mediaTypeStr, 2);

View File

@ -1,7 +1,7 @@
<?php
// CSRFP.php
// Created: 2021-06-11
// Updated: 2023-07-11
// Updated: 2023-07-21
namespace Index\Security;
@ -83,8 +83,8 @@ class CSRFP {
if(empty($token))
return false;
$uTime = -1;
extract(unpack('VuTime', $token));
$unpacked = unpack('Vts', $token);
$uTime = (int)$unpacked['ts'];
if($uTime < 0)
return false;

View File

@ -1,3 +0,0 @@
@echo off
phpstan --memory-limit=2G

101002
tools/phpunit

File diff suppressed because one or more lines are too long