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:
parent
ccf75ede4a
commit
5150f0cb56
11 changed files with 1786 additions and 101058 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -7,3 +7,4 @@
|
||||||
docs/html/
|
docs/html/
|
||||||
.phpdoc*
|
.phpdoc*
|
||||||
.phpunit*
|
.phpunit*
|
||||||
|
vendor/
|
||||||
|
|
41
LICENCE
41
LICENCE
|
@ -1,25 +1,30 @@
|
||||||
BSD 2-Clause License
|
|
||||||
|
|
||||||
Copyright (c) 2021-2023, flashwave <me@flash.moe>
|
Copyright (c) 2021-2023, flashwave <me@flash.moe>
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
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
|
* Redistributions of source code must retain the above copyright notice,
|
||||||
list of conditions and the following disclaimer.
|
this list of conditions and the following disclaimer.
|
||||||
|
|
||||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
this list of conditions and the following disclaimer in the documentation
|
notice, this list of conditions and the following disclaimer in the
|
||||||
and/or other materials provided with the distribution.
|
documentation and/or other materials provided with the distribution.
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* Neither the name of the copyright holder nor the names of its
|
||||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
contributors may be used to endorse or promote products derived from this
|
||||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
software without specific prior written permission.
|
||||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
||||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
|
||||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
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.
|
||||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
||||||
0.2307.171901
|
0.2307.211801
|
||||||
|
|
35
composer.json
Normal file
35
composer.json
Normal 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
1692
composer.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
11
index.php
11
index.php
|
@ -1,17 +1,20 @@
|
||||||
<?php
|
<?php
|
||||||
// index.php
|
// index.php
|
||||||
// Created: 2021-04-26
|
// Created: 2021-04-26
|
||||||
// Updated: 2021-05-04
|
// Updated: 2023-07-21
|
||||||
|
|
||||||
namespace Index;
|
namespace Index;
|
||||||
|
|
||||||
define('NDX_ROOT', __DIR__);
|
define('NDX_ROOT', __DIR__);
|
||||||
define('NDX_DIR_SRC', NDX_ROOT . DIRECTORY_SEPARATOR . 'src');
|
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::addNamespace(__NAMESPACE__, NDX_DIR_SRC);
|
||||||
Autoloader::register();
|
Autoloader::register();
|
||||||
|
}
|
||||||
|
|
||||||
// currently phpstan sucks and relies on error suppression, luckily it leaves a constant!
|
// currently phpstan sucks and relies on error suppression, luckily it leaves a constant!
|
||||||
if(!defined('__PHPSTAN_RUNNING__')) {
|
if(!defined('__PHPSTAN_RUNNING__')) {
|
||||||
|
|
17
phpunit.xml
17
phpunit.xml
|
@ -1,27 +1,24 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
|
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd"
|
||||||
bootstrap="index.php"
|
bootstrap="index.php"
|
||||||
colors="true"
|
colors="true"
|
||||||
cacheResultFile=".phpunit.cache/test-results"
|
|
||||||
executionOrder="depends,defects"
|
executionOrder="depends,defects"
|
||||||
forceCoversAnnotation="true"
|
|
||||||
beStrictAboutCoversAnnotation="true"
|
|
||||||
beStrictAboutOutputDuringTests="true"
|
beStrictAboutOutputDuringTests="true"
|
||||||
beStrictAboutTodoAnnotatedTests="true"
|
|
||||||
failOnRisky="true"
|
failOnRisky="true"
|
||||||
failOnWarning="true"
|
failOnWarning="true"
|
||||||
verbose="true">
|
cacheDirectory=".phpunit.cache"
|
||||||
|
requireCoverageMetadata="true"
|
||||||
|
beStrictAboutCoverageMetadata="true">
|
||||||
<testsuites>
|
<testsuites>
|
||||||
<testsuite name="default">
|
<testsuite name="default">
|
||||||
<directory suffix="Test.php">tests</directory>
|
<directory suffix="Test.php">tests</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
|
<coverage/>
|
||||||
<coverage cacheDirectory=".phpunit.cache/code-coverage"
|
<source>
|
||||||
processUncoveredFiles="true">
|
|
||||||
<include>
|
<include>
|
||||||
<directory suffix=".php">src</directory>
|
<directory suffix=".php">src</directory>
|
||||||
</include>
|
</include>
|
||||||
</coverage>
|
</source>
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
// MediaType.php
|
// MediaType.php
|
||||||
// Created: 2022-02-10
|
// Created: 2022-02-10
|
||||||
// Updated: 2023-02-01
|
// Updated: 2023-07-21
|
||||||
|
|
||||||
namespace Index;
|
namespace Index;
|
||||||
|
|
||||||
|
@ -133,10 +133,10 @@ class MediaType implements Stringable, IComparable, IEquatable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function parse(string $mediaTypeStr): MediaType {
|
public static function parse(string $mediaTypeStr): MediaType {
|
||||||
$parts = explode(';', $mediaTypeStr);
|
if(empty($mediaTypeStr))
|
||||||
if(empty($parts))
|
|
||||||
throw new InvalidArgumentException('Invalid media type supplied.');
|
throw new InvalidArgumentException('Invalid media type supplied.');
|
||||||
|
|
||||||
|
$parts = explode(';', $mediaTypeStr);
|
||||||
$mediaTypeStr = array_shift($parts);
|
$mediaTypeStr = array_shift($parts);
|
||||||
$mediaTypeParts = explode('/', $mediaTypeStr, 2);
|
$mediaTypeParts = explode('/', $mediaTypeStr, 2);
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
// CSRFP.php
|
// CSRFP.php
|
||||||
// Created: 2021-06-11
|
// Created: 2021-06-11
|
||||||
// Updated: 2023-07-11
|
// Updated: 2023-07-21
|
||||||
|
|
||||||
namespace Index\Security;
|
namespace Index\Security;
|
||||||
|
|
||||||
|
@ -83,8 +83,8 @@ class CSRFP {
|
||||||
if(empty($token))
|
if(empty($token))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
$uTime = -1;
|
$unpacked = unpack('Vts', $token);
|
||||||
extract(unpack('VuTime', $token));
|
$uTime = (int)$unpacked['ts'];
|
||||||
if($uTime < 0)
|
if($uTime < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
@echo off
|
|
||||||
|
|
||||||
phpstan --memory-limit=2G
|
|
101002
tools/phpunit
101002
tools/phpunit
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue