Add root folder to include path and move utility functions around.
This commit is contained in:
parent
22851470f4
commit
20aaa0f926
6 changed files with 81 additions and 72 deletions
56
misuzu.php
56
misuzu.php
|
@ -9,8 +9,9 @@ ini_set('display_errors', MSZ_DEBUG ? 'On' : 'Off');
|
||||||
|
|
||||||
date_default_timezone_set('UTC');
|
date_default_timezone_set('UTC');
|
||||||
mb_internal_encoding('UTF-8');
|
mb_internal_encoding('UTF-8');
|
||||||
|
set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__);
|
||||||
|
|
||||||
require_once __DIR__ . '/vendor/autoload.php';
|
require_once 'vendor/autoload.php';
|
||||||
|
|
||||||
$errorHandler = new \Whoops\Run;
|
$errorHandler = new \Whoops\Run;
|
||||||
$errorHandler->pushHandler(
|
$errorHandler->pushHandler(
|
||||||
|
@ -24,31 +25,34 @@ $errorHandler->pushHandler(
|
||||||
);
|
);
|
||||||
$errorHandler->register();
|
$errorHandler->register();
|
||||||
|
|
||||||
require_once __DIR__ . '/src/audit_log.php';
|
require_once 'src/array.php';
|
||||||
require_once __DIR__ . '/src/changelog.php';
|
require_once 'src/audit_log.php';
|
||||||
require_once __DIR__ . '/src/colour.php';
|
require_once 'src/changelog.php';
|
||||||
require_once __DIR__ . '/src/comments.php';
|
require_once 'src/colour.php';
|
||||||
require_once __DIR__ . '/src/general.php';
|
require_once 'src/comments.php';
|
||||||
require_once __DIR__ . '/src/git.php';
|
require_once 'src/general.php';
|
||||||
require_once __DIR__ . '/src/ip.php';
|
require_once 'src/git.php';
|
||||||
require_once __DIR__ . '/src/manage.php';
|
require_once 'src/manage.php';
|
||||||
require_once __DIR__ . '/src/news.php';
|
require_once 'src/news.php';
|
||||||
require_once __DIR__ . '/src/perms.php';
|
require_once 'src/perms.php';
|
||||||
require_once __DIR__ . '/src/tpl.php';
|
require_once 'src/string.php';
|
||||||
require_once __DIR__ . '/src/zalgo.php';
|
require_once 'src/tpl.php';
|
||||||
require_once __DIR__ . '/src/Forum/forum.php';
|
require_once 'src/zalgo.php';
|
||||||
require_once __DIR__ . '/src/Forum/perms.php';
|
require_once 'src/Forum/forum.php';
|
||||||
require_once __DIR__ . '/src/Forum/post.php';
|
require_once 'src/Forum/perms.php';
|
||||||
require_once __DIR__ . '/src/Forum/topic.php';
|
require_once 'src/Forum/post.php';
|
||||||
require_once __DIR__ . '/src/Forum/validate.php';
|
require_once 'src/Forum/topic.php';
|
||||||
require_once __DIR__ . '/src/Parsers/parse.php';
|
require_once 'src/Forum/validate.php';
|
||||||
require_once __DIR__ . '/src/Users/login_attempt.php';
|
require_once 'src/Net/cidr.php';
|
||||||
require_once __DIR__ . '/src/Users/profile.php';
|
require_once 'src/Net/ip.php';
|
||||||
require_once __DIR__ . '/src/Users/relations.php';
|
require_once 'src/Parsers/parse.php';
|
||||||
require_once __DIR__ . '/src/Users/role.php';
|
require_once 'src/Users/login_attempt.php';
|
||||||
require_once __DIR__ . '/src/Users/session.php';
|
require_once 'src/Users/profile.php';
|
||||||
require_once __DIR__ . '/src/Users/user.php';
|
require_once 'src/Users/relations.php';
|
||||||
require_once __DIR__ . '/src/Users/validation.php';
|
require_once 'src/Users/role.php';
|
||||||
|
require_once 'src/Users/session.php';
|
||||||
|
require_once 'src/Users/user.php';
|
||||||
|
require_once 'src/Users/validation.php';
|
||||||
|
|
||||||
$app = new Application(__DIR__ . '/config/config.ini');
|
$app = new Application(__DIR__ . '/config/config.ini');
|
||||||
|
|
||||||
|
|
5
src/Net/cidr.php
Normal file
5
src/Net/cidr.php
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<?php
|
||||||
|
function cidr_range_to_mask(string $startAddress, string $endAddress, bool $isRaw = false): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
20
src/array.php
Normal file
20
src/array.php
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
<?php
|
||||||
|
function array_test(array $array, callable $func): bool
|
||||||
|
{
|
||||||
|
foreach ($array as $value) {
|
||||||
|
if (!$func($value)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function array_apply(array $array, callable $func): array
|
||||||
|
{
|
||||||
|
for ($i = 0; $i < count($array); $i++) {
|
||||||
|
$array[$i] = $func($array[$i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $array;
|
||||||
|
}
|
26
src/string.php
Normal file
26
src/string.php
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
<?php
|
||||||
|
function starts_with(string $string, string $text): bool
|
||||||
|
{
|
||||||
|
return mb_substr($string, 0, mb_strlen($text)) === $text;
|
||||||
|
}
|
||||||
|
|
||||||
|
function ends_with(string $string, string $text): bool
|
||||||
|
{
|
||||||
|
return mb_substr($string, 0 - mb_strlen($text)) === $text;
|
||||||
|
}
|
||||||
|
|
||||||
|
function first_paragraph(string $text, string $delimiter = "\n"): string
|
||||||
|
{
|
||||||
|
$index = mb_strpos($text, $delimiter);
|
||||||
|
return $index === false ? $text : mb_substr($text, 0, $index);
|
||||||
|
}
|
||||||
|
|
||||||
|
function camel_to_snake(string $camel): string
|
||||||
|
{
|
||||||
|
return trim(mb_strtolower(preg_replace('#([A-Z][a-z]+)#', '$1_', $camel)), '_');
|
||||||
|
}
|
||||||
|
|
||||||
|
function snake_to_camel(string $snake): string
|
||||||
|
{
|
||||||
|
return str_replace('_', '', ucwords($snake, '_'));
|
||||||
|
}
|
46
utility.php
46
utility.php
|
@ -1,34 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
function starts_with(string $string, string $text): bool
|
|
||||||
{
|
|
||||||
return mb_substr($string, 0, mb_strlen($text)) === $text;
|
|
||||||
}
|
|
||||||
|
|
||||||
function ends_with(string $string, string $text): bool
|
|
||||||
{
|
|
||||||
return mb_substr($string, 0 - mb_strlen($text)) === $text;
|
|
||||||
}
|
|
||||||
|
|
||||||
function array_test(array $array, callable $func): bool
|
|
||||||
{
|
|
||||||
foreach ($array as $value) {
|
|
||||||
if (!$func($value)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function array_apply(array $array, callable $func): array
|
|
||||||
{
|
|
||||||
for ($i = 0; $i < count($array); $i++) {
|
|
||||||
$array[$i] = $func($array[$i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $array;
|
|
||||||
}
|
|
||||||
|
|
||||||
function set_cookie_m(string $name, string $value, int $expires): void
|
function set_cookie_m(string $name, string $value, int $expires): void
|
||||||
{
|
{
|
||||||
setcookie(
|
setcookie(
|
||||||
|
@ -227,12 +197,6 @@ function running_on_windows(): bool
|
||||||
return starts_with(mb_strtolower(PHP_OS), 'win');
|
return starts_with(mb_strtolower(PHP_OS), 'win');
|
||||||
}
|
}
|
||||||
|
|
||||||
function first_paragraph(string $text, string $delimiter = "\n"): string
|
|
||||||
{
|
|
||||||
$index = mb_strpos($text, $delimiter);
|
|
||||||
return $index === false ? $text : mb_substr($text, 0, $index);
|
|
||||||
}
|
|
||||||
|
|
||||||
function pdo_prepare_array_update(array $keys, bool $useKeys = false, string $format = '%s'): string
|
function pdo_prepare_array_update(array $keys, bool $useKeys = false, string $format = '%s'): string
|
||||||
{
|
{
|
||||||
return pdo_prepare_array($keys, $useKeys, sprintf($format, '`%1$s` = :%1$s'));
|
return pdo_prepare_array($keys, $useKeys, sprintf($format, '`%1$s` = :%1$s'));
|
||||||
|
@ -379,16 +343,6 @@ function url_construct(string $path, array $query = [], string $host = ''): stri
|
||||||
return mb_substr($url, 0, -1);
|
return mb_substr($url, 0, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function camel_to_snake(string $camel): string
|
|
||||||
{
|
|
||||||
return trim(mb_strtolower(preg_replace('#([A-Z][a-z]+)#', '$1_', $camel)), '_');
|
|
||||||
}
|
|
||||||
|
|
||||||
function snake_to_camel(string $snake): string
|
|
||||||
{
|
|
||||||
return str_replace('_', '', ucwords($snake, '_'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function is_user_int($value): bool
|
function is_user_int($value): bool
|
||||||
{
|
{
|
||||||
return ctype_digit(strval($value));
|
return ctype_digit(strval($value));
|
||||||
|
|
Loading…
Add table
Reference in a new issue