Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
db02bdd102 | ||
|
|
d9b71a64b3 | ||
|
|
f410d761ba | ||
|
|
fb4b9f3f81 | ||
|
|
1e94cd7b57 | ||
|
|
cba6a3f969 | ||
|
|
bea8629d10 | ||
|
|
b2751872a3 | ||
|
|
0a80abe8a4 | ||
|
|
1d220f25eb | ||
|
|
1716b2c627 | ||
|
|
a0126f70ab | ||
|
|
9a7399e821 | ||
|
|
6f653c24a0 | ||
|
|
b56f889c5e | ||
|
|
0680c2fd4a |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
||||
vendor
|
||||
composer.lock
|
||||
|
||||
120
.phan/config.php
Normal file
120
.phan/config.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This configuration will be read and overlaid on top of the
|
||||
* default configuration. Command line arguments will be applied
|
||||
* after this file is read.
|
||||
*
|
||||
* @see src/Phan/Config.php
|
||||
* See Config for all configurable options.
|
||||
*
|
||||
* A Note About Paths
|
||||
* ==================
|
||||
*
|
||||
* Files referenced from this file should be defined as
|
||||
*
|
||||
* ```
|
||||
* Config::projectPath('relative_path/to/file')
|
||||
* ```
|
||||
*
|
||||
* where the relative path is relative to the root of the
|
||||
* project which is defined as either the working directory
|
||||
* of the phan executable or a path passed in via the CLI
|
||||
* '-d' flag.
|
||||
*/
|
||||
|
||||
use Phan\Config;
|
||||
|
||||
return [
|
||||
// "target_php_version" => "8.2",
|
||||
// turn color on (-C)
|
||||
"color_issue_messages_if_supported" => true,
|
||||
// If true, missing properties will be created when
|
||||
// they are first seen. If false, we'll report an
|
||||
// error message.
|
||||
"allow_missing_properties" => false,
|
||||
|
||||
// Allow null to be cast as any type and for any
|
||||
// type to be cast to null.
|
||||
"null_casts_as_any_type" => false,
|
||||
|
||||
// Backwards Compatibility Checking
|
||||
'backward_compatibility_checks' => false,
|
||||
|
||||
// Run a quick version of checks that takes less
|
||||
// time
|
||||
"quick_mode" => false,
|
||||
|
||||
// Only emit critical issues to start with
|
||||
// (0 is low severity, 5 is normal severity, 10 is critical)
|
||||
"minimum_severity" => 0,
|
||||
|
||||
// enable for dead code check
|
||||
// this will spill out errors for all methods never called
|
||||
// use after all is OK to try to find unused code blocks
|
||||
// ignore recommended: PhanUnreferencedPublicMethod
|
||||
// "dead_code_detection" => true,
|
||||
|
||||
// default false for include path check
|
||||
"enable_include_path_checks" => true,
|
||||
"include_paths" => [
|
||||
'.',
|
||||
// '../test/configs/'
|
||||
],
|
||||
'ignore_undeclared_variables_in_global_scope' => true,
|
||||
|
||||
"file_list" => [
|
||||
"./test/configs/config.php",
|
||||
// "./test/configs/config.db.php",
|
||||
// "./test/configs/config.host.php",
|
||||
// "./test/configs/config.path.php",
|
||||
"./test/configs/config.other.php",
|
||||
"./test/configs/config.master.php",
|
||||
],
|
||||
|
||||
// A list of directories that should be parsed for class and
|
||||
// method information. After excluding the directories
|
||||
// defined in exclude_analysis_directory_list, the remaining
|
||||
// files will be statically analyzed for errors.
|
||||
//
|
||||
// Thus, both first-party and third-party code being used by
|
||||
// your application should be included in this list.
|
||||
'directory_list' => [
|
||||
// Change this to include the folders you wish to analyze
|
||||
// (and the folders of their dependencies)
|
||||
'src',
|
||||
// To speed up analysis, we recommend going back later and
|
||||
// limiting this to only the vendor/ subdirectories your
|
||||
// project depends on.
|
||||
// `phan --init` will generate a list of folders for you
|
||||
'vendor/egrajp/smarty-extended',
|
||||
],
|
||||
|
||||
|
||||
// A list of directories holding code that we want
|
||||
// to parse, but not analyze
|
||||
"exclude_analysis_directory_list" => [
|
||||
'vendor/egrajp/smarty-extended',
|
||||
],
|
||||
'exclude_file_list' => [
|
||||
],
|
||||
|
||||
// what not to show as problem
|
||||
'suppress_issue_types' => [
|
||||
// 'PhanUndeclaredMethod',
|
||||
'PhanEmptyFile',
|
||||
// ignore unreferences public methods, etc here (for dead code check)
|
||||
'PhanUnreferencedPublicMethod',
|
||||
'PhanUnreferencedClass',
|
||||
'PhanWriteOnlyPublicProperty',
|
||||
'PhanUnreferencedConstant',
|
||||
'PhanWriteOnlyPublicProperty',
|
||||
'PhanReadOnlyPublicProperty'
|
||||
],
|
||||
|
||||
// Override to hardcode existence and types of (non-builtin) globals in the global scope.
|
||||
// Class names should be prefixed with `\`.
|
||||
//
|
||||
// (E.g. `['_FOO' => '\FooClass', 'page' => '\PageClass', 'userId' => 'int']`)
|
||||
'globals_type_map' => [],
|
||||
];
|
||||
40
ReadMe.composer-release.md
Normal file
40
ReadMe.composer-release.md
Normal file
@@ -0,0 +1,40 @@
|
||||
# Create new package in system gitea/gitlab/composer.egplusww.jp
|
||||
|
||||
## Prepare
|
||||
|
||||
The following things must have been done:
|
||||
|
||||
- full phpstan check/phan check where possible
|
||||
- a valid version tag `vX.Y.Z` must have been created and pushed to all services
|
||||
|
||||
## Publish
|
||||
|
||||
To do the final publish
|
||||
|
||||
### GITEA and GITLAB
|
||||
|
||||
Run `publish/publish.sh` script to create composer packages.
|
||||
|
||||
This will automatically run all commands to create the packages
|
||||
|
||||
### composer.egplusww.jp web host
|
||||
|
||||
For the local composer package host.
|
||||
|
||||
update `/storage/var/www/html/composer/www/pacakges.json` file with new version and commit
|
||||
The entry is a copy of the `composer.json` with the following new entries:
|
||||
|
||||
```json
|
||||
{
|
||||
...,
|
||||
"version": "X.Y.Z",
|
||||
...
|
||||
"dist": {
|
||||
"url": "https://git.egplusww.jp/Composer/CoreLibs-Composer-All/archive/vX.Y.Z.zip",
|
||||
"type": "zip"
|
||||
},
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
run `git pull egra-gitea master` on udon-core in `/var/www/html/composer/www`
|
||||
30
ReadMe.md
30
ReadMe.md
@@ -4,20 +4,22 @@ This is just the lib/CoreLibs folder in a composer package.
|
||||
|
||||
For local install only
|
||||
|
||||
## Setup
|
||||
**Note**: for following classes the `egrajp/smarty-extended` has to be installed
|
||||
|
||||
In the composer.json file add the following
|
||||
- Template\SmartyExtended
|
||||
- Admin\EditBase
|
||||
|
||||
```json
|
||||
{
|
||||
"repositories": [
|
||||
{
|
||||
"type": "vcs",
|
||||
"url": "https://git.egplusww.jp/Composer/CoreLibs-Composer-All"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"egrajp/corelibs-composer-all": "@dev"
|
||||
}
|
||||
}
|
||||
## Setup from central composer
|
||||
|
||||
Setup from gitea internal servers
|
||||
|
||||
```sh
|
||||
composer config repositories.git.egplusww.jp.Composer composer https://git.egplusww.jp/api/packages/Composer/composer
|
||||
```
|
||||
|
||||
Alternative setup composer local zip file repot:
|
||||
`composer config repositories.composer.egplusww.jp composer http://composer.egplusww.jp`
|
||||
|
||||
## Install package
|
||||
|
||||
`composer require egrajp/corelibs-composer-all:^8.0`
|
||||
|
||||
@@ -15,5 +15,20 @@
|
||||
}
|
||||
],
|
||||
"minimum-stability": "dev",
|
||||
"require": {}
|
||||
"require": {
|
||||
"php": ">=8.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpstan/phpstan": "^1.10",
|
||||
"phan/phan": "v5.x-dev",
|
||||
"phpunit/phpunit": "^9",
|
||||
"egrajp/smarty-extended": "^4.3",
|
||||
"vimeo/psalm": "^5.0@dev"
|
||||
},
|
||||
"repositories": {
|
||||
"git.egplusww.jp.Composer": {
|
||||
"type": "composer",
|
||||
"url": "https://git.egplusww.jp/api/packages/Composer/composer"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
47
phpstan-baseline.neon
Normal file
47
phpstan-baseline.neon
Normal file
@@ -0,0 +1,47 @@
|
||||
parameters:
|
||||
ignoreErrors:
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$connection of function pg_escape_bytea expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#"
|
||||
count: 1
|
||||
path: src/DB/SQL/PgSQL.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$connection of function pg_escape_identifier expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#"
|
||||
count: 1
|
||||
path: src/DB/SQL/PgSQL.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$connection of function pg_escape_literal expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#"
|
||||
count: 1
|
||||
path: src/DB/SQL/PgSQL.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$connection of function pg_escape_string expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#"
|
||||
count: 1
|
||||
path: src/DB/SQL/PgSQL.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$connection of function pg_execute expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#"
|
||||
count: 1
|
||||
path: src/DB/SQL/PgSQL.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$connection of function pg_parameter_status expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#"
|
||||
count: 1
|
||||
path: src/DB/SQL/PgSQL.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$connection of function pg_prepare expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#"
|
||||
count: 1
|
||||
path: src/DB/SQL/PgSQL.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$connection of function pg_query expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#"
|
||||
count: 1
|
||||
path: src/DB/SQL/PgSQL.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$connection of function pg_query_params expects PgSql\\\\Connection\\|string, object\\|resource given\\.$#"
|
||||
count: 1
|
||||
path: src/DB/SQL/PgSQL.php
|
||||
|
||||
12
phpstan-bootstrap.php
Executable file
12
phpstan-bootstrap.php
Executable file
@@ -0,0 +1,12 @@
|
||||
<?php // phpcs:ignore PSR1.Files.SideEffects
|
||||
|
||||
// Boostrap file for PHPstand
|
||||
// sets the _SERVER['HTTP_HOST'] var so we can have DB detection
|
||||
$_SERVER['HTTP_HOST'] = 'soba.tokyo.tequila.jp';
|
||||
// so www/includes/edit_base.php works
|
||||
// require_once('www/lib/Smarty/SmartyBC.class.php');
|
||||
// for whatever reason it does not load that from the confing.master.php
|
||||
// for includes/admin_header.php
|
||||
define('BASE_NAME', '');
|
||||
|
||||
// __END__
|
||||
21
phpstan-conditional.php
Normal file
21
phpstan-conditional.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
// conditional formats for PHP versions
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
$config = [];
|
||||
|
||||
if (PHP_VERSION_ID >= 8_00_00) {
|
||||
// Change of signature in PHP 8.1
|
||||
/* $config['parameters']['ignoreErrors'][] = [
|
||||
'message' => '~Parameter #1 \$(result|connection) of function pg_\w+ '
|
||||
. 'expects resource(\|null)?, object\|resource given\.~',
|
||||
'path' => 'www/lib/CoreLibs/DB/SQL/PgSQL.php',
|
||||
// 'count' => 1,
|
||||
]; */
|
||||
}
|
||||
|
||||
return $config;
|
||||
|
||||
// __END_
|
||||
42
phpstan.neon
Normal file
42
phpstan.neon
Normal file
@@ -0,0 +1,42 @@
|
||||
# PHP Stan Config
|
||||
includes:
|
||||
- phpstan-conditional.php
|
||||
parameters:
|
||||
tmpDir: /tmp/phpstan-corelibs-composer
|
||||
level: 8 # max is now 9
|
||||
checkMissingCallableSignature: true
|
||||
treatPhpDocTypesAsCertain: false
|
||||
paths:
|
||||
- %currentWorkingDirectory%/src
|
||||
bootstrapFiles:
|
||||
- %currentWorkingDirectory%/phpstan-bootstrap.php
|
||||
- %currentWorkingDirectory%/vendor/autoload.php
|
||||
scanDirectories:
|
||||
- vendor/egrajp/smarty-extended
|
||||
scanFiles:
|
||||
- test/configs/config.php
|
||||
- test/configs/config.master.php
|
||||
- test/configs/config.other.php
|
||||
# excludePaths:
|
||||
# ignore composer
|
||||
# - vendor
|
||||
# ignore errores with
|
||||
ignoreErrors:
|
||||
#- # this error is ignore because of the PHP 8.0 to 8.1 change for pg_*, only for 8.0 or lower
|
||||
# message: "#^Parameter \\#1 \\$(result|connection) of function pg_\\w+ expects resource(\\|null)?, object\\|resource(\\|bool)? given\\.$#"
|
||||
# path: %currentWorkingDirectory%/www/lib/CoreLibs/DB/SQL/PgSQL.php
|
||||
# - # this is for 8.1 or newer
|
||||
# message: "#^Parameter \\#1 \\$(result|connection) of function pg_\\w+ expects PgSql\\\\(Result|Connection(\\|string)?(\\|null)?), object\\|resource given\\.$#"
|
||||
# path: %currentWorkingDirectory%/src/DB/SQL/PgSQL.php
|
||||
# this is ignored for now
|
||||
# - '#Expression in empty\(\) is always falsy.#'
|
||||
# -
|
||||
# message: '#Reflection error: [a-zA-Z0-9\\_]+ not found.#'
|
||||
# path: www/includes/edit_base.php
|
||||
#- 'error regex'
|
||||
#-
|
||||
# message: 'error regex'
|
||||
# path: %currentWorkingDirectory%/www/some/*
|
||||
# paths:
|
||||
# - ...
|
||||
# - ...
|
||||
6
phpunit.xml
Normal file
6
phpunit.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<phpunit
|
||||
cacheResultFile="/tmp/phpunit-corelibs-composer.result.cache"
|
||||
colors="true"
|
||||
verbose="true"
|
||||
>
|
||||
</phpunit>
|
||||
2
publish/.gitignore
vendored
Normal file
2
publish/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*.zip
|
||||
.env*
|
||||
1
publish/last.published
Normal file
1
publish/last.published
Normal file
@@ -0,0 +1 @@
|
||||
8.0.2
|
||||
60
publish/publish.sh
Executable file
60
publish/publish.sh
Executable file
@@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
BASE_FOLDER=$(dirname $(readlink -f $0))"/";
|
||||
VERSION=$(git tag --list | sort -V | tail -n1 | sed -e "s/^v//");
|
||||
file_last_published="${BASE_FOLDER}last.published";
|
||||
|
||||
if [ -z "${VERSION}" ]; then
|
||||
echo "Version must be set in the form x.y.z without any leading characters";
|
||||
exit;
|
||||
fi;
|
||||
# compare version, if different or newer, deploy
|
||||
if [ -f "${file_last_published}" ]; then
|
||||
LAST_PUBLISHED_VERSION=$(cat ${file_last_published});
|
||||
if $(dpkg --compare-versions "${VERSION}" le "${LAST_PUBLISHED_VERSION}"); then
|
||||
echo "git tag version ${VERSION} is not newer than previous published version ${LAST_PUBLISHED_VERSION}";
|
||||
exit;
|
||||
fi;
|
||||
fi;
|
||||
|
||||
# read in the .env.deploy file and we must have
|
||||
# GITLAB_USER
|
||||
# GITLAB_TOKEN
|
||||
# GITEA_DEPLOY_TOKEN
|
||||
if [ ! -f "${BASE_FOLDER}.env.deploy" ]; then
|
||||
echo "Deploy enviroment file .env.deploy is missing";
|
||||
exit;
|
||||
fi;
|
||||
set -o allexport;
|
||||
cd ${BASE_FOLDER};
|
||||
source .env.deploy;
|
||||
cd -;
|
||||
set +o allexport;
|
||||
|
||||
# gitea
|
||||
if [ ! -z "${GITEA_USER}" ] && [ ! -z "${GITEA_TOKEN}" ]; then
|
||||
curl -LJO \
|
||||
--output-dir "${BASE_FOLDER}" \
|
||||
https://git.egplusww.jp/Composer/CoreLibs-Composer-All/archive/v${VERSION}.zip;
|
||||
curl --user ${GITEA_USER}:${GITEA_TOKEN} \
|
||||
--upload-file "${BASE_FOLDER}/CoreLibs-Composer-All-v${VERSION}.zip" \
|
||||
https://git.egplusww.jp/api/packages/Composer/composer?version=${VERSION};
|
||||
echo "${VERSION}" > "${file_last_published}";
|
||||
else
|
||||
echo "Missing either GITEA_USER or GITEA_TOKEN environment variable";
|
||||
fi;
|
||||
|
||||
# gitlab
|
||||
if [ ! -z "${GITLAB_DEPLOY_TOKEN}" ]; then
|
||||
curl --data tag=v${VERSION} \
|
||||
--header "Deploy-Token: ${GITLAB_DEPLOY_TOKEN}" \
|
||||
"https://gitlab-na.factory.tools/api/v4/projects/950/packages/composer";
|
||||
curl --data branch=master \
|
||||
--header "Deploy-Token: ${GITLAB_DEPLOY_TOKEN}" \
|
||||
"https://gitlab-na.factory.tools/api/v4/projects/950/packages/composer";
|
||||
echo "${VERSION}" > "${file_last_published}";
|
||||
else
|
||||
echo "Missing GITLAB_DEPLOY_TOKEN environment variable";
|
||||
fi;
|
||||
|
||||
# __END__
|
||||
@@ -131,6 +131,31 @@ class Login
|
||||
// it will be set back to 255
|
||||
/** @var int */
|
||||
private $password_max_length = 255;
|
||||
|
||||
/** @var int minum password length */
|
||||
public const PASSWORD_MIN_LENGTH = 9;
|
||||
/** @var int maxium password lenght */
|
||||
public const PASSWORD_MAX_LENGTH = 255;
|
||||
/** @var string special characters for regex */
|
||||
public const PASSWORD_SPECIAL_RANGE = '@$!%*?&';
|
||||
/** @var string regex for lower case alphabet */
|
||||
public const PASSWORD_LOWER = '(?=.*[a-z])';
|
||||
/** @var string regex for upper case alphabet */
|
||||
public const PASSWORD_UPPER = '(?=.*[A-Z])';
|
||||
/** @var string regex for numbers */
|
||||
public const PASSWORD_NUMBER = '(?=.*\d)';
|
||||
/** @var string regex for special chanagers */
|
||||
public const PASSWORD_SPECIAL = "(?=.*[" . self::PASSWORD_SPECIAL_RANGE . "])";
|
||||
/** @var string regex for fixed allowed characters password regex */
|
||||
public const PASSWORD_REGEX = "/^"
|
||||
. self::PASSWORD_LOWER
|
||||
. self::PASSWORD_UPPER
|
||||
. self::PASSWORD_NUMBER
|
||||
. self::PASSWORD_SPECIAL
|
||||
. "[A-Za-z\d" . self::PASSWORD_SPECIAL_RANGE . "]"
|
||||
. "{" . self::PASSWORD_MIN_LENGTH . "," . self::PASSWORD_MAX_LENGTH . "}"
|
||||
. "$/";
|
||||
|
||||
/** @var array<string> can have several regexes, if nothing set, all is ok */
|
||||
private $password_valid_chars = [
|
||||
// '^(?=.*\d)(?=.*[A-Za-z])[0-9A-Za-z!@#$%]{8,}$',
|
||||
@@ -157,7 +182,7 @@ class Login
|
||||
private $acl = [];
|
||||
/** @var array<mixed> */
|
||||
private $default_acl_list = [];
|
||||
/** @var array<int|string,mixed> Reverse list to lookup level from type */
|
||||
/** @var array<string,int> Reverse list to lookup level from type */
|
||||
private $default_acl_list_type = [];
|
||||
/** @var int default ACL level to be based on if nothing set */
|
||||
private $default_acl_level = 0;
|
||||
@@ -167,6 +192,17 @@ class Login
|
||||
/** @var bool */
|
||||
private $login_is_ajax_page = false;
|
||||
|
||||
// settings
|
||||
/** @var array<string,mixed> options */
|
||||
private $options = [];
|
||||
/** @var array<string,string> locale options: locale, domain, encoding (opt), path */
|
||||
private $locale = [
|
||||
'locale' => '',
|
||||
'domain' => '',
|
||||
'encoding' => '',
|
||||
'path' => '',
|
||||
];
|
||||
|
||||
/** @var \CoreLibs\Debug\Logging logger */
|
||||
public $log;
|
||||
/** @var \CoreLibs\DB\IO database */
|
||||
@@ -183,15 +219,14 @@ class Login
|
||||
* @param \CoreLibs\DB\IO $db Database connection class
|
||||
* @param \CoreLibs\Debug\Logging $log Logging class
|
||||
* @param \CoreLibs\Create\Session $session Session interface class
|
||||
* @param bool $auto_login [default true] Auto login flag, legacy
|
||||
* If set to true will run login
|
||||
* during construction
|
||||
* @param array<string,mixed> $options Login ACL settings
|
||||
* $auto_login [default true] DEPRECATED, moved into options
|
||||
*/
|
||||
public function __construct(
|
||||
\CoreLibs\DB\IO $db,
|
||||
\CoreLibs\Debug\Logging $log,
|
||||
\CoreLibs\Create\Session $session,
|
||||
bool $auto_login = true
|
||||
array $options = []
|
||||
) {
|
||||
// attach db class
|
||||
$this->db = $db;
|
||||
@@ -202,6 +237,13 @@ class Login
|
||||
// attach session class
|
||||
$this->session = $session;
|
||||
|
||||
// set and check options
|
||||
if (false === $this->loginSetOptions($options)) {
|
||||
// on failure, exit
|
||||
echo "<b>Could not set options</b>";
|
||||
$this->loginTerminate(4000);
|
||||
}
|
||||
|
||||
// string key, msg: string, flag: e (error), o (ok)
|
||||
$this->login_error_msg = [
|
||||
'0' => [
|
||||
@@ -332,14 +374,14 @@ class Login
|
||||
'type' => $res['type'],
|
||||
'name' => $res['name']
|
||||
];
|
||||
$this->default_acl_list_type[$res['type']] = $res['level'];
|
||||
$this->default_acl_list_type[(string)$res['type']] = (int)$res['level'];
|
||||
}
|
||||
// write that into the session
|
||||
$_SESSION['DEFAULT_ACL_LIST'] = $this->default_acl_list;
|
||||
$_SESSION['DEFAULT_ACL_LIST_TYPE'] = $this->default_acl_list_type;
|
||||
|
||||
// this will be deprecated
|
||||
if ($auto_login === true) {
|
||||
if ($this->options['auto_login'] === true) {
|
||||
$this->loginMainCall();
|
||||
}
|
||||
}
|
||||
@@ -384,6 +426,192 @@ class Login
|
||||
// **** PRIVATE INTERNAL
|
||||
// *************************************************************************
|
||||
|
||||
/**
|
||||
* Set options
|
||||
* Current allowed
|
||||
* target <string>: site target
|
||||
* debug <bool>
|
||||
* auto_login <bool>: self start login process
|
||||
* db_schema <string>
|
||||
* password_min_length <int>
|
||||
* default_acl_level <int>
|
||||
* logout_target <string>: should default be '' or target path to where
|
||||
* can_change <bool>: can change password (NOT IMPLEMENTED)
|
||||
* forget_flow <boo>: reset password on forget (NOT IMPLEMENTED)
|
||||
* locale_path <string>: absolue path to the locale folder
|
||||
* site_locale <string>: what locale to load
|
||||
* site_domain <string>: what domain (locale file name) to use
|
||||
*
|
||||
* @param array<string,mixed> $options Options array from class load
|
||||
* @return bool True on ok, False on failure
|
||||
*/
|
||||
private function loginSetOptions(array $options): bool
|
||||
{
|
||||
// target and debug flag
|
||||
if (
|
||||
empty($options['target'])
|
||||
) {
|
||||
$options['target'] = 'test';
|
||||
}
|
||||
if (
|
||||
empty($options['debug']) ||
|
||||
!is_bool($options['debug'])
|
||||
) {
|
||||
$options['debug'] = false;
|
||||
}
|
||||
|
||||
// AUTO LOGIN
|
||||
if (
|
||||
!isset($options['auto_login']) ||
|
||||
!is_bool($options['auto_login'])
|
||||
) {
|
||||
// if set to true will run login call during class construction
|
||||
$options['auto_login'] = false;
|
||||
}
|
||||
|
||||
// DB SCHEMA
|
||||
if (
|
||||
empty($options['db_schema']) ||
|
||||
// TODO more strict check
|
||||
is_string($options['db_schema'])
|
||||
) {
|
||||
// get scham from db, else fallback to public
|
||||
if (!empty($this->db->dbGetSchema(true))) {
|
||||
$options['db_schema'] = $this->db->dbGetSchema(true);
|
||||
} else {
|
||||
$options['db_schema'] = 'public';
|
||||
}
|
||||
}
|
||||
if ($this->db->dbGetSchema() != $options['db_schema']) {
|
||||
$this->db->dbSetSchema($options['db_schema']);
|
||||
}
|
||||
|
||||
// MIN PASSWORD LENGTH
|
||||
// can only be in length of current defined min/max
|
||||
if (
|
||||
!empty($options['password_min_lenght']) &&
|
||||
!is_numeric($options['password_min_length']) &&
|
||||
$options['password_min_length'] >= self::PASSWORD_MIN_LENGTH &&
|
||||
$options['password_min_length'] <= self::PASSWORD_MAX_LENGTH
|
||||
) {
|
||||
if (
|
||||
false === $this->loginSetPasswordMinLength(
|
||||
(int)$options['password_min_length']
|
||||
)
|
||||
) {
|
||||
$options['password_min_length'] = self::PASSWORD_MIN_LENGTH;
|
||||
}
|
||||
}
|
||||
|
||||
// DEFAULT ACL LEVEL
|
||||
if (
|
||||
!isset($options['default_acl_level']) ||
|
||||
!is_numeric($options['default_acl_level']) ||
|
||||
$options['default_acl_level'] < 0 || $options['default_acl_level'] > 100
|
||||
) {
|
||||
$options['default_acl_level'] = 0;
|
||||
if (defined('DEFAULT_ACL_LEVEL')) {
|
||||
trigger_error(
|
||||
'loginMainCall: DEFAULT_ACL_LEVEL should not be used',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
$options['default_acl_level'] = DEFAULT_ACL_LEVEL;
|
||||
}
|
||||
}
|
||||
$this->default_acl_level = (int)$options['default_acl_level'];
|
||||
|
||||
// LOGOUT TARGET
|
||||
if (!isset($options['logout_target'])) {
|
||||
if (defined('LOGOUT_TARGET')) {
|
||||
trigger_error(
|
||||
'loginMainCall: LOGOUT_TARGET should not be used',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
$options['logout_target'] = LOGOUT_TARGET;
|
||||
$this->logout_target = $options['logout_target'];
|
||||
}
|
||||
}
|
||||
|
||||
// *** PASSWORD SETTINGS
|
||||
// User can change password
|
||||
if (
|
||||
!isset($options['can_change']) ||
|
||||
!is_bool($options['can_change'])
|
||||
) {
|
||||
$options['can_change'] = false;
|
||||
}
|
||||
$this->password_change = $options['can_change'];
|
||||
// User can trigger a forgot password flow
|
||||
if (
|
||||
!isset($options['forgot_flow']) ||
|
||||
!is_bool($options['forgot_flow'])
|
||||
) {
|
||||
$options['forgot_flow'] = false;
|
||||
}
|
||||
$this->password_forgot = $options['forgot_flow'];
|
||||
|
||||
// *** LANGUAGE
|
||||
// LANG: LOCALE PATH
|
||||
if (empty($options['locale_path'])) {
|
||||
// trigger deprecation error
|
||||
trigger_error(
|
||||
'loginSetOptions: misssing locale_path entry is deprecated',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
// set path
|
||||
$options['locale_path'] = BASE . INCLUDES . LOCALE;
|
||||
}
|
||||
$_SESSION['LOCALE_PATH'] = $options['locale_path'];
|
||||
// LANG: LOCALE
|
||||
if (empty($options['site_locale'])) {
|
||||
trigger_error(
|
||||
'loginMainCall: SITE_LOCALE should not be used',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
$options['site_locale'] = defined('SITE_LOCALE') && !empty(SITE_LOCALE) ?
|
||||
SITE_LOCALE : 'en.UTF-8';
|
||||
}
|
||||
// LANG: DOMAIN
|
||||
if (empty($options['site_domain'])) {
|
||||
// we need to get domain set from outside
|
||||
$options['site_domain'] = 'admin';
|
||||
if (
|
||||
defined('SITE_DOMAIN')
|
||||
) {
|
||||
// trigger deprecation error
|
||||
trigger_error(
|
||||
'loginSetOptions: misssing site_domain entry is deprecated (SITE_DOMAIN)',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
// set domain
|
||||
$options['site_domain'] = SITE_DOMAIN;
|
||||
} elseif (
|
||||
defined('CONTENT_PATH')
|
||||
) {
|
||||
// trigger deprecation error
|
||||
trigger_error(
|
||||
'loginSetOptions: misssing site_domain entry is deprecated (CONTENT_PATH)',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
$options['set_domain'] = str_replace(DIRECTORY_SEPARATOR, '', CONTENT_PATH);
|
||||
}
|
||||
}
|
||||
$_SESSION['DEFAULT_DOMAIN'] = $options['site_domain'];
|
||||
// LANG: ENCODING
|
||||
if (empty($options['site_encoding'])) {
|
||||
trigger_error(
|
||||
'loginMainCall: SITE_ENCODING should not be used',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
$options['site_encoding'] = defined('SITE_ENCODING') && !empty(SITE_ENCODING) ?
|
||||
SITE_ENCODING : 'UTF-8';
|
||||
}
|
||||
|
||||
// write array to options
|
||||
$this->options = $options;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for all flags and sets error codes for each
|
||||
* In order:
|
||||
@@ -691,6 +919,7 @@ class Login
|
||||
// rgb: nnn.n for each
|
||||
// hsl: nnn.n for first, nnn.n% for 2nd, 3rd
|
||||
// Check\Colors::validateColor()
|
||||
// LANGUAGE/LOCALE/ENCODING:
|
||||
$_SESSION['LANG'] = $res['locale'] ?? 'en';
|
||||
$_SESSION['DEFAULT_CHARSET'] = $res['encoding'] ?? 'UTF-8';
|
||||
$_SESSION['DEFAULT_LOCALE'] = $_SESSION['LANG']
|
||||
@@ -980,13 +1209,72 @@ class Login
|
||||
// $this->debug('ACL', $this->print_ar($this->acl));
|
||||
}
|
||||
|
||||
/**
|
||||
* set locale
|
||||
* if invalid, set to empty string
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function loginSetLocale(): void
|
||||
{
|
||||
// ** LANGUAGE SET AFTER LOGIN **
|
||||
// set the locale
|
||||
if (
|
||||
!empty($_SESSION['DEFAULT_LOCALE']) &&
|
||||
preg_match("/^[-A-Za-z0-9_.@]+$/", $_SESSION['DEFAULT_LOCALE'])
|
||||
) {
|
||||
$locale = $_SESSION['DEFAULT_LOCALE'];
|
||||
} elseif (
|
||||
!preg_match("/^[-A-Za-z0-9_.@]+$/", $this->options['site_locale'])
|
||||
) {
|
||||
$locale = $this->options['site_locale'];
|
||||
} else {
|
||||
$locale = '';
|
||||
}
|
||||
// set the charset
|
||||
preg_match('/(?:\\.(?P<charset>[-A-Za-z0-9_]+))/', $locale, $matches);
|
||||
$locale_encoding = $matches['charset'] ?? '';
|
||||
if (!empty($locale_encoding)) {
|
||||
$encoding = strtoupper($locale_encoding);
|
||||
} elseif (
|
||||
!empty($_SESSION['DEFAULT_CHARSET']) &&
|
||||
preg_match("/^[-A-Za-z0-9_]+$/", $_SESSION['DEFAULT_CHARSET'])
|
||||
) {
|
||||
$encoding = $_SESSION['DEFAULT_CHARSET'];
|
||||
} elseif (
|
||||
!preg_match("/^[-A-Za-z0-9_]+$/", $this->options['site_encoding'])
|
||||
) {
|
||||
$encoding = $this->options['site_encoding'];
|
||||
} else {
|
||||
$encoding = '';
|
||||
}
|
||||
// check domain
|
||||
$domain = $this->options['site_domain'];
|
||||
if (
|
||||
!preg_match("/^\w+$/", $this->options['site_domain'])
|
||||
) {
|
||||
$domain = '';
|
||||
}
|
||||
$path = $this->options['locale_path'];
|
||||
if (!is_dir($path)) {
|
||||
$path = '';
|
||||
}
|
||||
// domain and path are a must set from class options
|
||||
$this->locale = [
|
||||
'locale' => $locale,
|
||||
'domain' => $domain,
|
||||
'encoding' => $encoding,
|
||||
'path' => $path,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if the password is in a valid format
|
||||
*
|
||||
* @param string $password the new password
|
||||
* @return bool true or false if valid password or not
|
||||
*/
|
||||
private function loginPasswordChangeValidPassword($password): bool
|
||||
private function loginPasswordChangeValidPassword(string $password): bool
|
||||
{
|
||||
$is_valid_password = true;
|
||||
// check for valid in regex arrays in list
|
||||
@@ -1048,7 +1336,7 @@ class Login
|
||||
$res = $this->db->dbReturnRow($q);
|
||||
if (
|
||||
!is_array($res) ||
|
||||
(is_array($res) && empty($res['edit_user_id']))
|
||||
empty($res['edit_user_id'])
|
||||
) {
|
||||
// username wrong
|
||||
$this->login_error = 201;
|
||||
@@ -1068,9 +1356,11 @@ class Login
|
||||
}
|
||||
if (
|
||||
!is_array($res) ||
|
||||
(is_array($res) &&
|
||||
(empty($res['edit_user_id']) ||
|
||||
!$this->loginPasswordCheck($res['old_password_hash'], $this->pw_old_password)))
|
||||
empty($res['edit_user_id']) ||
|
||||
!$this->loginPasswordCheck(
|
||||
$res['old_password_hash'],
|
||||
$this->pw_old_password
|
||||
)
|
||||
) {
|
||||
// old password wrong
|
||||
$this->login_error = 202;
|
||||
@@ -1124,7 +1414,7 @@ class Login
|
||||
*
|
||||
* @return string|null html data for login page, or null for nothing
|
||||
*/
|
||||
private function loginCreateLoginHTML()
|
||||
private function loginCreateLoginHTML(): ?string
|
||||
{
|
||||
$html_string = null;
|
||||
// if permission is ok, return null
|
||||
@@ -1421,8 +1711,12 @@ EOM;
|
||||
* @param string $username login user username
|
||||
* @return void has no return
|
||||
*/
|
||||
private function writeLog(string $event, string $data, $error = '', string $username = ''): void
|
||||
{
|
||||
private function writeLog(
|
||||
string $event,
|
||||
string $data,
|
||||
string|int $error = '',
|
||||
string $username = ''
|
||||
): void {
|
||||
if ($this->login) {
|
||||
$this->action = 'Login';
|
||||
} elseif ($this->logout) {
|
||||
@@ -1507,50 +1801,9 @@ EOM;
|
||||
echo '<b>No active session found</b>';
|
||||
$this->loginTerminate(2000);
|
||||
}
|
||||
|
||||
// if we have a search path we need to set it, to use the correct DB to login
|
||||
// check what schema to use. if there is a login schema use this, else check
|
||||
// if there is a schema set in the config, or fall back to DB_SCHEMA
|
||||
// if this exists, if this also does not exists use public schema
|
||||
/** @phpstan-ignore-next-line */
|
||||
if (defined('LOGIN_DB_SCHEMA') && !empty(LOGIN_DB_SCHEMA)) {
|
||||
$SCHEMA = LOGIN_DB_SCHEMA;
|
||||
} elseif (!empty($this->db->dbGetSchema(true))) {
|
||||
$SCHEMA = $this->db->dbGetSchema(true);
|
||||
} elseif (defined('PUBLIC_SCHEMA')) {
|
||||
$SCHEMA = PUBLIC_SCHEMA;
|
||||
} else {
|
||||
$SCHEMA = 'public';
|
||||
}
|
||||
// set schema if schema differs to schema set in db conneciton
|
||||
if ($this->db->dbGetSchema() != $SCHEMA) {
|
||||
$this->db->dbExec("SET search_path TO " . $SCHEMA);
|
||||
}
|
||||
|
||||
// set internal page name
|
||||
$this->page_name = $this->loginReadPageName();
|
||||
|
||||
// set default ACL Level
|
||||
if (defined('DEFAULT_ACL_LEVEL')) {
|
||||
$this->default_acl_level = DEFAULT_ACL_LEVEL;
|
||||
}
|
||||
|
||||
if (defined('PASSWORD_MIN_LENGTH')) {
|
||||
$this->password_min_length = PASSWORD_MIN_LENGTH;
|
||||
$this->password_min_length_max = PASSWORD_MIN_LENGTH;
|
||||
}
|
||||
if (defined('PASSWORD_MIN_LENGTH')) {
|
||||
$this->password_max_length = PASSWORD_MAX_LENGTH;
|
||||
}
|
||||
|
||||
// pre-check that password min/max lengths are inbetween 1 and 255;
|
||||
if ($this->password_max_length > 255) {
|
||||
$this->password_max_length = 255;
|
||||
}
|
||||
if ($this->password_min_length < 1) {
|
||||
$this->password_min_length = 1;
|
||||
}
|
||||
|
||||
// set global is ajax page for if we show the data directly,
|
||||
// or need to pass it back
|
||||
// to the continue AJAX class for output back to the user
|
||||
@@ -1602,20 +1855,8 @@ EOM;
|
||||
$this->pw_old_password = $_POST['pw_old_password'] ?? '';
|
||||
$this->pw_new_password = $_POST['pw_new_password'] ?? '';
|
||||
$this->pw_new_password_confirm = $_POST['pw_new_password_confirm'] ?? '';
|
||||
// logout target (from config)
|
||||
if (defined('LOGOUT_TARGET')) {
|
||||
$this->logout_target = LOGOUT_TARGET;
|
||||
}
|
||||
// disallow user list for password change
|
||||
$this->pw_change_deny_users = ['admin'];
|
||||
// set flag if password change is okay
|
||||
if (defined('PASSWORD_CHANGE')) {
|
||||
$this->password_change = PASSWORD_CHANGE;
|
||||
}
|
||||
// NOTE: forgot password flow with email
|
||||
if (defined('PASSWORD_FORGOT')) {
|
||||
$this->password_forgot = PASSWORD_FORGOT;
|
||||
}
|
||||
// max login counts before error reporting
|
||||
$this->max_login_error_count = 10;
|
||||
// users that never get locked, even if they are set strict
|
||||
@@ -1628,26 +1869,13 @@ EOM;
|
||||
// logsout user
|
||||
$this->loginLogoutUser();
|
||||
// ** LANGUAGE SET AFTER LOGIN **
|
||||
// set the locale
|
||||
if (
|
||||
$this->session->checkActiveSession() === true &&
|
||||
!empty($_SESSION['DEFAULT_LOCALE'])
|
||||
) {
|
||||
$locale = $_SESSION['DEFAULT_LOCALE'];
|
||||
} else {
|
||||
$locale = (defined('SITE_LOCALE') && !empty(SITE_LOCALE)) ?
|
||||
SITE_LOCALE :
|
||||
/** @phpstan-ignore-next-line DEFAULT_LOCALE could be empty */
|
||||
((defined('DEFAULT_LOCALE') && !empty(DEFAULT_LOCALE)) ?
|
||||
DEFAULT_LOCALE : 'en.UTF-8');
|
||||
}
|
||||
// set domain
|
||||
if (defined('CONTENT_PATH')) {
|
||||
$domain = str_replace('/', '', CONTENT_PATH);
|
||||
} else {
|
||||
$domain = 'admin';
|
||||
}
|
||||
$this->l = new \CoreLibs\Language\L10n($locale, $domain);
|
||||
$this->loginSetLocale();
|
||||
// load translator
|
||||
$this->l = new \CoreLibs\Language\L10n(
|
||||
$this->locale['locale'],
|
||||
$this->locale['domain'],
|
||||
$this->locale['path']
|
||||
);
|
||||
// if the password change flag is okay, run the password change method
|
||||
if ($this->password_change) {
|
||||
$this->loginPasswordChange();
|
||||
@@ -1663,18 +1891,21 @@ EOM;
|
||||
// if variable AJAX flag is not set, show output
|
||||
// else pass through for ajax work
|
||||
if ($this->login_is_ajax_page === false) {
|
||||
// the login screen if we hav no login permission & login screen html data
|
||||
// the login screen if we hav no login permission and
|
||||
// login screen html data
|
||||
if ($this->login_html !== null) {
|
||||
// echo $this->login_html;
|
||||
$this->loginPrintLogin();
|
||||
}
|
||||
// do not go anywhere, quit processing here
|
||||
// do something with possible debug data?
|
||||
if (TARGET == 'live' || TARGET == 'remote') {
|
||||
if (
|
||||
in_array($this->options['target'], ['live', 'remove'])
|
||||
) {
|
||||
// login
|
||||
$this->log->setLogLevelAll('debug', DEBUG ? true : false);
|
||||
$this->log->setLogLevelAll('debug', $this->options['debug']);
|
||||
$this->log->setLogLevelAll('echo', false);
|
||||
$this->log->setLogLevelAll('print', DEBUG ? true : false);
|
||||
$this->log->setLogLevelAll('print', $this->options['debug']);
|
||||
}
|
||||
$status_msg = $this->log->printErrorMsg();
|
||||
// if ($this->echo_output_all) {
|
||||
@@ -1794,10 +2025,9 @@ EOM;
|
||||
// check that numeric, positive numeric, not longer than max input string lenght
|
||||
// and not short than min password length
|
||||
if (
|
||||
is_numeric($length) &&
|
||||
$length >= $this->password_min_length_max &&
|
||||
$length <= $this->password_max_length &&
|
||||
$length <= 255
|
||||
$length <= self::PASSWORD_MAX_LENGTH
|
||||
) {
|
||||
$this->password_min_length = $length;
|
||||
return true;
|
||||
@@ -2069,9 +2299,12 @@ EOM;
|
||||
* @param string $type Type name to look in the acl list
|
||||
* @return int|bool Either int level or false for not found
|
||||
*/
|
||||
public function loginGetAclListFromType(string $type)
|
||||
public function loginGetAclListFromType(string $type): int|bool
|
||||
{
|
||||
return $this->default_acl_list_type[$type] ?? false;
|
||||
if (!isset($this->default_acl_list_type[$type])) {
|
||||
return false;
|
||||
}
|
||||
return (int)$this->default_acl_list_type[$type];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2081,7 +2314,7 @@ EOM;
|
||||
* @return bool true/false: if the edit access is not
|
||||
* in the valid list: false
|
||||
*/
|
||||
public function loginCheckEditAccess($edit_access_id): bool
|
||||
public function loginCheckEditAccess(?int $edit_access_id): bool
|
||||
{
|
||||
if ($edit_access_id === null) {
|
||||
return false;
|
||||
@@ -2122,8 +2355,10 @@ EOM;
|
||||
* @param string|int $data_key key value to search for
|
||||
* @return bool|string false for not found or string for found data
|
||||
*/
|
||||
public function loginGetEditAccessData(int $edit_access_id, $data_key)
|
||||
{
|
||||
public function loginGetEditAccessData(
|
||||
int $edit_access_id,
|
||||
string|int $data_key
|
||||
): bool|string {
|
||||
if (!isset($_SESSION['UNIT'][$edit_access_id]['data'][$data_key])) {
|
||||
return false;
|
||||
}
|
||||
@@ -2137,9 +2372,12 @@ EOM;
|
||||
* @param string $uid Edit Access UID to look for
|
||||
* @return int|bool Either primary key in int or false in bool for not found
|
||||
*/
|
||||
public function loginGetEditAccessIdFromUid(string $uid)
|
||||
public function loginGetEditAccessIdFromUid(string $uid): int|bool
|
||||
{
|
||||
return $_SESSION['UNIT_UID'][$uid] ?? false;
|
||||
if (!isset($_SESSION['UNIT_UID'][$uid])) {
|
||||
return false;
|
||||
}
|
||||
return (int)$_SESSION['UNIT_UID'][$uid];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2204,10 +2442,59 @@ EOM;
|
||||
* @param string|int $data_key
|
||||
* @return bool|string
|
||||
*/
|
||||
public function loginSetEditAccessData(int $edit_access_id, $data_key)
|
||||
{
|
||||
public function loginSetEditAccessData(
|
||||
int $edit_access_id,
|
||||
string|int $data_key
|
||||
): bool|string {
|
||||
return $this->loginGetEditAccessData($edit_access_id, $data_key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return locale settings with
|
||||
* locale
|
||||
* domain
|
||||
* encoding
|
||||
* path
|
||||
*
|
||||
* empty string if not set
|
||||
*
|
||||
* @return array<string,string> Locale settings
|
||||
*/
|
||||
public function loginGetLocale(): array
|
||||
{
|
||||
return $this->locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* return header color or null for not set
|
||||
*
|
||||
* @return string|null Header color in RGB hex with leading sharp
|
||||
*/
|
||||
public function loginGetHeaderColor(): ?string
|
||||
{
|
||||
return $_SESSION['HEADER_COLOR'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current loaded list of pages the user can access
|
||||
*
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function loginGetPages(): array
|
||||
{
|
||||
|
||||
return $_SESSION['PAGES'] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current set EUID (edit user id)
|
||||
*
|
||||
* @return string EUID as string
|
||||
*/
|
||||
public function loginGetEuid(): string
|
||||
{
|
||||
return $this->euid;
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
|
||||
@@ -121,14 +121,14 @@ class Backend
|
||||
* @param \CoreLibs\Debug\Logging $log Logging class
|
||||
* @param \CoreLibs\Create\Session $session Session interface class
|
||||
* @param \CoreLibs\Language\L10n $l10n l10n language class
|
||||
* @param array<string,string> $locale locale data read from setLocale
|
||||
* @param int|null $set_default_acl_level Default ACL level
|
||||
*/
|
||||
public function __construct(
|
||||
\CoreLibs\DB\IO $db,
|
||||
\CoreLibs\Debug\Logging $log,
|
||||
\CoreLibs\Create\Session $session,
|
||||
\CoreLibs\Language\L10n $l10n,
|
||||
array $locale
|
||||
?int $set_default_acl_level = null
|
||||
) {
|
||||
// attach db class
|
||||
$this->db = $db;
|
||||
@@ -141,12 +141,12 @@ class Backend
|
||||
// get the language sub class & init it
|
||||
$this->l = $l10n;
|
||||
// parse and read, legacy stuff
|
||||
$locale = $this->l->getLocaleAsArray();
|
||||
$this->encoding = $locale['encoding'];
|
||||
$this->lang = $locale['lang'];
|
||||
// get first part from lang
|
||||
$this->lang_short = explode('_', $locale['lang'])[0];
|
||||
$this->domain = $this->l->getDomain();
|
||||
$this->lang_dir = $this->l->getBaseLocalePath();
|
||||
$this->lang_short = $locale['lang_short'];
|
||||
$this->domain = $locale['domain'];
|
||||
$this->lang_dir = $locale['path'];
|
||||
|
||||
// set the page name
|
||||
$this->page_name = \CoreLibs\Get\System::getPageName();
|
||||
@@ -156,7 +156,14 @@ class Backend
|
||||
$this->$_action = $_POST[$_action] ?? '';
|
||||
}
|
||||
|
||||
$this->default_acl = DEFAULT_ACL_LEVEL;
|
||||
if ($set_default_acl_level === null) {
|
||||
/** @deprecated Admin::__construct missing default_acl_level parameter */
|
||||
trigger_error(
|
||||
'Calling Admin::__construct without default_acl_level parameter is deprecated',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
}
|
||||
$this->default_acl = $set_default_acl_level ?? DEFAULT_ACL_LEVEL;
|
||||
|
||||
// queue key
|
||||
if (preg_match("/^(add|save|delete|remove|move|up|down|push_live)$/", $this->action)) {
|
||||
@@ -190,35 +197,34 @@ class Backend
|
||||
* @param string $event any kind of event description,
|
||||
* @param string|array<mixed> $data any kind of data related to that event
|
||||
* @param string $write_type write type can bei STRING or BINARY
|
||||
* @param string|null $db_schema override target schema
|
||||
* @return void
|
||||
*/
|
||||
public function adbEditLog(
|
||||
string $event = '',
|
||||
$data = '',
|
||||
string $write_type = 'STRING'
|
||||
string|array $data = '',
|
||||
string $write_type = 'STRING',
|
||||
?string $db_schema = null
|
||||
): void {
|
||||
$data_binary = '';
|
||||
$data_write = '';
|
||||
if ($write_type == 'BINARY') {
|
||||
$data_binary = $this->db->dbEscapeBytea((string)bzcompress(serialize($data)));
|
||||
$data = 'see bzip compressed data_binary field';
|
||||
$data_write = 'see bzip compressed data_binary field';
|
||||
}
|
||||
if ($write_type == 'STRING') {
|
||||
$data_binary = '';
|
||||
$data = $this->db->dbEscapeString(serialize($data));
|
||||
$data_write = $this->db->dbEscapeString(serialize($data));
|
||||
}
|
||||
|
||||
// check schema
|
||||
$SCHEMA = 'public';
|
||||
/** @phpstan-ignore-next-line */
|
||||
if (defined('LOGIN_DB_SCHEMA') && !empty(LOGIN_DB_SCHEMA)) {
|
||||
$SCHEMA = LOGIN_DB_SCHEMA;
|
||||
} elseif ($this->db->dbGetSchema()) {
|
||||
$SCHEMA = $this->db->dbGetSchema();
|
||||
} elseif (defined('PUBLIC_SCHEMA')) {
|
||||
$SCHEMA = PUBLIC_SCHEMA;
|
||||
/** @var string $DB_SCHEMA check schema */
|
||||
$DB_SCHEMA = 'public';
|
||||
if ($db_schema !== null) {
|
||||
$DB_SCHEMA = $db_schema;
|
||||
} elseif (!empty($this->db->dbGetSchema())) {
|
||||
$DB_SCHEMA = $this->db->dbGetSchema();
|
||||
}
|
||||
/** @phpstan-ignore-next-line for whatever reason $SCHEMA is seen as possible array */
|
||||
$q = "INSERT INTO " . $SCHEMA . ".edit_log "
|
||||
$q = "INSERT INTO " . $DB_SCHEMA . ".edit_log "
|
||||
. "(euid, event_date, event, data, data_binary, page, "
|
||||
. "ip, user_agent, referer, script_name, query_string, server_name, http_host, "
|
||||
. "http_accept, http_accept_charset, http_accept_encoding, session_id, "
|
||||
@@ -229,10 +235,12 @@ class Backend
|
||||
'NULL')
|
||||
. ", "
|
||||
. "NOW(), "
|
||||
. "'" . $this->db->dbEscapeString((string)$event) . "', '" . $data . "', "
|
||||
. "'" . $data_binary . "', '" . $this->db->dbEscapeString((string)$this->page_name) . "', "
|
||||
. "'" . @$_SERVER["REMOTE_ADDR"] . "', "
|
||||
. "'" . $this->db->dbEscapeString(@$_SERVER['HTTP_USER_AGENT']) . "', "
|
||||
. "'" . $this->db->dbEscapeString((string)$event) . "', "
|
||||
. "'" . $data_write . "', "
|
||||
. "'" . $data_binary . "', "
|
||||
. "'" . $this->db->dbEscapeString((string)$this->page_name) . "', "
|
||||
. "'" . ($_SERVER["REMOTE_ADDR"] ?? '') . "', "
|
||||
. "'" . $this->db->dbEscapeString($_SERVER['HTTP_USER_AGENT'] ?? '') . "', "
|
||||
. "'" . $this->db->dbEscapeString($_SERVER['HTTP_REFERER'] ?? '') . "', "
|
||||
. "'" . $this->db->dbEscapeString($_SERVER['SCRIPT_FILENAME'] ?? '') . "', "
|
||||
. "'" . $this->db->dbEscapeString($_SERVER['QUERY_STRING'] ?? '') . "', "
|
||||
@@ -262,7 +270,7 @@ class Backend
|
||||
* @param string|int $menu_show_flag
|
||||
* @return string|int
|
||||
*/
|
||||
public function adbSetMenuShowFlag($menu_show_flag)
|
||||
public function adbSetMenuShowFlag(string|int $menu_show_flag): string|int
|
||||
{
|
||||
// must be string or int
|
||||
$this->menu_show_flag = $menu_show_flag;
|
||||
@@ -274,7 +282,7 @@ class Backend
|
||||
*
|
||||
* @return string|int
|
||||
*/
|
||||
public function adbGetMenuShowFlag()
|
||||
public function adbGetMenuShowFlag(): string|int
|
||||
{
|
||||
return $this->menu_show_flag;
|
||||
}
|
||||
@@ -282,11 +290,25 @@ class Backend
|
||||
/**
|
||||
* menu creater (from login menu session pages)
|
||||
*
|
||||
* @param int $flag visible flag trigger
|
||||
* @param string|null $set_content_path
|
||||
* @param int $flag visible flag trigger
|
||||
* @return array<mixed> menu array for output on page (smarty)
|
||||
*/
|
||||
public function adbTopMenu(int $flag = 0): array
|
||||
{
|
||||
public function adbTopMenu(
|
||||
?string $set_content_path = null,
|
||||
int $flag = 0,
|
||||
): array {
|
||||
if (
|
||||
$set_content_path === null ||
|
||||
!is_string($set_content_path)
|
||||
) {
|
||||
/** @deprecated adbTopMenu missing set_content_path parameter */
|
||||
trigger_error(
|
||||
'Calling adbTopMenu without set_content_path parameter is deprecated',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
}
|
||||
$set_content_path = $set_content_path ?? CONTENT_PATH;
|
||||
if ($this->menu_show_flag) {
|
||||
$flag = $this->menu_show_flag;
|
||||
}
|
||||
@@ -377,7 +399,7 @@ class Backend
|
||||
\CoreLibs\Get\System::getPageName() == $data['filename'] &&
|
||||
(!isset($data['hostname']) || (
|
||||
isset($data['hostname']) &&
|
||||
(!$data['hostname'] || strstr($data['hostname'], CONTENT_PATH) !== false)
|
||||
(!$data['hostname'] || strstr($data['hostname'], $set_content_path) !== false)
|
||||
))
|
||||
) {
|
||||
$selected = 1;
|
||||
@@ -427,69 +449,6 @@ class Backend
|
||||
};
|
||||
return $enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* creates out of a normal db_return array an assoc array
|
||||
*
|
||||
* @param array<mixed> $db_array input array
|
||||
* @param string|int|bool $key key
|
||||
* @param string|int|bool $value value
|
||||
* @return array<mixed> associative array
|
||||
* @deprecated \CoreLibs\Combined\ArrayHandler::genAssocArray()
|
||||
*/
|
||||
public function adbAssocArray(array $db_array, $key, $value): array
|
||||
{
|
||||
trigger_error(
|
||||
'Method ' . __METHOD__ . ' is deprecated: \CoreLibs\Combined\ArrayHandler::genAssocArray',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
return \CoreLibs\Combined\ArrayHandler::genAssocArray($db_array, $key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* converts bytes into formated string with KB, MB, etc
|
||||
*
|
||||
* @param string|int|float $number string or int or number
|
||||
* @return string formatted string
|
||||
* @deprecated \CoreLibs\Convert\Byte::humanReadableByteFormat()
|
||||
*/
|
||||
public function adbByteStringFormat($number): string
|
||||
{
|
||||
trigger_error(
|
||||
'Method ' . __METHOD__ . ' is deprecated: \CoreLibs\Convert\Byte::humanReadableByteFormat()',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
return \CoreLibs\Convert\Byte::humanReadableByteFormat($number);
|
||||
}
|
||||
|
||||
/**
|
||||
* converts picture to a thumbnail with max x and max y size
|
||||
*
|
||||
* @param string $pic source image file with or without path
|
||||
* @param int $size_x maximum size width
|
||||
* @param int $size_y maximum size height
|
||||
* @param string $dummy empty, or file_type to show an icon
|
||||
* instead of nothing if file is not found
|
||||
* @param string $path if source start is not ROOT path
|
||||
* if empty ROOT is choosen
|
||||
* @return string|bool thumbnail name, or false for error
|
||||
* @deprecated \CoreLibs\Output\Image::createThumbnail()
|
||||
*/
|
||||
public function adbCreateThumbnail(
|
||||
string $pic,
|
||||
int $size_x,
|
||||
int $size_y,
|
||||
string $dummy = '',
|
||||
string $path = '',
|
||||
string $cache = ''
|
||||
) {
|
||||
trigger_error(
|
||||
'Method ' . __METHOD__ . ' is deprecated: \CoreLibs\Output\Image::createThumbnail()',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
return \CoreLibs\Output\Image::createThumbnail($pic, $size_x, $size_y, $dummy, $path, $cache);
|
||||
}
|
||||
|
||||
/**
|
||||
* wrapper function to fill up the mssages array
|
||||
*
|
||||
@@ -523,15 +482,16 @@ class Backend
|
||||
/**
|
||||
* writes live queue
|
||||
*
|
||||
* @param string $queue_key string to identfy the queue
|
||||
* @param string $type [description]
|
||||
* @param string $target [description]
|
||||
* @param string $data [description]
|
||||
* @param string $key_name [description]
|
||||
* @param string $key_value [description]
|
||||
* @param ?string $associate [description]
|
||||
* @param ?string $file [description]
|
||||
* @return void has no return
|
||||
* @param string $queue_key string to identfy the queue
|
||||
* @param string $type [description]
|
||||
* @param string $target [description]
|
||||
* @param string $data [description]
|
||||
* @param string $key_name [description]
|
||||
* @param string $key_value [description]
|
||||
* @param string|null $associate [description]
|
||||
* @param string|null $file [description]
|
||||
* @param string|null $db_schema override target schema
|
||||
* @return void
|
||||
*/
|
||||
public function adbLiveQueue(
|
||||
string $queue_key,
|
||||
@@ -541,19 +501,17 @@ class Backend
|
||||
string $key_name,
|
||||
string $key_value,
|
||||
string $associate = null,
|
||||
string $file = null
|
||||
string $file = null,
|
||||
string $db_schema = null,
|
||||
): void {
|
||||
/** @phpstan-ignore-next-line */
|
||||
if (defined('GLOBAL_DB_SCHEMA') && !empty(GLOBAL_DB_SCHEMA)) {
|
||||
$SCHEMA = GLOBAL_DB_SCHEMA;
|
||||
} elseif ($this->db->dbGetSchema()) {
|
||||
$SCHEMA = $this->db->dbGetSchema();
|
||||
} elseif (defined('PUBLIC_SCHEMA')) {
|
||||
$SCHEMA = PUBLIC_SCHEMA;
|
||||
} else {
|
||||
$SCHEMA = 'public';
|
||||
/** @var string $DB_SCHEMA check schema */
|
||||
$DB_SCHEMA = 'public';
|
||||
if ($db_schema !== null) {
|
||||
$DB_SCHEMA = $db_schema;
|
||||
} elseif (!empty($this->db->dbGetSchema())) {
|
||||
$DB_SCHEMA = $this->db->dbGetSchema();
|
||||
}
|
||||
$q = "INSERT INTO " . $SCHEMA . ".live_queue ("
|
||||
$q = "INSERT INTO " . $DB_SCHEMA . ".live_queue ("
|
||||
. "queue_key, key_value, key_name, type, target, data, group_key, action, associate, file"
|
||||
. ") VALUES ("
|
||||
. "'" . $this->db->dbEscapeString($queue_key) . "', '" . $this->db->dbEscapeString($key_value) . "', "
|
||||
@@ -569,28 +527,28 @@ class Backend
|
||||
* Basic class holds exact the same, except the Year/Month/Day/etc strings
|
||||
* are translated in this call
|
||||
*
|
||||
* @param int $year year YYYY
|
||||
* @param int $month month m
|
||||
* @param int $day day d
|
||||
* @param int $hour hour H
|
||||
* @param int $min min i
|
||||
* @param string $suffix additional info printed after the date time
|
||||
* variable in the drop down
|
||||
* also used for ID in the on change JS call
|
||||
* @param int $min_steps default is 1 (minute), can set to anything,
|
||||
* is used as sum up from 0
|
||||
* @param bool $name_pos_back default false, if set to true,
|
||||
* the name will be printend
|
||||
* after the drop down and not before the drop down
|
||||
* @return string HTML formated strings for drop down lists
|
||||
* of date and time
|
||||
* @param int|string $year year YYYY
|
||||
* @param int|string $month month m
|
||||
* @param int|string $day day d
|
||||
* @param int|string $hour hour H
|
||||
* @param int|string $min min i
|
||||
* @param string $suffix additional info printed after the date time
|
||||
* variable in the drop down
|
||||
* also used for ID in the on change JS call
|
||||
* @param int $min_steps default is 1 (minute), can set to anything,
|
||||
* is used as sum up from 0
|
||||
* @param bool $name_pos_back default false, if set to true,
|
||||
* the name will be printend
|
||||
* after the drop down and not before the drop down
|
||||
* @return string HTML formated strings for drop down lists
|
||||
* of date and time
|
||||
*/
|
||||
public function adbPrintDateTime(
|
||||
$year,
|
||||
$month,
|
||||
$day,
|
||||
$hour,
|
||||
$min,
|
||||
int|string $year,
|
||||
int|string $month,
|
||||
int|string $day,
|
||||
int|string $hour,
|
||||
int|string $min,
|
||||
string $suffix = '',
|
||||
int $min_steps = 1,
|
||||
bool $name_pos_back = false
|
||||
|
||||
@@ -35,6 +35,8 @@ class EditBase
|
||||
private $form;
|
||||
/** @var \CoreLibs\Debug\Logging */
|
||||
public $log;
|
||||
/** @var \CoreLibs\ACL\Login */
|
||||
public $login;
|
||||
|
||||
/**
|
||||
* construct form generator
|
||||
@@ -42,18 +44,24 @@ class EditBase
|
||||
* @param array<mixed> $db_config db config array, mandatory
|
||||
* @param \CoreLibs\Debug\Logging $log Logging class, null auto set
|
||||
* @param \CoreLibs\Language\L10n $l10n l10n language class, null auto set
|
||||
* @param array<string,string> $locale locale array from ::setLocale,
|
||||
* null auto set
|
||||
* @param \CoreLibs\ACL\Login $login login class for ACL settings
|
||||
* @param array<string,mixed> $options Various settings options
|
||||
*/
|
||||
public function __construct(
|
||||
array $db_config,
|
||||
\CoreLibs\Debug\Logging $log,
|
||||
\CoreLibs\Language\L10n $l10n,
|
||||
array $locale
|
||||
\CoreLibs\ACL\Login $login,
|
||||
array $options
|
||||
) {
|
||||
$this->log = $log;
|
||||
$this->login = $login;
|
||||
// smarty template engine (extended Translation version)
|
||||
$this->smarty = new \CoreLibs\Template\SmartyExtend($l10n, $locale);
|
||||
$this->smarty = new \CoreLibs\Template\SmartyExtend(
|
||||
$l10n,
|
||||
$options['cache_id'] ?? '',
|
||||
$options['compile_id'] ?? '',
|
||||
);
|
||||
// turn off set log per class
|
||||
$log->setLogPer('class', false);
|
||||
|
||||
@@ -62,7 +70,7 @@ class EditBase
|
||||
$db_config,
|
||||
$log,
|
||||
$l10n,
|
||||
$locale
|
||||
$this->login->loginGetAcl()
|
||||
);
|
||||
if ($this->form->mobile_phone) {
|
||||
echo "I am sorry, but this page cannot be viewed by a mobile phone";
|
||||
@@ -228,10 +236,14 @@ class EditBase
|
||||
/**
|
||||
* all edit pages
|
||||
*
|
||||
* @param string $set_root
|
||||
* @param string $set_content_path
|
||||
* @return void
|
||||
*/
|
||||
private function editPageFlow(): void
|
||||
{
|
||||
private function editPageFlow(
|
||||
string $set_root,
|
||||
string $set_content_path,
|
||||
): void {
|
||||
// set table width
|
||||
$table_width = '100%';
|
||||
// load call only if id is set
|
||||
@@ -268,23 +280,16 @@ class EditBase
|
||||
|
||||
// MENU START
|
||||
// request some session vars
|
||||
if (empty($_SESSION['HEADER_COLOR'])) {
|
||||
$this->DATA['HEADER_COLOR'] = '#E0E2FF';
|
||||
} else {
|
||||
$this->DATA['HEADER_COLOR'] = $_SESSION['HEADER_COLOR'];
|
||||
}
|
||||
$this->DATA['USER_NAME'] = $_SESSION['USER_NAME'];
|
||||
$this->DATA['EUID'] = $_SESSION['EUID'];
|
||||
$this->DATA['GROUP_NAME'] = $_SESSION['GROUP_NAME'];
|
||||
$this->DATA['GROUP_LEVEL'] = $_SESSION['GROUP_ACL_LEVEL'];
|
||||
$PAGES = $_SESSION['PAGES'];
|
||||
$this->DATA['HEADER_COLOR'] = $this->login->loginGetHeaderColor() ?? '#E0E2FF';
|
||||
$this->DATA['USER_NAME'] = $this->login->loginGetAcl()['user_name'] ?? '';
|
||||
$this->DATA['EUID'] = $this->login->loginGetEuid();
|
||||
$this->DATA['GROUP_NAME'] = $this->login->loginGetAcl()['group_name'] ?? '';
|
||||
$this->DATA['ACCESS_LEVEL'] = $this->login->loginGetAcl()['base'] ?? '';
|
||||
// below is old and to removed when edit_body.tpl is updates
|
||||
$this->DATA['GROUP_LEVEL'] = $this->DATA['ACCESS_LEVEL'];
|
||||
$PAGES = $this->login->loginGetPages();
|
||||
|
||||
//$this->form->log->debug('menu', $this->form->log->prAr($PAGES));
|
||||
|
||||
// build nav from $PAGES ...
|
||||
if (!isset($PAGES) || !is_array($PAGES)) {
|
||||
$PAGES = [];
|
||||
}
|
||||
$menuarray = [];
|
||||
foreach ($PAGES as $PAGE_CUID => $PAGE_DATA) {
|
||||
if ($PAGE_DATA['menu'] && $PAGE_DATA['online']) {
|
||||
@@ -334,7 +339,7 @@ class EditBase
|
||||
$menu_element['filename'] == \CoreLibs\Get\System::getPageName() &&
|
||||
(!isset($menu_element['hostname']) || (
|
||||
isset($menu_element['hostname']) &&
|
||||
(!$menu_element['hostname'] || strstr($menu_element['hostname'], CONTENT_PATH) !== false)
|
||||
(!$menu_element['hostname'] || strstr($menu_element['hostname'], $set_content_path) !== false)
|
||||
))
|
||||
) {
|
||||
$position = $i;
|
||||
@@ -414,6 +419,8 @@ class EditBase
|
||||
$elements[] = $this->form->formCreateElement('additional_acl');
|
||||
break;
|
||||
case 'edit_schemes':
|
||||
// @deprecated Will be removed
|
||||
case 'edit_schemas':
|
||||
$elements[] = $this->form->formCreateElement('enabled');
|
||||
$elements[] = $this->form->formCreateElement('name');
|
||||
$elements[] = $this->form->formCreateElement('header_color');
|
||||
@@ -429,7 +436,7 @@ class EditBase
|
||||
$search_glob = [];
|
||||
foreach ($folders as $folder) {
|
||||
// make sure this folder actually exists
|
||||
if (is_dir(ROOT . $folder)) {
|
||||
if (is_dir($set_root . $folder)) {
|
||||
foreach ($files as $file) {
|
||||
$search_glob[] = $folder . $file;
|
||||
}
|
||||
@@ -532,31 +539,74 @@ class EditBase
|
||||
* @throws Exception
|
||||
* @throws SmartyException
|
||||
*/
|
||||
public function editBaseRun()
|
||||
{
|
||||
public function editBaseRun(
|
||||
?string $template_dir = null,
|
||||
?string $compile_dir = null,
|
||||
?string $cache_dir = null,
|
||||
?string $set_admin_stylesheet = null,
|
||||
?string $set_default_encoding = null,
|
||||
?string $set_css = null,
|
||||
?string $set_js = null,
|
||||
?string $set_root = null,
|
||||
?string $set_content_path = null
|
||||
): void {
|
||||
// trigger deprecated warning
|
||||
if (
|
||||
$template_dir === null ||
|
||||
$compile_dir === null ||
|
||||
$cache_dir === null ||
|
||||
$set_admin_stylesheet === null ||
|
||||
$set_default_encoding === null ||
|
||||
$set_css === null ||
|
||||
$set_js === null ||
|
||||
$set_root === null ||
|
||||
$set_content_path === null
|
||||
) {
|
||||
/** @deprecated editBaseRun call without parameters */
|
||||
trigger_error(
|
||||
'Calling editBaseRun without paramters is deprecated',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
}
|
||||
// set vars (to be deprecated)
|
||||
$template_dir = $template_dir ?? BASE . INCLUDES . TEMPLATES . CONTENT_PATH;
|
||||
$compile_dir = $compile_dir ?? BASE . TEMPLATES_C;
|
||||
$cache_dir = $cache_dir ?? BASE . CACHE;
|
||||
$set_admin_stylesheet = $set_admin_stylesheet ?? ADMIN_STYLESHEET;
|
||||
$set_default_encoding = $set_default_encoding ?? DEFAULT_ENCODING;
|
||||
$set_css = $set_css ?? LAYOUT . CSS;
|
||||
$set_js = $set_js ?? LAYOUT . JS;
|
||||
$set_root = $set_root ?? ROOT;
|
||||
$set_content_path = $set_content_path ?? CONTENT_PATH;
|
||||
|
||||
// set the template dir
|
||||
// WARNING: this has a special check for the mailing tool layout (old layout)
|
||||
if (defined('LAYOUT')) {
|
||||
$this->smarty->setTemplateDir(BASE . INCLUDES . TEMPLATES . CONTENT_PATH);
|
||||
$this->DATA['css'] = LAYOUT . CSS;
|
||||
$this->DATA['js'] = LAYOUT . JS;
|
||||
} else {
|
||||
// WARNING: this has a special check for the mailing tool layout (old no layout folder)
|
||||
if (!defined('LAYOUT')) {
|
||||
trigger_error(
|
||||
'EditBase with unset LAYOUT is deprecated',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
$this->smarty->setTemplateDir(TEMPLATES);
|
||||
$this->DATA['css'] = CSS;
|
||||
$this->DATA['js'] = JS;
|
||||
} else {
|
||||
$this->smarty->setTemplateDir($template_dir);
|
||||
$this->DATA['css'] = $set_css;
|
||||
$this->DATA['js'] = $set_js;
|
||||
}
|
||||
$ADMIN_STYLESHEET = 'edit.css';
|
||||
// define all needed smarty stuff for the general HTML/page building
|
||||
$this->HEADER['CSS'] = CSS;
|
||||
$this->HEADER['DEFAULT_ENCODING'] = DEFAULT_ENCODING;
|
||||
/** @phpstan-ignore-next-line because ADMIN_STYLESHEET can be null */
|
||||
$this->HEADER['STYLESHEET'] = $ADMIN_STYLESHEET ?? ADMIN_STYLESHEET;
|
||||
$this->HEADER['CSS'] = $set_css;
|
||||
$this->HEADER['DEFAULT_ENCODING'] = $set_default_encoding;
|
||||
$this->HEADER['STYLESHEET'] = $set_admin_stylesheet;
|
||||
|
||||
// main run
|
||||
if ($this->form->my_page_name == 'edit_order') {
|
||||
$this->editOrderPage();
|
||||
} else {
|
||||
$this->editPageFlow();
|
||||
$this->editPageFlow(
|
||||
$set_root,
|
||||
$set_content_path
|
||||
);
|
||||
}
|
||||
|
||||
// debug data, if DEBUG flag is on, this data is print out
|
||||
@@ -569,11 +619,11 @@ class EditBase
|
||||
foreach ($CONTENT_DATA as $key => $value) {
|
||||
$this->smarty->assign($key, $value);
|
||||
}
|
||||
if (is_dir(BASE . TEMPLATES_C)) {
|
||||
$this->smarty->setCompileDir(BASE . TEMPLATES_C);
|
||||
if (is_dir($compile_dir)) {
|
||||
$this->smarty->setCompileDir($compile_dir);
|
||||
}
|
||||
if (is_dir(BASE . CACHE)) {
|
||||
$this->smarty->setCacheDir(BASE . CACHE);
|
||||
if (is_dir($cache_dir)) {
|
||||
$this->smarty->setCacheDir($cache_dir);
|
||||
}
|
||||
$this->smarty->display(
|
||||
$this->EDIT_TEMPLATE,
|
||||
|
||||
@@ -672,9 +672,6 @@ class Basic
|
||||
public static function arrayToString(array $array, string $connect_char): string
|
||||
{
|
||||
trigger_error('Method ' . __METHOD__ . ' is deprecated, use join()', E_USER_DEPRECATED);
|
||||
if (!is_array($array)) {
|
||||
$array = [];
|
||||
}
|
||||
return join($connect_char, $array);
|
||||
}
|
||||
|
||||
@@ -992,7 +989,7 @@ class Basic
|
||||
int $jpeg_quality = 80
|
||||
) {
|
||||
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Output\Image::createThumbnailSimple()', E_USER_DEPRECATED);
|
||||
return \CoreLibs\Output\Image::createThumbnailSimple($filename, $thumb_width, $thumb_height, $thumbnail_path, $create_dummy, $use_cache, $high_quality, $jpeg_quality);
|
||||
return \CoreLibs\Output\Image::createThumbnailSimple($filename, $thumb_width, $thumb_height, $thumbnail_path, null, $create_dummy, $use_cache, $high_quality, $jpeg_quality);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -42,8 +42,11 @@ class Colors
|
||||
* @param int|false $hsl_flag flag to check for hsl type
|
||||
* @return bool True if no error, False if error
|
||||
*/
|
||||
private static function rgbHslContentCheck(string $color, $rgb_flag, $hsl_flag): bool
|
||||
{
|
||||
private static function rgbHslContentCheck(
|
||||
string $color,
|
||||
int|false $rgb_flag,
|
||||
int|false $hsl_flag
|
||||
): bool {
|
||||
// extract string between () and split into elements
|
||||
preg_match("/\((.*)\)/", $color, $matches);
|
||||
if (
|
||||
|
||||
@@ -25,7 +25,7 @@ class Encoding
|
||||
* if null is set then "none"
|
||||
* @return void
|
||||
*/
|
||||
public static function setErrorChar($string): void
|
||||
public static function setErrorChar(string|int|null $string): void
|
||||
{
|
||||
if (empty($string)) {
|
||||
$string = 'none';
|
||||
@@ -52,7 +52,7 @@ class Encoding
|
||||
* directly
|
||||
* @return string|int Set error character
|
||||
*/
|
||||
public static function getErrorChar(bool $return_substitute_func = false)
|
||||
public static function getErrorChar(bool $return_substitute_func = false): string|int
|
||||
{
|
||||
// return mb_substitute_character();
|
||||
if ($return_substitute_func === true) {
|
||||
@@ -78,14 +78,14 @@ class Encoding
|
||||
* @param string $string string to test
|
||||
* @param string $from_encoding encoding of string to test
|
||||
* @param string $to_encoding target encoding
|
||||
* @return bool|array<string> false if no error or
|
||||
* @return array<string>|false false if no error or
|
||||
* array with failed characters
|
||||
*/
|
||||
public static function checkConvertEncoding(
|
||||
string $string,
|
||||
string $from_encoding,
|
||||
string $to_encoding
|
||||
) {
|
||||
): array|false {
|
||||
// convert to target encoding and convert back
|
||||
$temp = mb_convert_encoding($string, $to_encoding, $from_encoding);
|
||||
$compare = mb_convert_encoding($temp, $from_encoding, $to_encoding);
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* DEPRECATED: Use correct Convert\Json:: instead
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CoreLibs\Check;
|
||||
|
||||
use CoreLibs\Convert\Json;
|
||||
|
||||
class Jason
|
||||
{
|
||||
/**
|
||||
* @param string|null $json a json string, or null data
|
||||
* @param bool $override if set to true, then on json error
|
||||
* set original value as array
|
||||
* @return array<mixed> returns an array from the json values
|
||||
* @deprecated Use Json::jsonConvertToArray()
|
||||
*/
|
||||
public static function jsonConvertToArray(?string $json, bool $override = false): array
|
||||
{
|
||||
return Json::jsonConvertToArray($json, $override);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool|boolean $return_string [default=false] if set to true
|
||||
* it will return the message string and not
|
||||
* the error number
|
||||
* @return int|string Either error number (0 for no error)
|
||||
* or error string ('' for no error)
|
||||
* @deprecated Use Json::jsonGetLastError()
|
||||
*/
|
||||
public static function jsonGetLastError(bool $return_string = false)
|
||||
{
|
||||
return Json::jsonGetLastError($return_string);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -21,12 +21,12 @@ class ArrayHandler
|
||||
* the needle can be found in the
|
||||
* haystack array
|
||||
*/
|
||||
public static function arraySearchRecursive($needle, array $haystack, ?string $key_search_for = null): array
|
||||
{
|
||||
public static function arraySearchRecursive(
|
||||
string|int $needle,
|
||||
array $haystack,
|
||||
?string $key_search_for = null
|
||||
): array {
|
||||
$path = [];
|
||||
if (!is_array($haystack)) {
|
||||
$haystack = [];
|
||||
}
|
||||
if (
|
||||
$key_search_for != null &&
|
||||
array_key_exists($key_search_for, $haystack) &&
|
||||
@@ -72,7 +72,7 @@ class ArrayHandler
|
||||
*
|
||||
* @param string|int $needle needle (search for)
|
||||
* @param array<mixed> $haystack haystack (search in)
|
||||
* @param string|int $key_search_for the key to look for in
|
||||
* @param string|int|null $key_search_for the key to look for in
|
||||
* @param bool $old [true], if set to false will
|
||||
* return new flat layout
|
||||
* @param array<mixed>|null $path recursive call for previous path
|
||||
@@ -80,9 +80,9 @@ class ArrayHandler
|
||||
* the element was found
|
||||
*/
|
||||
public static function arraySearchRecursiveAll(
|
||||
$needle,
|
||||
string|int $needle,
|
||||
array $haystack,
|
||||
$key_search_for,
|
||||
string|int|null $key_search_for,
|
||||
bool $old = true,
|
||||
?array $path = null
|
||||
): ?array {
|
||||
@@ -101,10 +101,6 @@ class ArrayHandler
|
||||
$path['work'] = [];
|
||||
}
|
||||
}
|
||||
// should not be needed because it would trigger a php mehtod error
|
||||
if (!is_array($haystack)) {
|
||||
$haystack = [];
|
||||
}
|
||||
|
||||
// go through the array,
|
||||
foreach ($haystack as $_key => $_value) {
|
||||
@@ -152,17 +148,18 @@ class ArrayHandler
|
||||
* array search simple. looks for key, value combination, if found, returns true
|
||||
* on default does not strict check, so string '4' will match int 4 and vica versa
|
||||
*
|
||||
* @param array<mixed> $array search in as array
|
||||
* @param string|int $key key (key to search in)
|
||||
* @param string|int $value value (what to find)
|
||||
* @param bool $strict [false], if set to true, will strict check key/value
|
||||
* @return bool true on found, false on not found
|
||||
* @param array<mixed> $array search in as array
|
||||
* @param string|int $key key (key to search in)
|
||||
* @param string|int|bool $value value (what to find)
|
||||
* @param bool $strict [false], if set to true, will strict check key/value
|
||||
* @return bool true on found, false on not found
|
||||
*/
|
||||
public static function arraySearchSimple(array $array, $key, $value, bool $strict = false): bool
|
||||
{
|
||||
if (!is_array($array)) {
|
||||
$array = [];
|
||||
}
|
||||
public static function arraySearchSimple(
|
||||
array $array,
|
||||
string|int $key,
|
||||
string|int|bool $value,
|
||||
bool $strict = false
|
||||
): bool {
|
||||
foreach ($array as $_key => $_value) {
|
||||
// if value is an array, we search
|
||||
if (is_array($_value)) {
|
||||
@@ -189,9 +186,9 @@ class ArrayHandler
|
||||
* bool key flag: true: handle keys as string or int
|
||||
* default false: all keys are string
|
||||
*
|
||||
* @return array<mixed>|bool merged array
|
||||
* @return array<mixed>|false merged array
|
||||
*/
|
||||
public static function arrayMergeRecursive()
|
||||
public static function arrayMergeRecursive(): array|false
|
||||
{
|
||||
// croak on not enough arguemnts (we need at least two)
|
||||
if (func_num_args() < 2) {
|
||||
@@ -264,10 +261,10 @@ class ArrayHandler
|
||||
* @param array<mixed> $needle elements to search for
|
||||
* @param array<mixed> $haystack array where the $needle elements should
|
||||
* be searched int
|
||||
* @return array<mixed>|bool either the found elements or
|
||||
* @return array<mixed>|false either the found elements or
|
||||
* false for nothing found or error
|
||||
*/
|
||||
public static function inArrayAny(array $needle, array $haystack)
|
||||
public static function inArrayAny(array $needle, array $haystack): array|false
|
||||
{
|
||||
$found = [];
|
||||
foreach ($needle as $element) {
|
||||
@@ -291,8 +288,12 @@ class ArrayHandler
|
||||
* @param bool $set_only flag to return all (default), or set only
|
||||
* @return array<mixed> associative array
|
||||
*/
|
||||
public static function genAssocArray(array $db_array, $key, $value, bool $set_only = false): array
|
||||
{
|
||||
public static function genAssocArray(
|
||||
array $db_array,
|
||||
string|int|bool $key,
|
||||
string|int|bool $value,
|
||||
bool $set_only = false
|
||||
): array {
|
||||
$ret_array = [];
|
||||
// do this to only run count once
|
||||
for ($i = 0, $iMax = count($db_array); $i < $iMax; $i++) {
|
||||
@@ -385,11 +386,8 @@ class ArrayHandler
|
||||
* and will be pushed up
|
||||
* @return array<mixed> modified, flattened array
|
||||
*/
|
||||
public static function arrayFlatForKey(array $array, $search): array
|
||||
public static function arrayFlatForKey(array $array, string|int $search): array
|
||||
{
|
||||
if (!is_array($array)) {
|
||||
$array = [];
|
||||
}
|
||||
foreach ($array as $key => $value) {
|
||||
// if it is not an array do just nothing
|
||||
if (!is_array($value)) {
|
||||
|
||||
@@ -74,7 +74,7 @@ class DateTime
|
||||
* @return string formated date+time in Y-M-D h:m:s ms
|
||||
*/
|
||||
public static function dateStringFormat(
|
||||
$timestamp,
|
||||
int|float $timestamp,
|
||||
bool $show_micro = false,
|
||||
bool $micro_as_float = false
|
||||
): string {
|
||||
@@ -100,8 +100,10 @@ class DateTime
|
||||
* @param bool $show_micro show micro seconds, default true
|
||||
* @return string interval formatted string or string as is
|
||||
*/
|
||||
public static function timeStringFormat($timestamp, bool $show_micro = true): string
|
||||
{
|
||||
public static function timeStringFormat(
|
||||
string|int|float $timestamp,
|
||||
bool $show_micro = true
|
||||
): string {
|
||||
// check if the timestamp has any h/m/s/ms inside, if yes skip
|
||||
if (!preg_match("/(h|m|s|ms)/", (string)$timestamp)) {
|
||||
list($timestamp, $ms) = array_pad(explode('.', (string)round((float)$timestamp, 4)), 2, null);
|
||||
@@ -157,7 +159,7 @@ class DateTime
|
||||
* @param string|int|float $timestring formatted interval
|
||||
* @return string|int|float converted float interval, or string as is
|
||||
*/
|
||||
public static function stringToTime($timestring)
|
||||
public static function stringToTime(string|int|float $timestring): string|int|float
|
||||
{
|
||||
$timestamp = 0;
|
||||
if (preg_match("/(d|h|m|s|ms)/", (string)$timestring)) {
|
||||
@@ -247,9 +249,9 @@ class DateTime
|
||||
* @param string $date a date string in the format YYYY-MM-DD
|
||||
* @return bool true if valid date, false if date not valid
|
||||
*/
|
||||
public static function checkDate($date): bool
|
||||
public static function checkDate(string $date): bool
|
||||
{
|
||||
if (!$date) {
|
||||
if (empty($date)) {
|
||||
return false;
|
||||
}
|
||||
list ($year, $month, $day) = array_pad(
|
||||
@@ -324,7 +326,7 @@ class DateTime
|
||||
* @return int|bool false on error
|
||||
* or int -1 (s<e)/0 (s=e)/1 (s>e) as difference
|
||||
*/
|
||||
public static function compareDate($start_date, $end_date)
|
||||
public static function compareDate(string $start_date, string $end_date): int|bool
|
||||
{
|
||||
// pre check for empty or wrong
|
||||
if ($start_date == '--' || $end_date == '--' || !$start_date || !$end_date) {
|
||||
@@ -367,7 +369,7 @@ class DateTime
|
||||
* @return int|bool false for error
|
||||
* or -1 (s<e)/0 (s=e)/1 (s>e) as difference
|
||||
*/
|
||||
public static function compareDateTime($start_datetime, $end_datetime)
|
||||
public static function compareDateTime(string $start_datetime, string $end_datetime): int|bool
|
||||
{
|
||||
// pre check for empty or wrong
|
||||
if ($start_datetime == '--' || $end_datetime == '--' || !$start_datetime || !$end_datetime) {
|
||||
@@ -402,8 +404,11 @@ class DateTime
|
||||
* @param bool $return_named return array type, false (default), true for named
|
||||
* @return array<mixed> 0/overall, 1/weekday, 2/weekend
|
||||
*/
|
||||
public static function calcDaysInterval($start_date, $end_date, bool $return_named = false): array
|
||||
{
|
||||
public static function calcDaysInterval(
|
||||
string $start_date,
|
||||
string $end_date,
|
||||
bool $return_named = false
|
||||
): array {
|
||||
// pos 0 all, pos 1 weekday, pos 2 weekend
|
||||
$days = [];
|
||||
// if anything invalid, return 0,0,0
|
||||
|
||||
@@ -39,7 +39,7 @@ class Byte
|
||||
* @return string converted byte number (float) with suffix
|
||||
* @throws \Exception 1: no valid flag set
|
||||
*/
|
||||
public static function humanReadableByteFormat($bytes, int $flags = 0): string
|
||||
public static function humanReadableByteFormat(string|int|float $bytes, int $flags = 0): string
|
||||
{
|
||||
// if not numeric, return as is
|
||||
if (is_numeric($bytes)) {
|
||||
@@ -121,7 +121,7 @@ class Byte
|
||||
* @return string|int|float converted value or original value
|
||||
* @throws \Exception 1: no valid flag set
|
||||
*/
|
||||
public static function stringByteFormat($number, int $flags = 0)
|
||||
public static function stringByteFormat(string|int|float $number, int $flags = 0): string|int|float
|
||||
{
|
||||
// use SI 1000 mod and not 1024 mod
|
||||
if ($flags & self::BYTE_FORMAT_SI) {
|
||||
|
||||
@@ -31,8 +31,12 @@ class Colors
|
||||
* @return string|bool rgb in hex values with leading # if set,
|
||||
* false for invalid color
|
||||
*/
|
||||
public static function rgb2hex(int $red, int $green, int $blue, bool $hex_prefix = true)
|
||||
{
|
||||
public static function rgb2hex(
|
||||
int $red,
|
||||
int $green,
|
||||
int $blue,
|
||||
bool $hex_prefix = true
|
||||
): string|bool {
|
||||
$hex_color = '';
|
||||
if ($hex_prefix === true) {
|
||||
$hex_color = '#';
|
||||
@@ -61,7 +65,7 @@ class Colors
|
||||
string $hexStr,
|
||||
bool $return_as_string = false,
|
||||
string $seperator = ','
|
||||
) {
|
||||
): string|array|bool {
|
||||
$hexStr = preg_replace("/[^0-9A-Fa-f]/", '', $hexStr); // Gets a proper hex string
|
||||
if (!is_string($hexStr)) {
|
||||
return false;
|
||||
@@ -99,7 +103,7 @@ class Colors
|
||||
* @return array<int|float>|bool Hue, Sat, Brightness/Value
|
||||
* false for input value error
|
||||
*/
|
||||
public static function rgb2hsb(int $red, int $green, int $blue)
|
||||
public static function rgb2hsb(int $red, int $green, int $blue): array|bool
|
||||
{
|
||||
// check that rgb is from 0 to 255
|
||||
foreach (['red', 'green', 'blue'] as $c) {
|
||||
@@ -146,7 +150,7 @@ class Colors
|
||||
* @return array<int>|bool 0 red/1 green/2 blue array as 0-255
|
||||
* false for input value error
|
||||
*/
|
||||
public static function hsb2rgb(float $H, float $S, float $V)
|
||||
public static function hsb2rgb(float $H, float $S, float $V): array|bool
|
||||
{
|
||||
// check that H is 0 to 359, 360 = 0
|
||||
// and S and V are 0 to 1
|
||||
@@ -232,7 +236,7 @@ class Colors
|
||||
* @return array<float>|bool hue/sat/luminance
|
||||
* false for input value error
|
||||
*/
|
||||
public static function rgb2hsl(int $red, int $green, int $blue)
|
||||
public static function rgb2hsl(int $red, int $green, int $blue): array|bool
|
||||
{
|
||||
// check that rgb is from 0 to 255
|
||||
foreach (['red', 'green', 'blue'] as $c) {
|
||||
@@ -285,11 +289,8 @@ class Colors
|
||||
* @param float $lum luminance: 0-100
|
||||
* @return array<int,float|int>|bool red/blue/green 0-255 each
|
||||
*/
|
||||
public static function hsl2rgb(float $hue, float $sat, float $lum)
|
||||
public static function hsl2rgb(float $hue, float $sat, float $lum): array|bool
|
||||
{
|
||||
if (!is_numeric($hue)) {
|
||||
return false;
|
||||
}
|
||||
if ($hue == 360) {
|
||||
$hue = 0;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace CoreLibs\Convert\Extends;
|
||||
|
||||
class VarSetTypeMain
|
||||
class SetVarTypeMain
|
||||
{
|
||||
/**
|
||||
* If input variable is string then returns it, else returns default set
|
||||
@@ -19,7 +19,7 @@ class Html
|
||||
* @param mixed $string string to html encode
|
||||
* @return mixed if string, encoded, else as is (eg null)
|
||||
*/
|
||||
public static function htmlent($string)
|
||||
public static function htmlent(mixed $string): mixed
|
||||
{
|
||||
if (is_string($string)) {
|
||||
return htmlentities($string, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
|
||||
@@ -52,7 +52,7 @@ class Html
|
||||
* @return ?string returns checked or selected,
|
||||
* else returns null
|
||||
*/
|
||||
public static function checked($haystack, string $needle, int $type = 0): ?string
|
||||
public static function checked(array|string $haystack, string $needle, int $type = 0): ?string
|
||||
{
|
||||
if (is_array($haystack)) {
|
||||
if (in_array($needle, $haystack)) {
|
||||
|
||||
@@ -51,13 +51,13 @@ class Json
|
||||
/**
|
||||
* returns human readable string for json errors thrown in jsonConvertToArray
|
||||
*
|
||||
* @param bool|boolean $return_string [default=false] if set to true
|
||||
* it will return the message string and not
|
||||
* the error number
|
||||
* @return int|string Either error number (0 for no error)
|
||||
* or error string ('' for no error)
|
||||
* @param bool $return_string [default=false] if set to true
|
||||
* it will return the message string and not
|
||||
* the error number
|
||||
* @return int|string Either error number (0 for no error)
|
||||
* or error string ('' for no error)
|
||||
*/
|
||||
public static function jsonGetLastError(bool $return_string = false)
|
||||
public static function jsonGetLastError(bool $return_string = false): int|string
|
||||
{
|
||||
$json_error_string = '';
|
||||
// valid errors as of php 8.0
|
||||
|
||||
@@ -48,7 +48,7 @@ class Math
|
||||
* @param string|int|float $number string or number to check
|
||||
* @return float if not number, then returns 0, else original input
|
||||
*/
|
||||
public static function initNumeric($number): float
|
||||
public static function initNumeric(string|int|float $number): float
|
||||
{
|
||||
if (!is_numeric($number)) {
|
||||
return 0;
|
||||
|
||||
@@ -11,9 +11,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace CoreLibs\Convert;
|
||||
|
||||
use CoreLibs\Convert\Extends\VarSetTypeMain;
|
||||
use CoreLibs\Convert\Extends\SetVarTypeMain;
|
||||
|
||||
class VarSetType extends Extends\VarSetTypeMain
|
||||
class SetVarType extends Extends\SetVarTypeMain
|
||||
{
|
||||
/**
|
||||
* Check is input is string, if not return default string.
|
||||
@@ -25,7 +25,7 @@ class VarSetType extends Extends\VarSetTypeMain
|
||||
*/
|
||||
public static function setStr(mixed $val, string $default = ''): string
|
||||
{
|
||||
return (string)VarSetTypeMain::setStrMain($val, $default, false);
|
||||
return (string)SetVarTypeMain::setStrMain($val, $default, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,7 +39,7 @@ class VarSetType extends Extends\VarSetTypeMain
|
||||
*/
|
||||
public static function makeStr(mixed $val, string $default = ''): string
|
||||
{
|
||||
return (string)VarSetTypeMain::makeStrMain($val, $default, false);
|
||||
return (string)SetVarTypeMain::makeStrMain($val, $default, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -52,7 +52,7 @@ class VarSetType extends Extends\VarSetTypeMain
|
||||
*/
|
||||
public static function setInt(mixed $val, int $default = 0): int
|
||||
{
|
||||
return (int)VarSetTypeMain::setIntMain($val, $default, false);
|
||||
return (int)SetVarTypeMain::setIntMain($val, $default, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,7 +65,7 @@ class VarSetType extends Extends\VarSetTypeMain
|
||||
*/
|
||||
public static function makeInt(mixed $val, int $default = 0): int
|
||||
{
|
||||
return (int)VarSetTypeMain::makeIntMain($val, $default, false);
|
||||
return (int)SetVarTypeMain::makeIntMain($val, $default, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,7 +78,7 @@ class VarSetType extends Extends\VarSetTypeMain
|
||||
*/
|
||||
public static function setFloat(mixed $val, float $default = 0.0): float
|
||||
{
|
||||
return (float)VarSetTypeMain::setFloatMain($val, $default, false);
|
||||
return (float)SetVarTypeMain::setFloatMain($val, $default, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,7 +91,7 @@ class VarSetType extends Extends\VarSetTypeMain
|
||||
*/
|
||||
public static function makeFloat(mixed $val, float $default = 0.0): float
|
||||
{
|
||||
return (float)VarSetTypeMain::makeFloatMain($val, $default, false);
|
||||
return (float)SetVarTypeMain::makeFloatMain($val, $default, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,7 +104,7 @@ class VarSetType extends Extends\VarSetTypeMain
|
||||
*/
|
||||
public static function setArray(mixed $val, array $default = []): array
|
||||
{
|
||||
return (array)VarSetTypeMain::setArrayMain($val, $default, false);
|
||||
return (array)SetVarTypeMain::setArrayMain($val, $default, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,7 +117,7 @@ class VarSetType extends Extends\VarSetTypeMain
|
||||
*/
|
||||
public static function setBool(mixed $val, bool $default = false): bool
|
||||
{
|
||||
return (bool)VarSetTypeMain::setBoolMain($val, $default, false);
|
||||
return (bool)SetVarTypeMain::setBoolMain($val, $default, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -129,7 +129,7 @@ class VarSetType extends Extends\VarSetTypeMain
|
||||
*/
|
||||
public static function makeBool(mixed $val, bool $default = false): bool
|
||||
{
|
||||
return (bool)VarSetTypeMain::makeBoolMain($val, $default, false);
|
||||
return (bool)SetVarTypeMain::makeBoolMain($val, $default, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,9 +9,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace CoreLibs\Convert;
|
||||
|
||||
use CoreLibs\Convert\Extends\VarSetTypeMain;
|
||||
use CoreLibs\Convert\Extends\SetVarTypeMain;
|
||||
|
||||
class VarSetTypeNull extends Extends\VarSetTypeMain
|
||||
class SetVarTypeNull extends Extends\SetVarTypeMain
|
||||
{
|
||||
/**
|
||||
* Check is input is string, if not return default string.
|
||||
@@ -23,7 +23,7 @@ class VarSetTypeNull extends Extends\VarSetTypeMain
|
||||
*/
|
||||
public static function setStr(mixed $val, ?string $default = null): ?string
|
||||
{
|
||||
return VarSetTypeMain::setStrMain($val, $default, true);
|
||||
return SetVarTypeMain::setStrMain($val, $default, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,7 +37,7 @@ class VarSetTypeNull extends Extends\VarSetTypeMain
|
||||
*/
|
||||
public static function makeStr(mixed $val, string $default = null): ?string
|
||||
{
|
||||
return VarSetTypeMain::makeStrMain($val, $default, true);
|
||||
return SetVarTypeMain::makeStrMain($val, $default, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ class VarSetTypeNull extends Extends\VarSetTypeMain
|
||||
*/
|
||||
public static function setInt(mixed $val, ?int $default = null): ?int
|
||||
{
|
||||
return VarSetTypeMain::setIntMain($val, $default, true);
|
||||
return SetVarTypeMain::setIntMain($val, $default, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,7 +62,7 @@ class VarSetTypeNull extends Extends\VarSetTypeMain
|
||||
*/
|
||||
public static function makeInt(mixed $val, int $default = null): ?int
|
||||
{
|
||||
return VarSetTypeMain::makeIntMain($val, $default, true);
|
||||
return SetVarTypeMain::makeIntMain($val, $default, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,7 +74,7 @@ class VarSetTypeNull extends Extends\VarSetTypeMain
|
||||
*/
|
||||
public static function setFloat(mixed $val, ?float $default = null): ?float
|
||||
{
|
||||
return VarSetTypeMain::setFloatMain($val, $default, true);
|
||||
return SetVarTypeMain::setFloatMain($val, $default, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,7 +86,7 @@ class VarSetTypeNull extends Extends\VarSetTypeMain
|
||||
*/
|
||||
public static function makeFloat(mixed $val, float $default = null): ?float
|
||||
{
|
||||
return VarSetTypeMain::makeFloatMain($val, $default, true);
|
||||
return SetVarTypeMain::makeFloatMain($val, $default, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,7 +98,7 @@ class VarSetTypeNull extends Extends\VarSetTypeMain
|
||||
*/
|
||||
public static function setArray(mixed $val, ?array $default = null): ?array
|
||||
{
|
||||
return VarSetTypeMain::setArrayMain($val, $default, true);
|
||||
return SetVarTypeMain::setArrayMain($val, $default, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,7 +110,7 @@ class VarSetTypeNull extends Extends\VarSetTypeMain
|
||||
*/
|
||||
public static function setBool(mixed $val, ?bool $default = null): ?bool
|
||||
{
|
||||
return VarSetTypeMain::setBoolMain($val, $default, true);
|
||||
return SetVarTypeMain::setBoolMain($val, $default, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -123,7 +123,7 @@ class VarSetTypeNull extends Extends\VarSetTypeMain
|
||||
{
|
||||
// note that the default value here is irrelevant, we return null
|
||||
// on unsetable string var
|
||||
return VarSetTypeMain::makeBoolMain($val, false, true);
|
||||
return SetVarTypeMain::makeBoolMain($val, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,33 +90,6 @@ class Hash
|
||||
{
|
||||
return hash(self::STANDARD_HASH_LONG, $string);
|
||||
}
|
||||
|
||||
/**
|
||||
* create a unique id with the standard hash type defined in __hash
|
||||
*
|
||||
* @return string Unique ID with fixed length of 8 characters
|
||||
* @deprecated Use \CoreLibs\Create\Uids::uniqIdShort() instead
|
||||
*/
|
||||
public static function __uniqId(): string
|
||||
{
|
||||
trigger_error('Method ' . __METHOD__ . ' is deprecated, '
|
||||
. '\CoreLibs\Create\Uids::uniqIdShort() class', E_USER_DEPRECATED);
|
||||
return \CoreLibs\Create\Uids::uniqIdShort();
|
||||
}
|
||||
|
||||
/**
|
||||
* create a unique id with the standard long hash type
|
||||
* defined in __hashLong
|
||||
*
|
||||
* @return string Unique ID with length of current default long hash
|
||||
* @deprecated Use \CoreLibs\Create\Uids::uniqIdLong() instead
|
||||
*/
|
||||
public static function __uniqIdLong(): string
|
||||
{
|
||||
trigger_error('Method ' . __METHOD__ . ' is deprecated, '
|
||||
. '\CoreLibs\Create\Uids::uniqIdLong() class', E_USER_DEPRECATED);
|
||||
return \CoreLibs\Create\Uids::uniqIdLong();
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
|
||||
@@ -32,7 +32,7 @@ class RandomKey
|
||||
*
|
||||
* @return void has no return
|
||||
*/
|
||||
private static function initRandomKeyData()
|
||||
private static function initRandomKeyData(): void
|
||||
{
|
||||
// random key generation base string
|
||||
self::$key_range = join('', array_merge(
|
||||
@@ -52,7 +52,6 @@ class RandomKey
|
||||
private static function validateRandomKeyLenght(int $key_length): bool
|
||||
{
|
||||
if (
|
||||
is_numeric($key_length) &&
|
||||
$key_length > 0 &&
|
||||
$key_length <= self::$max_key_length
|
||||
) {
|
||||
|
||||
@@ -18,19 +18,6 @@ class Session
|
||||
/** @var string list for errors */
|
||||
private $session_intern_error_str = '';
|
||||
|
||||
/**
|
||||
* Start session
|
||||
* startSession should be called for complete check
|
||||
* If this is called without any name set before the php.ini name is
|
||||
* used.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function startSessionCall(): void
|
||||
{
|
||||
session_start();
|
||||
}
|
||||
|
||||
/**
|
||||
* init a session, if array is empty or array does not have session_name set
|
||||
* then no auto init is run
|
||||
@@ -44,6 +31,19 @@ class Session
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start session
|
||||
* startSession should be called for complete check
|
||||
* If this is called without any name set before the php.ini name is
|
||||
* used.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function startSessionCall(): void
|
||||
{
|
||||
session_start();
|
||||
}
|
||||
|
||||
/**
|
||||
* check if we are in CLI, we set this, so we can mock this
|
||||
* Not this is just a wrapper for the static System::checkCLI call
|
||||
@@ -116,7 +116,7 @@ class Session
|
||||
* @param string|null $session_name
|
||||
* @return string|bool
|
||||
*/
|
||||
public function startSession(?string $session_name = null)
|
||||
public function startSession(?string $session_name = null): string|bool
|
||||
{
|
||||
// we can't start sessions on command line
|
||||
if ($this->checkCliStatus()) {
|
||||
@@ -163,7 +163,7 @@ class Session
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public function getSessionId()
|
||||
public function getSessionId(): string|bool
|
||||
{
|
||||
return session_id();
|
||||
}
|
||||
@@ -173,7 +173,7 @@ class Session
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public function getSessionName()
|
||||
public function getSessionName(): string|bool
|
||||
{
|
||||
return session_name();
|
||||
}
|
||||
@@ -275,7 +275,7 @@ class Session
|
||||
* @param mixed $value value to set (can be anything)
|
||||
* @return void
|
||||
*/
|
||||
public function setS($name, $value): void
|
||||
public function setS(string|int $name, mixed $value): void
|
||||
{
|
||||
$_SESSION[$name] = $value;
|
||||
}
|
||||
@@ -286,7 +286,7 @@ class Session
|
||||
* @param string|int $name value key to get from _SESSION
|
||||
* @return mixed value stored in _SESSION
|
||||
*/
|
||||
public function getS($name)
|
||||
public function getS(string|int $name): mixed
|
||||
{
|
||||
return $_SESSION[$name] ?? '';
|
||||
}
|
||||
@@ -297,7 +297,7 @@ class Session
|
||||
* @param string|int $name Name to check for
|
||||
* @return bool True for set, False fornot set
|
||||
*/
|
||||
public function issetS($name): bool
|
||||
public function issetS(string|int $name): bool
|
||||
{
|
||||
return isset($_SESSION[$name]);
|
||||
}
|
||||
@@ -308,7 +308,7 @@ class Session
|
||||
* @param string|int $name _SESSION key name to remove
|
||||
* @return void
|
||||
*/
|
||||
public function unsetS($name): void
|
||||
public function unsetS(string|int $name): void
|
||||
{
|
||||
if (isset($_SESSION[$name])) {
|
||||
unset($_SESSION[$name]);
|
||||
@@ -325,7 +325,7 @@ class Session
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function __set($name, $value): void
|
||||
public function __set(string|int $name, mixed $value): void
|
||||
{
|
||||
$_SESSION[$name] = $value;
|
||||
}
|
||||
@@ -334,13 +334,14 @@ class Session
|
||||
* Undocumented function
|
||||
*
|
||||
* @param string|int $name
|
||||
* @return mixed
|
||||
* @return mixed If name is not found, it will return null
|
||||
*/
|
||||
public function __get($name)
|
||||
public function __get(string|int $name): mixed
|
||||
{
|
||||
if (isset($_SESSION[$name])) {
|
||||
return $_SESSION[$name];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -349,7 +350,7 @@ class Session
|
||||
* @param string|int $name
|
||||
* @return bool
|
||||
*/
|
||||
public function __isset($name): bool
|
||||
public function __isset(string|int $name): bool
|
||||
{
|
||||
return isset($_SESSION[$name]);
|
||||
}
|
||||
@@ -360,7 +361,7 @@ class Session
|
||||
* @param string|int $name
|
||||
* @return void
|
||||
*/
|
||||
public function __unset($name): void
|
||||
public function __unset(string|int $name): void
|
||||
{
|
||||
if (isset($_SESSION[$name])) {
|
||||
unset($_SESSION[$name]);
|
||||
|
||||
@@ -57,7 +57,7 @@ class ArrayIO extends \CoreLibs\DB\IO
|
||||
* @param array<mixed> $db_config db connection config
|
||||
* @param array<mixed> $table_array table array config
|
||||
* @param string $table_name table name string
|
||||
* @param \CoreLibs\Debug\Logging|null $log Logging class, default set if not set
|
||||
* @param \CoreLibs\Debug\Logging $log Logging class
|
||||
* @param int $base_acl_level Set base acl level, if needed
|
||||
* @param int $acl_admin Flag if this is an admin ACL access level
|
||||
*/
|
||||
@@ -65,12 +65,12 @@ class ArrayIO extends \CoreLibs\DB\IO
|
||||
array $db_config,
|
||||
array $table_array,
|
||||
string $table_name,
|
||||
\CoreLibs\Debug\Logging $log = null,
|
||||
\CoreLibs\Debug\Logging $log,
|
||||
int $base_acl_level = 0,
|
||||
int $acl_admin = 0
|
||||
) {
|
||||
// instance db_io class
|
||||
parent::__construct($db_config, $log ?? new \CoreLibs\Debug\Logging());
|
||||
parent::__construct($db_config, $log);
|
||||
// more error vars for this class
|
||||
$this->error_string['1999'] = 'No table array or table name set';
|
||||
$this->error_string['1021'] = 'No Primary Key given';
|
||||
@@ -137,7 +137,7 @@ class ArrayIO extends \CoreLibs\DB\IO
|
||||
* @param string $text any html encoded string
|
||||
* @return string decoded html string
|
||||
*/
|
||||
public function convertData($text): string
|
||||
public function convertData(string $text): string
|
||||
{
|
||||
$text = str_replace('<b>', '<b>', $text);
|
||||
$text = str_replace('</b>', '</b>', $text);
|
||||
@@ -156,7 +156,7 @@ class ArrayIO extends \CoreLibs\DB\IO
|
||||
* @param string $text encoded html string
|
||||
* @return string decoded html string
|
||||
*/
|
||||
public function convertEntities($text): string
|
||||
public function convertEntities(string $text): string
|
||||
{
|
||||
$text = str_replace('<', '<', $text);
|
||||
$text = str_replace('>', '>', $text);
|
||||
@@ -172,7 +172,7 @@ class ArrayIO extends \CoreLibs\DB\IO
|
||||
* @param bool $write write to error message, default false
|
||||
* @return string the array data as html string entry
|
||||
*/
|
||||
public function dbDumpArray($write = false): string
|
||||
public function dbDumpArray(bool $write = false): string
|
||||
{
|
||||
reset($this->table_array);
|
||||
$string = '';
|
||||
@@ -192,7 +192,7 @@ class ArrayIO extends \CoreLibs\DB\IO
|
||||
*
|
||||
* @return bool true if pk value is set, else false
|
||||
*/
|
||||
public function dbCheckPkSet()
|
||||
public function dbCheckPkSet(): bool
|
||||
{
|
||||
// if pk_id is set, overrule ...
|
||||
if ($this->pk_id) {
|
||||
@@ -210,10 +210,10 @@ class ArrayIO extends \CoreLibs\DB\IO
|
||||
|
||||
/**
|
||||
* resets the whole array values
|
||||
* @param boolean $reset_pk true if we want to reset the pk too
|
||||
* @param bool $reset_pk true if we want to reset the pk too
|
||||
* @return void has no return
|
||||
*/
|
||||
public function dbResetArray($reset_pk = false): void
|
||||
public function dbResetArray(bool $reset_pk = false): void
|
||||
{
|
||||
reset($this->table_array);
|
||||
foreach (array_keys($this->table_array) as $column) {
|
||||
@@ -230,10 +230,10 @@ class ArrayIO extends \CoreLibs\DB\IO
|
||||
*
|
||||
* @param array<mixed> $table_array optional override for table array set
|
||||
* set this as new table array too
|
||||
* @param boolean $acl_limit [false], if set to true, well do ACL limit check
|
||||
* @param bool $acl_limit [false], if set to true, well do ACL limit check
|
||||
* @return array<mixed> returns the table array that was deleted
|
||||
*/
|
||||
public function dbDelete($table_array = [], $acl_limit = false)
|
||||
public function dbDelete(array $table_array = [], bool $acl_limit = false): array
|
||||
{
|
||||
// is array and has values, override set and set new
|
||||
if (is_array($table_array) && count($table_array)) {
|
||||
@@ -294,12 +294,12 @@ class ArrayIO extends \CoreLibs\DB\IO
|
||||
/**
|
||||
* reads one row into the array
|
||||
*
|
||||
* @param boolean $edit on true convert data, else as is
|
||||
* @param bool $edit on true convert data, else as is
|
||||
* @param array<mixed> $table_array optional table array, overwrites
|
||||
* internal set array
|
||||
* @return array<mixed> set table array with values
|
||||
*/
|
||||
public function dbRead($edit = false, $table_array = [])
|
||||
public function dbRead(bool $edit = false, array $table_array = []): array
|
||||
{
|
||||
// if array give, overrules internal array
|
||||
if (is_array($table_array) && count($table_array)) {
|
||||
@@ -381,9 +381,9 @@ class ArrayIO extends \CoreLibs\DB\IO
|
||||
/**
|
||||
* writes one set into DB or updates one set (if PK exists)
|
||||
*
|
||||
* @param boolean $addslashes old convert entities and set set escape
|
||||
* @param bool $addslashes old convert entities and set set escape
|
||||
* @param array<mixed> $table_array optional table array, overwrites internal one
|
||||
* @param boolean $acl_limit [false], if set to true, well do ACL limit check
|
||||
* @param bool $acl_limit [false], if set to true, well do ACL limit check
|
||||
* @return array<mixed> table array or null
|
||||
*/
|
||||
public function dbWrite(
|
||||
@@ -391,7 +391,7 @@ class ArrayIO extends \CoreLibs\DB\IO
|
||||
array $table_array = [],
|
||||
bool $acl_limit = false
|
||||
): array {
|
||||
if (is_array($table_array) && count($table_array)) {
|
||||
if (count($table_array)) {
|
||||
$this->table_array = $table_array;
|
||||
}
|
||||
// PK ID check
|
||||
@@ -475,13 +475,12 @@ class ArrayIO extends \CoreLibs\DB\IO
|
||||
$this->table_array[$column]['type'] != 'view' &&
|
||||
strlen($column) > 0 &&
|
||||
// no acl limiter
|
||||
($acl_limit === false ||
|
||||
(
|
||||
$acl_limit === false ||
|
||||
// acl limit is true, min edit must be at larger than set
|
||||
$acl_limit === true &&
|
||||
$this->base_acl_level >=
|
||||
($this->table_array[$column]['min_edit_acl'] ?? 100)
|
||||
))
|
||||
)
|
||||
) {
|
||||
// for password use hidden value if main is not set
|
||||
if (
|
||||
@@ -528,7 +527,7 @@ class ArrayIO extends \CoreLibs\DB\IO
|
||||
}
|
||||
$q_data .= $_value;
|
||||
} elseif (isset($this->table_array[$column]['bool'])) {
|
||||
// boolean storeage (reverse check on ifset)
|
||||
// bool storage (reverse check on ifset)
|
||||
$q_data .= "'" . $this->dbBoolean($this->table_array[$column]['value'], true) . "'";
|
||||
} elseif (
|
||||
isset($this->table_array[$column]['interval']) ||
|
||||
|
||||
397
src/DB/IO.php
397
src/DB/IO.php
@@ -12,7 +12,7 @@
|
||||
* 2013/10/10, prepare/excute were added, including auto RETURNING primary key if
|
||||
* possible for any INSERT query in exec or prepare/execute, better debugging and
|
||||
* data dumping. Proper string escape wrapper, special db exec writer for complex
|
||||
* array inserts in auto calls. boolean converter from postresql to php
|
||||
* array inserts in auto calls. bool converter from postresql to php
|
||||
*
|
||||
* 2003/12/08, one major change: renamed db_exec_ext to db_return, as it has not
|
||||
* much in common with the normal db_exec wrapper, as it was written only for
|
||||
@@ -168,7 +168,7 @@
|
||||
* - all HTML from the query data (color codes, etc) via flag to debug call
|
||||
*
|
||||
* HISTORY:
|
||||
* 2008/10/25 (cs) add db_boolean to fix the postgres to php boolean var problem
|
||||
* 2008/10/25 (cs) add db_boolean to fix the postgres to php bool var problem
|
||||
* (TODO: implement this in any select return)
|
||||
* 2008/07/03 (cs) add db_write_data function, original written for inventory tool "invSQLWriteData"
|
||||
* 2008/04/16 (cs) add db_escape_string function for correct string escape
|
||||
@@ -288,7 +288,7 @@ class IO
|
||||
private $query; // the query string at the moment
|
||||
// only inside
|
||||
// basic vars
|
||||
/** @var object|resource|bool|int|null */ // replace object with PgSql\Connection|
|
||||
/** @var \PgSql\Connection|false|null */ // replace object with PgSql\Connection|
|
||||
private $dbh; // the dbh handler, if disconnected by command is null, bool:false/int:-1 on error,
|
||||
/** @var bool */
|
||||
private $db_debug = false; // DB_DEBUG ... (if set prints out debug msgs)
|
||||
@@ -315,7 +315,7 @@ class IO
|
||||
/** @var array<mixed,mixed> */
|
||||
private $cursor_ext; // hash of hashes
|
||||
// per query vars
|
||||
/** @var object|resource|bool */ // replace object with PgSql\Result
|
||||
/** @var \PgSql\Result|false */ // replace object with PgSql\Result
|
||||
private $cursor; // actual cursor (DBH)
|
||||
/** @var int */
|
||||
private $num_rows; // how many rows have been found
|
||||
@@ -378,16 +378,16 @@ class IO
|
||||
/**
|
||||
* main DB concstructor with auto connection to DB and failure set on failed connection
|
||||
* @param array<mixed> $db_config DB configuration array
|
||||
* @param \CoreLibs\Debug\Logging|null $log Logging class
|
||||
* @param \CoreLibs\Debug\Logging $log Logging class
|
||||
* @param bool|null $db_debug_override Overrides debug settings in db_config
|
||||
*/
|
||||
public function __construct(
|
||||
array $db_config,
|
||||
?\CoreLibs\Debug\Logging $log = null,
|
||||
\CoreLibs\Debug\Logging $log,
|
||||
?bool $db_debug_override = null
|
||||
) {
|
||||
// attach logger
|
||||
$this->log = $log ?? new \CoreLibs\Debug\Logging();
|
||||
$this->log = $log;
|
||||
// sets the names (for connect/reconnect)
|
||||
$this->db_name = $db_config['db_name'] ?? '';
|
||||
$this->db_user = $db_config['db_user'] ?? '';
|
||||
@@ -405,9 +405,9 @@ class IO
|
||||
$db_debug_override ??
|
||||
// from db config setting
|
||||
$db_config['db_debug'] ??
|
||||
// should be handled from outside
|
||||
// [DEPRECATED] should be handled from outside
|
||||
$_SESSION['DB_DEBUG'] ??
|
||||
// globals should be deprecated
|
||||
// [DEPRECATED] globals should be deprecated
|
||||
$GLOBALS['DB_DEBUG'] ??
|
||||
false
|
||||
);
|
||||
@@ -495,15 +495,15 @@ class IO
|
||||
* OTOH this whole class is so PgSQL specific
|
||||
* that non PgSQL doesn't make much sense anymore
|
||||
*
|
||||
* @return \CoreLibs\DB\SQL\PgSQL|null DB functions object or false on error
|
||||
* @return SQL\PgSQL|null DB functions object or false on error
|
||||
*/
|
||||
private function __loadDBFunctions()
|
||||
private function __loadDBFunctions(): SQL\PgSQL|null
|
||||
{
|
||||
$db_functions = null;
|
||||
switch ($this->db_type) {
|
||||
// list of valid DB function objects
|
||||
case 'pgsql':
|
||||
$db_functions = new \CoreLibs\DB\SQL\PgSQL();
|
||||
$db_functions = new SQL\PgSQL();
|
||||
break;
|
||||
// if non set or none matching abort
|
||||
default:
|
||||
@@ -566,7 +566,7 @@ class IO
|
||||
*/
|
||||
private function __closeDB(): void
|
||||
{
|
||||
if (!empty($this->dbh) && $this->dbh !== false) {
|
||||
if (!empty($this->dbh)) {
|
||||
$this->db_functions->__dbClose();
|
||||
$this->dbh = null;
|
||||
}
|
||||
@@ -632,9 +632,6 @@ class IO
|
||||
private function __printArray(array $array): string
|
||||
{
|
||||
$string = '';
|
||||
if (!is_array($array)) {
|
||||
$array = [];
|
||||
}
|
||||
foreach ($array as $key => $value) {
|
||||
$string .= $this->nbsp . '<b>' . $key . '</b> => ';
|
||||
if (is_array($value)) {
|
||||
@@ -701,7 +698,7 @@ class IO
|
||||
|
||||
/**
|
||||
* Check if there is a cursor and write this cursors error info
|
||||
* @param object|resource|bool $cursor current cursor for pg_result_error,
|
||||
* @param \PgSql\Result|false $cursor current cursor for pg_result_error,
|
||||
* pg_last_error too, but pg_result_error
|
||||
* is more accurate (PgSql\Result)
|
||||
* @return array<mixed> Pos 0: if we could get the method where it was called
|
||||
@@ -709,7 +706,7 @@ class IO
|
||||
* Pos 1: if we have the pg_error_string from last error
|
||||
* if nothing then empty string
|
||||
*/
|
||||
private function __dbErrorPreprocessor($cursor = false): array
|
||||
private function __dbErrorPreprocessor(\PgSql\Result|false $cursor = false): array
|
||||
{
|
||||
$pg_error_string = '';
|
||||
// 1 = self/__dbErrorPreprocessor, 2 = __dbError, __dbWarning,
|
||||
@@ -774,12 +771,15 @@ class IO
|
||||
/**
|
||||
* write an error
|
||||
* @param integer $error_id Any Error ID, used in debug message string
|
||||
* @param object|resource|bool $cursor Optional cursor, passed on to preprocessor
|
||||
* @param \PgSql\Result|false $cursor Optional cursor, passed on to preprocessor
|
||||
* @param string $msg optional message added to debug
|
||||
* @return void
|
||||
*/
|
||||
protected function __dbError(int $error_id, $cursor = false, string $msg = ''): void
|
||||
{
|
||||
protected function __dbError(
|
||||
int $error_id,
|
||||
\PgSql\Result|false $cursor = false,
|
||||
string $msg = ''
|
||||
): void {
|
||||
$error_id = (string)$error_id;
|
||||
[$where_called, $pg_error_string] = $this->__dbErrorPreprocessor($cursor);
|
||||
// write error msg ...
|
||||
@@ -798,12 +798,15 @@ class IO
|
||||
/**
|
||||
* write a warning
|
||||
* @param integer $warning_id Integer warning id added to debug
|
||||
* @param object|resource|bool $cursor Optional cursor, passed on to preprocessor
|
||||
* @param \PgSql\Result|false $cursor Optional cursor, passed on to preprocessor
|
||||
* @param string $msg optional message added to debug
|
||||
* @return void
|
||||
*/
|
||||
protected function __dbWarning(int $warning_id, $cursor = false, string $msg = ''): void
|
||||
{
|
||||
protected function __dbWarning(
|
||||
int $warning_id,
|
||||
\PgSql\Result|false $cursor = false,
|
||||
string $msg = ''
|
||||
): void {
|
||||
$warning_id = (string)$warning_id;
|
||||
[$where_called, $pg_error_string] = $this->__dbErrorPreprocessor($cursor);
|
||||
$this->__dbDebug(
|
||||
@@ -821,18 +824,18 @@ class IO
|
||||
/**
|
||||
* if there is the 'to_encoding' var set,
|
||||
* and the field is in the wrong encoding converts it to the target
|
||||
* @param array<mixed>|bool|null $row Array from fetch_row
|
||||
* @return array<mixed>|bool Convert fetch_row array, or false
|
||||
* @param array<mixed>|false $row Array from fetch_row
|
||||
* @return array<mixed>|false Convert fetch_row array, or false
|
||||
*/
|
||||
private function __dbConvertEncoding($row)
|
||||
private function __dbConvertEncoding(array|false $row): array|false
|
||||
{
|
||||
if ($row === null) {
|
||||
if (is_bool($row)) {
|
||||
return false;
|
||||
}
|
||||
// only do if array, else pass through row (can be false)
|
||||
if (
|
||||
!is_array($row) ||
|
||||
empty($this->to_encoding)// || empty($this->db_encoding)
|
||||
empty($this->to_encoding)
|
||||
) {
|
||||
return $row;
|
||||
}
|
||||
@@ -914,7 +917,7 @@ class IO
|
||||
* check if there is another query running, or do we hang after a
|
||||
* PHP error
|
||||
* @param integer $timeout_seconds For complex timeout waits, default 3 seconds
|
||||
* @return boolean True for connection OK, else false
|
||||
* @return bool True for connection OK, else false
|
||||
*/
|
||||
private function __dbCheckConnectionOk(int $timeout_seconds = 3): bool
|
||||
{
|
||||
@@ -932,7 +935,7 @@ class IO
|
||||
* dbReturn
|
||||
* Read data from previous written data cache
|
||||
* @param string $query_hash The hash for the current query
|
||||
* @param boolean $assoc_only Only return assoc value (key named)
|
||||
* @param bool $assoc_only Only return assoc value (key named)
|
||||
* @return array<mixed> Current position query data from cache
|
||||
*/
|
||||
private function __dbReturnCacheRead(string $query_hash, bool $assoc_only): array
|
||||
@@ -983,10 +986,11 @@ class IO
|
||||
* - sets internal hash for query
|
||||
* - checks multiple call count
|
||||
* @param string $query query string
|
||||
* @param string $pk_name primary key [if set to NULL no returning will be added]
|
||||
* @return string|bool queryt hash OR boolean false on error
|
||||
* @param string $pk_name primary key
|
||||
* [if set to NULL no returning will be added]
|
||||
* @return string|false queryt hash OR bool false on error
|
||||
*/
|
||||
private function __dbPrepareExec(string $query, string $pk_name)
|
||||
private function __dbPrepareExec(string $query, string $pk_name): string|false
|
||||
{
|
||||
// reset current cursor before exec
|
||||
$this->cursor = false;
|
||||
@@ -1152,10 +1156,10 @@ class IO
|
||||
* insert_id_ext [DEPRECATED, all in insert_id_arr]
|
||||
* - holds all returning as array
|
||||
* TODO: Only use insert_id_arr and use functions to get ok array or single
|
||||
* @param boolean $returning_id
|
||||
* @param bool $returning_id
|
||||
* @param string $query
|
||||
* @param string|null $pk_name
|
||||
* @param object|resource|bool $cursor (PgSql\Result)
|
||||
* @param \PgSql\Result|false $cursor (PgSql\Result)
|
||||
* @param string|null $stm_name If not null, is dbExecutre run
|
||||
* @return void
|
||||
*/
|
||||
@@ -1163,7 +1167,7 @@ class IO
|
||||
bool $returning_id,
|
||||
string $query,
|
||||
?string $pk_name,
|
||||
$cursor,
|
||||
\PgSql\Result|false $cursor,
|
||||
?string $stm_name = null
|
||||
): void {
|
||||
// $this->log->debug('DB SET INSERT ID', 'Ret: ' . ($returning_id ? 'Y' : 'N')
|
||||
@@ -1271,10 +1275,10 @@ class IO
|
||||
|
||||
/**
|
||||
* get certain settings like username, db name
|
||||
* @param string $name what setting to query
|
||||
* @return mixed setting value, if not allowed name return false
|
||||
* @param string $name what setting to query
|
||||
* @return int|string|bool setting value, if not allowed name return false
|
||||
*/
|
||||
public function dbGetSetting(string $name)
|
||||
public function dbGetSetting(string $name): int|string|bool
|
||||
{
|
||||
$setting = '';
|
||||
switch ($name) {
|
||||
@@ -1373,7 +1377,7 @@ class IO
|
||||
* extended version info, can access all additional information data
|
||||
* @param string $parameter Array parameter name, if not valid returns
|
||||
* empty string
|
||||
* @param boolean $strip Strip extended server info string, default true
|
||||
* @param bool $strip Strip extended server info string, default true
|
||||
* eg nn.n (other info) will only return nn.n
|
||||
* @return string Parameter value
|
||||
*/
|
||||
@@ -1392,14 +1396,15 @@ class IO
|
||||
}
|
||||
|
||||
/**
|
||||
* returns boolean true or false if the string matches the database version
|
||||
* returns bool true or false if the string matches the database version
|
||||
* @param string $compare string to match in type =X.Y, >X.Y, <X.Y, <=X.Y, >=X.Y
|
||||
* @return bool true for ok, false on not ok
|
||||
*/
|
||||
public function dbCompareVersion(string $compare): bool
|
||||
{
|
||||
$matches = [];
|
||||
// compare has =, >, < prefix, and gets stripped, if the rest is not X.Y format then error
|
||||
// compare has =, >, < prefix, and gets stripped
|
||||
// if the rest is not X.Y format then error
|
||||
preg_match("/^([<>=]{1,})(\d{1,})\.(\d{1,})/", $compare, $matches);
|
||||
$compare = $matches[1];
|
||||
$to_master = $matches[2];
|
||||
@@ -1464,7 +1469,7 @@ class IO
|
||||
* else current cursor
|
||||
* @return string Formated string with all the data in the array
|
||||
*/
|
||||
public function dbDumpData($query = ''): string
|
||||
public function dbDumpData(string $query = ''): string
|
||||
{
|
||||
// set start array
|
||||
if ($query) {
|
||||
@@ -1490,7 +1495,7 @@ class IO
|
||||
* @param string|int|float|bool $string string to escape
|
||||
* @return string escaped string
|
||||
*/
|
||||
public function dbEscapeString($string): string
|
||||
public function dbEscapeString(string|int|float|bool $string): string
|
||||
{
|
||||
return $this->db_functions->__dbEscapeString($string);
|
||||
}
|
||||
@@ -1501,7 +1506,7 @@ class IO
|
||||
* @param string|int|float|bool $string string to escape
|
||||
* @return string escaped string
|
||||
*/
|
||||
public function dbEscapeLiteral($string): string
|
||||
public function dbEscapeLiteral(string|int|float|bool $string): string
|
||||
{
|
||||
return $this->db_functions->__dbEscapeLiteral($string);
|
||||
}
|
||||
@@ -1538,11 +1543,11 @@ class IO
|
||||
|
||||
/**
|
||||
* clear up any data for valid DB insert
|
||||
* @param int|float|string|null $value to escape data
|
||||
* @param string $kbn escape trigger type
|
||||
* @return string escaped value
|
||||
* @param int|float|string|bool|null $value to escape data
|
||||
* @param string $kbn escape trigger type
|
||||
* @return string escaped value
|
||||
*/
|
||||
public function dbSqlEscape($value, string $kbn = '')
|
||||
public function dbSqlEscape(int|float|string|bool|null $value, string $kbn = ''): string
|
||||
{
|
||||
switch ($kbn) {
|
||||
case 'i':
|
||||
@@ -1551,24 +1556,35 @@ class IO
|
||||
case 'f':
|
||||
$value = empty($value) ? 'NULL' : floatval($value);
|
||||
break;
|
||||
// string (null is null, else is string)
|
||||
case 't':
|
||||
$value = $value === null ?
|
||||
'NULL' :
|
||||
"'" . $this->dbEscapeString($value) . "'";
|
||||
break;
|
||||
// string litereal (null is null, else is stirng)
|
||||
case 'tl':
|
||||
$value = $value === null ?
|
||||
'NULL' :
|
||||
$this->dbEscapeLiteral($value);
|
||||
break;
|
||||
// what is d?
|
||||
// escape string, set empty to null
|
||||
case 'd':
|
||||
$value = empty($value) ? 'NULL' : "'" . $this->dbEscapeString($value) . "'";
|
||||
$value = empty($value) ?
|
||||
'NULL' :
|
||||
"'" . $this->dbEscapeString($value) . "'";
|
||||
break;
|
||||
// escape string literal, set empty to null
|
||||
case 'dl':
|
||||
$value = empty($value) ?
|
||||
'NULL' :
|
||||
$this->dbEscapeLiteral($value);
|
||||
break;
|
||||
// bytea data
|
||||
case 'by':
|
||||
$value = empty($value) ? 'NULL' : $this->dbEscapeBytea((string)$value);
|
||||
break;
|
||||
// bool
|
||||
case 'b':
|
||||
if (is_float($value)) {
|
||||
$value = (int)$value;
|
||||
@@ -1577,6 +1593,7 @@ class IO
|
||||
'NULL' :
|
||||
"'" . $this->dbBoolean($value, true) . "'";
|
||||
break;
|
||||
// int, but with empty value is 0
|
||||
case 'i2':
|
||||
$value = empty($value) ? 0 : intval($value);
|
||||
break;
|
||||
@@ -1590,14 +1607,14 @@ class IO
|
||||
|
||||
/**
|
||||
* if the input is a single char 't' or 'f
|
||||
* it will return the boolean value instead
|
||||
* it will return the bool value instead
|
||||
* also converts smallint 1/0 to true false
|
||||
* @param string|bool|int $string 't' / 'f' or any string, or bool true/false
|
||||
* @param boolean $rev do reverse (bool to string)
|
||||
* @return bool|string correct php boolean true/false
|
||||
* @param bool $rev do reverse (bool to string)
|
||||
* @return bool|string correct php bool true/false
|
||||
* or postgresql 't'/'f'
|
||||
*/
|
||||
public function dbBoolean($string, $rev = false)
|
||||
public function dbBoolean(string|bool|int $string, bool $rev = false): bool|string
|
||||
{
|
||||
if (!$rev) {
|
||||
if ($string == 't' || $string == 'true') {
|
||||
@@ -1696,9 +1713,9 @@ class IO
|
||||
* returns an array of the table with columns and values. FALSE on no table found
|
||||
* @param string $table table name
|
||||
* @param string $schema optional schema name
|
||||
* @return array<mixed>|bool array of table data, false on error (table not found)
|
||||
* @return array<mixed>|false array of table data, false on error (table not found)
|
||||
*/
|
||||
public function dbShowTableMetaData(string $table, string $schema = '')
|
||||
public function dbShowTableMetaData(string $table, string $schema = ''): array|false
|
||||
{
|
||||
$this->__dbErrorReset();
|
||||
$table = (!empty($schema) ? $schema . '.' : '') . $table;
|
||||
@@ -1736,14 +1753,14 @@ class IO
|
||||
* NO_CACHE/3: don't write cache
|
||||
* @param bool $assoc_only True to only returned the named and not
|
||||
* index position ones
|
||||
* @return array<mixed>|bool return array data or false on error/end
|
||||
* @return array<mixed>|false return array data or false on error/end
|
||||
* @#suppress PhanTypeMismatchDimFetch
|
||||
*/
|
||||
public function dbReturn(
|
||||
string $query,
|
||||
int $cache = self::USE_CACHE,
|
||||
bool $assoc_only = false
|
||||
) {
|
||||
): array|false {
|
||||
$this->__dbErrorReset();
|
||||
if (!$query) {
|
||||
$this->__dbError(11);
|
||||
@@ -1754,7 +1771,7 @@ class IO
|
||||
// pre declare array
|
||||
if (!isset($this->cursor_ext[$query_hash])) {
|
||||
$this->cursor_ext[$query_hash] = [
|
||||
// cursor, null: unset, 1: finished read/cache, 2: object/resource reading
|
||||
// cursor, null: unset, 1: finished read/cache, 2: object reading
|
||||
'cursor' => null,
|
||||
// cached data
|
||||
'data' => [],
|
||||
@@ -1851,7 +1868,6 @@ class IO
|
||||
|
||||
// if cursor exists ...
|
||||
if ($this->cursor_ext[$query_hash]['cursor']) {
|
||||
/** @phpstan-ignore-next-line claims this is always false, but can be true */
|
||||
if ($first_call === true) {
|
||||
$this->cursor_ext[$query_hash]['log'][] = 'First call';
|
||||
// count the rows returned (if select)
|
||||
@@ -2001,9 +2017,9 @@ class IO
|
||||
* if pk name is table name and _id, pk_name
|
||||
* is not needed to be set
|
||||
* if NULL is given here, no RETURNING will be auto added
|
||||
* @return object|resource|bool cursor for this query or false on error (PgSql\Result)
|
||||
* @return \PgSql\Result|false cursor for this query or false on error
|
||||
*/
|
||||
public function dbExec(string $query = '', string $pk_name = '')
|
||||
public function dbExec(string $query = '', string $pk_name = ''): \PgSql\Result|false
|
||||
{
|
||||
$this->__dbErrorReset();
|
||||
// prepare and check if we can actually run it
|
||||
@@ -2032,7 +2048,7 @@ class IO
|
||||
|
||||
/**
|
||||
* executes a cursor and returns the data, if no more data 0 will be returned
|
||||
* @param object|resource|bool $cursor the cursor from db_exec or
|
||||
* @param \PgSql\Result|false $cursor the cursor from db_exec or
|
||||
* pg_query/pg_exec/mysql_query
|
||||
* if not set will use internal cursor,
|
||||
* if not found, stops with 0 (error)
|
||||
@@ -2040,9 +2056,9 @@ class IO
|
||||
* @param bool $assoc_only false is default,
|
||||
* if true only named rows,
|
||||
* not numbered index rows
|
||||
* @return array<mixed>|bool row array or false on error
|
||||
* @return array<mixed>|false row array or false on error
|
||||
*/
|
||||
public function dbFetchArray($cursor = false, bool $assoc_only = false)
|
||||
public function dbFetchArray(\PgSql\Result|false $cursor = false, bool $assoc_only = false): array|false
|
||||
{
|
||||
$this->__dbErrorReset();
|
||||
// set last available cursor if none set or false
|
||||
@@ -2065,9 +2081,9 @@ class IO
|
||||
* returns the FIRST row of the given query
|
||||
* @param string $query the query to be executed
|
||||
* @param bool $assoc_only if true, only return assoc entry (default false)
|
||||
* @return array<mixed>|bool row array or false on error
|
||||
* @return array<mixed>|false row array or false on error
|
||||
*/
|
||||
public function dbReturnRow(string $query, bool $assoc_only = false)
|
||||
public function dbReturnRow(string $query, bool $assoc_only = false): array|false
|
||||
{
|
||||
$this->__dbErrorReset();
|
||||
if (!$query) {
|
||||
@@ -2092,9 +2108,9 @@ class IO
|
||||
* createds an array of hashes of the query (all data)
|
||||
* @param string $query the query to be executed
|
||||
* @param bool $assoc_only if true, only name ref are returned (default true)
|
||||
* @return array<mixed>|bool array of hashes (row -> fields), false on error
|
||||
* @return array<mixed>|false array of hashes (row -> fields), false on error
|
||||
*/
|
||||
public function dbReturnArray(string $query, bool $assoc_only = true)
|
||||
public function dbReturnArray(string $query, bool $assoc_only = true): array|false
|
||||
{
|
||||
$this->__dbErrorReset();
|
||||
if (!$query) {
|
||||
@@ -2152,41 +2168,44 @@ class IO
|
||||
* returns the full array for cursor ext
|
||||
* or cursor for one query
|
||||
* or detail data fonr one query cursor data
|
||||
* @param string|null $query Query string, if not null convert to hash
|
||||
* and return set cursor ext for only this
|
||||
* if not found or null return null
|
||||
* @return array<mixed>|string|int|resource|object|null
|
||||
* Cursor Extended array full if no parameter
|
||||
* Key is hash string from query run
|
||||
* Or cursor data entry if query field is set
|
||||
* If nothing found return null
|
||||
* @param string|null $query Query string, if not null convert to hash
|
||||
* and return set cursor ext for only this
|
||||
* if not found or null return null
|
||||
* @param string $query_field [=''] optional query field to get
|
||||
* @return array<mixed>|string|int|\PgSql\Result|null
|
||||
* Cursor Extended array full if no parameter
|
||||
* Key is hash string from query run
|
||||
* Or cursor data entry if query field is set
|
||||
* If nothing found return null
|
||||
*/
|
||||
public function dbGetCursorExt($query = null, string $query_field = '')
|
||||
{
|
||||
if ($query !== null) {
|
||||
$query_hash = $this->dbGetQueryHash($query);
|
||||
if (
|
||||
is_array($this->cursor_ext) &&
|
||||
isset($this->cursor_ext[$query_hash])
|
||||
) {
|
||||
if (empty($query_field)) {
|
||||
return $this->cursor_ext[$query_hash];
|
||||
} else {
|
||||
return $this->cursor_ext[$query_hash][$query_field] ?? null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
public function dbGetCursorExt(
|
||||
$query = null,
|
||||
string $query_field = ''
|
||||
): array|string|int|\PgSql\Result|null {
|
||||
if ($query === null) {
|
||||
return $this->cursor_ext;
|
||||
}
|
||||
$query_hash = $this->dbGetQueryHash($query);
|
||||
if (
|
||||
is_array($this->cursor_ext) &&
|
||||
isset($this->cursor_ext[$query_hash])
|
||||
) {
|
||||
if (empty($query_field)) {
|
||||
return $this->cursor_ext[$query_hash];
|
||||
} else {
|
||||
return $this->cursor_ext[$query_hash][$query_field] ?? null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return $this->cursor_ext;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the current position the read out
|
||||
* @param string $query query to find in cursor_ext
|
||||
* @return int|bool query position (row pos), false on error
|
||||
* @return int|false query position (row pos), false on error
|
||||
*/
|
||||
public function dbGetCursorPos(string $query)
|
||||
public function dbGetCursorPos(string $query): int|false
|
||||
{
|
||||
$this->__dbErrorReset();
|
||||
if (!$query) {
|
||||
@@ -2200,9 +2219,9 @@ class IO
|
||||
/**
|
||||
* returns the number of rows for the current select query
|
||||
* @param string $query query to find in cursor_ext
|
||||
* @return int|bool query position (row pos), false on error
|
||||
* @return int|false query position (row pos), false on error
|
||||
*/
|
||||
public function dbGetCursorNumRows(string $query)
|
||||
public function dbGetCursorNumRows(string $query): int|false
|
||||
{
|
||||
$this->__dbErrorReset();
|
||||
if (!$query) {
|
||||
@@ -2254,11 +2273,14 @@ class IO
|
||||
* @param string $stm_name statement name
|
||||
* @param string $query queryt string to run
|
||||
* @param string $pk_name optional primary key
|
||||
* @return bool|object|resource false on error, true on warning or
|
||||
* result on full ok (PgSql\Result)
|
||||
* @return \PgSql\Result|bool false on error, true on warning or
|
||||
* result on full ok
|
||||
*/
|
||||
public function dbPrepare(string $stm_name, string $query, string $pk_name = '')
|
||||
{
|
||||
public function dbPrepare(
|
||||
string $stm_name,
|
||||
string $query,
|
||||
string $pk_name = ''
|
||||
): \PgSql\Result|bool {
|
||||
$this->__dbErrorReset();
|
||||
$matches = [];
|
||||
if (!$query) {
|
||||
@@ -2362,9 +2384,9 @@ class IO
|
||||
* runs a prepare query
|
||||
* @param string $stm_name statement name for the query to run
|
||||
* @param array<mixed> $data data to run for this query, empty array for none
|
||||
* @return mixed false on error, or result on OK
|
||||
* @return \PgSql\Result|false false on error, or result on OK
|
||||
*/
|
||||
public function dbExecute(string $stm_name, array $data = [])
|
||||
public function dbExecute(string $stm_name, array $data = []): \PgSql\Result|false
|
||||
{
|
||||
$this->__dbErrorReset();
|
||||
// if no DB Handler drop out
|
||||
@@ -2484,11 +2506,10 @@ class IO
|
||||
/**
|
||||
* checks a previous async query and returns data if finished
|
||||
* NEEDS : dbExecAsync
|
||||
* @return bool|object|resource cursor resource if the query is still running,
|
||||
* false if an error occured or cursor of that query
|
||||
* (PgSql\Result)
|
||||
* @return \PgSql\Result|bool cursor resource if the query is still running,
|
||||
* false if an error occured or cursor of that query
|
||||
*/
|
||||
public function dbCheckAsync()
|
||||
public function dbCheckAsync(): \PgSql\Result|bool
|
||||
{
|
||||
$this->__dbErrorReset();
|
||||
// if there is actually a async query there
|
||||
@@ -2548,7 +2569,7 @@ class IO
|
||||
* @param int $primary_key id key to decide if we write insert or update
|
||||
* @param string $table name for the target table
|
||||
* @param array<mixed> $data data array to override _POST data
|
||||
* @return int|bool primary key
|
||||
* @return int|false primary key
|
||||
*/
|
||||
public function dbWriteData(
|
||||
array $write_array,
|
||||
@@ -2556,13 +2577,7 @@ class IO
|
||||
int $primary_key,
|
||||
string $table,
|
||||
array $data = []
|
||||
) {
|
||||
if (!is_array($write_array)) {
|
||||
$write_array = [];
|
||||
}
|
||||
if (!is_array($not_write_array)) {
|
||||
$not_write_array = [];
|
||||
}
|
||||
): int|false {
|
||||
$not_write_update_array = [];
|
||||
return $this->dbWriteDataExt(
|
||||
$write_array,
|
||||
@@ -2587,16 +2602,16 @@ class IO
|
||||
* to write during update (optional)
|
||||
* @param array<mixed> $data optional array with data
|
||||
* if not _POST vars are used
|
||||
* @return int|bool primary key
|
||||
* @return int|false primary key
|
||||
*/
|
||||
public function dbWriteDataExt(
|
||||
array $write_array,
|
||||
$primary_key,
|
||||
int|string|array $primary_key,
|
||||
string $table,
|
||||
array $not_write_array = [],
|
||||
array $not_write_update_array = [],
|
||||
array $data = []
|
||||
) {
|
||||
): int|false {
|
||||
if (!is_array($primary_key)) {
|
||||
$primary_key = [
|
||||
'row' => $table . '_id',
|
||||
@@ -2712,7 +2727,10 @@ class IO
|
||||
$primary_key['value'] = $this->dbGetInsertPK();
|
||||
}
|
||||
// if there is not priamry key value field return false
|
||||
return $primary_key['value'] ?? false;
|
||||
if (!is_numeric($primary_key['value'])) {
|
||||
return false;
|
||||
}
|
||||
return (int)$primary_key['value'];
|
||||
}
|
||||
|
||||
// ***************************
|
||||
@@ -2725,7 +2743,7 @@ class IO
|
||||
* @param bool|null $debug true/false or null for just getting current set
|
||||
* @return bool Current debug flag as set
|
||||
*/
|
||||
public function dbSetDebug($debug = null): bool
|
||||
public function dbSetDebug(?bool $debug = null): bool
|
||||
{
|
||||
if ($debug !== null) {
|
||||
$this->db_debug = $debug;
|
||||
@@ -2806,7 +2824,7 @@ class IO
|
||||
* @return bool False on failure to find schema value or set schema,
|
||||
* True on successful set
|
||||
*/
|
||||
public function dbSetSchema(string $db_schema)
|
||||
public function dbSetSchema(string $db_schema): bool
|
||||
{
|
||||
$this->__dbErrorReset();
|
||||
if (empty($db_schema)) {
|
||||
@@ -2935,9 +2953,9 @@ class IO
|
||||
|
||||
/**
|
||||
* Return current database handler
|
||||
* @return object|resource|bool|int|null
|
||||
* @return \PgSql\Connection|false|null
|
||||
*/
|
||||
public function dbGetDbh()
|
||||
public function dbGetDbh(): \PgSql\Connection|false|null
|
||||
{
|
||||
return $this->dbh;
|
||||
}
|
||||
@@ -2993,7 +3011,7 @@ class IO
|
||||
*
|
||||
* @return array<mixed>|string|int|null Current insert query primary key
|
||||
*/
|
||||
public function dbGetInsertPK()
|
||||
public function dbGetInsertPK(): array|string|int|null
|
||||
{
|
||||
if (empty($this->insert_id_pk_name)) {
|
||||
return null;
|
||||
@@ -3017,7 +3035,7 @@ class IO
|
||||
* @param integer|null $pos
|
||||
* @return array<mixed>|string|int|null
|
||||
*/
|
||||
public function dbGetReturningExt(?string $key = null, ?int $pos = null)
|
||||
public function dbGetReturningExt(?string $key = null, ?int $pos = null): array|string|int|null
|
||||
{
|
||||
// return as is if key is null
|
||||
if ($key === null) {
|
||||
@@ -3048,7 +3066,6 @@ class IO
|
||||
} else {
|
||||
// find in all inside the array
|
||||
$__arr = array_column($this->insert_id_arr, $key);
|
||||
/** @phpstan-ignore-next-line [Why is this always true?] */
|
||||
if (count($__arr)) {
|
||||
return $__arr;
|
||||
} else {
|
||||
@@ -3112,7 +3129,7 @@ class IO
|
||||
* Not ethat returnin_id also can return false
|
||||
* but will not set an error entry
|
||||
*/
|
||||
public function dbGetPrepareCursorValue(string $stm_name, string $key)
|
||||
public function dbGetPrepareCursorValue(string $stm_name, string $key): null|string|int|bool
|
||||
{
|
||||
// if no statement name
|
||||
if (empty($stm_name)) {
|
||||
@@ -3161,8 +3178,8 @@ class IO
|
||||
* Sets error number that was last
|
||||
* So we always have the last error number stored even if a new
|
||||
* one is created
|
||||
* @param boolean $transform Set to true to transform into id + error message
|
||||
* @return string Last error number as string or error message
|
||||
* @param bool $transform Set to true to transform into id + error message
|
||||
* @return string Last error number as string or error message
|
||||
*/
|
||||
public function dbGetLastError(bool $transform = false): string
|
||||
{
|
||||
@@ -3182,10 +3199,10 @@ class IO
|
||||
/**
|
||||
* Sets warning number that was last
|
||||
* So we always have the last warning number stored even if a new one is created
|
||||
* @param boolean $transform Set to true to transform into id + warning message
|
||||
* @return string Last Warning number as string or warning message
|
||||
* @param bool $transform Set to true to transform into id + warning message
|
||||
* @return string Last Warning number as string or warning message
|
||||
*/
|
||||
public function dbGetLastWarning(bool $transform = false)
|
||||
public function dbGetLastWarning(bool $transform = false): string
|
||||
{
|
||||
// if no warning, return empty
|
||||
if (empty($this->warning_id)) {
|
||||
@@ -3223,119 +3240,11 @@ class IO
|
||||
* Null for error
|
||||
* @deprecated Use ->dbGetInsertPK();
|
||||
*/
|
||||
public function dbGetReturning()
|
||||
public function dbGetReturning(): array|string|int|bool|null
|
||||
{
|
||||
return $this->dbGetInsertPK();
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the db init error
|
||||
* if failed to connect it is set to true
|
||||
* else false
|
||||
* @return bool connection failure status
|
||||
* @deprecated Use dbGetConnectionStatus() and True means correct connection
|
||||
*/
|
||||
public function getConnectionStatus(): bool
|
||||
{
|
||||
trigger_error('Method ' . __METHOD__ . ' is deprecated, '
|
||||
. 'use dbGetConnectionStatus() with True for successful connection', E_USER_DEPRECATED);
|
||||
// reverse because before it was reverse
|
||||
return $this->dbGetConnectionStatus() ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets error number that was last
|
||||
* So we always have the last error number stored even if a new one is created
|
||||
* @return int last error number
|
||||
* @deprecated Use dbGetLastError()
|
||||
*/
|
||||
public function getHadError(): int
|
||||
{
|
||||
trigger_error('Method ' . __METHOD__ . ' is deprecated, use dbGetLastError()', E_USER_DEPRECATED);
|
||||
return (int)$this->dbGetLastError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets warning number that was last
|
||||
* So we always have the last warning number stored even if a new one is created
|
||||
* @return int last error number
|
||||
* @deprecated Use dbGetLastWarning()
|
||||
*/
|
||||
public function getHadWarning(): int
|
||||
{
|
||||
trigger_error('Method ' . __METHOD__ . ' is deprecated, use dbGetLastWarning()', E_USER_DEPRECATED);
|
||||
return (int)$this->dbGetLastWarning();
|
||||
}
|
||||
|
||||
/**
|
||||
* old call for getInserReturnExt
|
||||
* @param string|null $key See above
|
||||
* @return array<mixed>|string|int|bool|null See above
|
||||
* @deprecated use getReturningExt($key = null) instead
|
||||
*/
|
||||
public function getInsertReturn($key = null)
|
||||
{
|
||||
trigger_error('Method ' . __METHOD__ . ' is deprecated, use getReturningExt($key = null)', E_USER_DEPRECATED);
|
||||
return $this->dbGetReturningExt($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* DEPRECATED: getReturning
|
||||
* @return array<mixed>|string|int|bool|null [DEPRECATED]
|
||||
* @deprecated use dbGetReturning() instead
|
||||
*/
|
||||
public function getReturning()
|
||||
{
|
||||
trigger_error('Method ' . __METHOD__ . ' is deprecated, use dbGetReturning()', E_USER_DEPRECATED);
|
||||
return $this->dbGetInsertPK();
|
||||
}
|
||||
|
||||
/**
|
||||
* DEPRECATED: getInsertPK
|
||||
* @return array<mixed>|string|int|bool|null [DEPRECATED]
|
||||
* @deprecated use dbGetInsertPK() instead
|
||||
*/
|
||||
public function getInsertPK()
|
||||
{
|
||||
trigger_error('Method ' . __METHOD__ . ' is deprecated, use dbGetInsertPK()', E_USER_DEPRECATED);
|
||||
return $this->dbGetInsertPK();
|
||||
}
|
||||
|
||||
/**
|
||||
* DEPRECATED: getReturningExt
|
||||
* @param string|null $key [DEPRECATED]
|
||||
* @return array<mixed>|string|bool|int|null [DEPRECATED]
|
||||
* @deprecated use dbGetReturningExt($key = null) instead
|
||||
*/
|
||||
public function getReturningExt($key = null)
|
||||
{
|
||||
trigger_error('Method ' . __METHOD__ . ' is deprecated, use dbGetReturningExt($key = null)', E_USER_DEPRECATED);
|
||||
return $this->dbGetReturningExt($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* DEPRECATED: getCursorExt
|
||||
* @param string|null $q [DEPRECATED]
|
||||
* @return array<mixed>|string|int|resource|object|null [DEPRECATED]
|
||||
* @deprecated use dbGetCursorExt($q = null) instead
|
||||
*/
|
||||
public function getCursorExt($q = null)
|
||||
{
|
||||
trigger_error('Method ' . __METHOD__ . ' is deprecated, use dbGetCursorExt($q = null)', E_USER_DEPRECATED);
|
||||
return $this->dbGetCursorExt($q);
|
||||
}
|
||||
|
||||
/**
|
||||
* DEPRECATED: getNumRows
|
||||
* @return int|null [DEPRECATED]
|
||||
* @deprecated use dbGetNumRows() instead
|
||||
*/
|
||||
public function getNumRows()
|
||||
{
|
||||
trigger_error('Method ' . __METHOD__ . ' is deprecated, use dbGetNumRows()', E_USER_DEPRECATED);
|
||||
return $this->dbGetNumRows();
|
||||
}
|
||||
|
||||
// end if db class
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CoreLibs\DB\SQL\SqlInterface;
|
||||
namespace CoreLibs\DB\SQL\Interface;
|
||||
|
||||
interface SqlFunctions
|
||||
{
|
||||
@@ -21,33 +21,33 @@ interface SqlFunctions
|
||||
* Undocumented function
|
||||
*
|
||||
* @param string $query
|
||||
* @return object|resource|bool
|
||||
* @return \PgSql\Result|false
|
||||
*/
|
||||
public function __dbQuery(string $query);
|
||||
public function __dbQuery(string $query): \PgSql\Result|false;
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param string $query
|
||||
* @param array<mixed> $params
|
||||
* @return object|resource|bool
|
||||
* @return \PgSql\Result|false
|
||||
*/
|
||||
public function __dbQueryParams(string $query, array $params);
|
||||
public function __dbQueryParams(string $query, array $params): \PgSql\Result|false;
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param string $query
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function __dbSendQuery(string $query): bool;
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return object|resource|bool
|
||||
* @return \PgSql\Result|false
|
||||
*/
|
||||
public function __dbGetResult();
|
||||
public function __dbGetResult(): \PgSql\Result|false;
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
@@ -61,85 +61,85 @@ interface SqlFunctions
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $query
|
||||
* @return object|resource|bool
|
||||
* @return \PgSql\Result|false
|
||||
*/
|
||||
public function __dbPrepare(string $name, string $query);
|
||||
public function __dbPrepare(string $name, string $query): \PgSql\Result|false;
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param string $name
|
||||
* @param array<mixed> $data
|
||||
* @return object|resource|bool
|
||||
* @return \PgSql\Result|false
|
||||
*/
|
||||
public function __dbExecute(string $name, array $data);
|
||||
public function __dbExecute(string $name, array $data): \PgSql\Result|false;
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param object|resource|bool $cursor
|
||||
* @return integer
|
||||
* @param \PgSql\Result|false $cursor
|
||||
* @return int
|
||||
*/
|
||||
public function __dbNumRows($cursor): int;
|
||||
public function __dbNumRows(\PgSql\Result|false $cursor): int;
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param object|resource|bool $cursor
|
||||
* @return integer
|
||||
* @param \PgSql\Result|false $cursor
|
||||
* @return int
|
||||
*/
|
||||
public function __dbNumFields($cursor): int;
|
||||
public function __dbNumFields(\PgSql\Result|false $cursor): int;
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param object|resource|bool $cursor
|
||||
* @param \PgSql\Result|false $cursor
|
||||
* @param int $i
|
||||
* @return string|bool
|
||||
* @return string|false
|
||||
*/
|
||||
public function __dbFieldName($cursor, int $i);
|
||||
public function __dbFieldName(\PgSql\Result|false $cursor, int $i): string|false;
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param object|resource|bool $cursor
|
||||
* @param \PgSql\Result|false $cursor
|
||||
* @param int $result_type
|
||||
* @return array<mixed>|bool
|
||||
*/
|
||||
public function __dbFetchArray($cursor, int $result_type = PGSQL_BOTH);
|
||||
public function __dbFetchArray(\PgSql\Result|false $cursor, int $result_type = PGSQL_BOTH);
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param boolean $assoc_type
|
||||
* @return integer
|
||||
* @param bool $assoc_type
|
||||
* @return int
|
||||
*/
|
||||
public function __dbResultType(bool $assoc_type = true): int;
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param object|resource|bool $cursor
|
||||
* @param \PgSql\Result|false $cursor
|
||||
* @return array<mixed>|bool
|
||||
*/
|
||||
public function __dbFetchAll($cursor);
|
||||
public function __dbFetchAll(\PgSql\Result|false $cursor): array|bool;
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param object|resource|bool $cursor
|
||||
* @return integer
|
||||
* @param \PgSql\Result|false $cursor
|
||||
* @return int
|
||||
*/
|
||||
public function __dbAffectedRows($cursor): int;
|
||||
public function __dbAffectedRows(\PgSql\Result|false $cursor): int;
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param string $query
|
||||
* @param string|null $pk_name
|
||||
* @return string|integer|false
|
||||
* @return string|int|false
|
||||
*/
|
||||
public function __dbInsertId(string $query, ?string $pk_name);
|
||||
public function __dbInsertId(string $query, ?string $pk_name): string|int|false;
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
@@ -148,7 +148,7 @@ interface SqlFunctions
|
||||
* @param string $schema
|
||||
* @return string|bool
|
||||
*/
|
||||
public function __dbPrimaryKey(string $table, string $schema = '');
|
||||
public function __dbPrimaryKey(string $table, string $schema = ''): string|bool;
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
@@ -157,9 +157,9 @@ interface SqlFunctions
|
||||
* @param string $db_user
|
||||
* @param string $db_pass
|
||||
* @param string $db_name
|
||||
* @param integer $db_port
|
||||
* @param int $db_port
|
||||
* @param string $db_ssl
|
||||
* @return object|resource|bool
|
||||
* @return \PgSql\Connection|false
|
||||
*/
|
||||
public function __dbConnect(
|
||||
string $db_host,
|
||||
@@ -168,24 +168,24 @@ interface SqlFunctions
|
||||
string $db_name,
|
||||
int $db_port,
|
||||
string $db_ssl = 'allow'
|
||||
);
|
||||
): \PgSql\Connection|false;
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param object|resource|bool $cursor
|
||||
* @param \PgSql\Result|false $cursor
|
||||
* @return string
|
||||
*/
|
||||
public function __dbPrintError($cursor = false): string;
|
||||
public function __dbPrintError(\PgSql\Result|false $cursor = false): string;
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param string $table
|
||||
* @param boolean $extended
|
||||
* @param bool $extended
|
||||
* @return array<mixed>|bool
|
||||
*/
|
||||
public function __dbMetaData(string $table, $extended = true);
|
||||
public function __dbMetaData(string $table, bool $extended = true): array|bool;
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
@@ -193,7 +193,7 @@ interface SqlFunctions
|
||||
* @param string|int|float|bool $string
|
||||
* @return string
|
||||
*/
|
||||
public function __dbEscapeString($string): string;
|
||||
public function __dbEscapeString(string|int|float|bool $string): string;
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
@@ -201,7 +201,7 @@ interface SqlFunctions
|
||||
* @param string|int|float|bool $string
|
||||
* @return string
|
||||
*/
|
||||
public function __dbEscapeLiteral($string): string;
|
||||
public function __dbEscapeLiteral(string|int|float|bool $string): string;
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
@@ -230,15 +230,15 @@ interface SqlFunctions
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function __dbConnectionBusy(): bool;
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param integer $timeout_seconds
|
||||
* @return boolean
|
||||
* @param int $timeout_seconds
|
||||
* @return bool
|
||||
*/
|
||||
public function __dbConnectionBusySocketWait(int $timeout_seconds = 3): bool;
|
||||
|
||||
@@ -253,8 +253,8 @@ interface SqlFunctions
|
||||
* Undocumented function
|
||||
*
|
||||
* @param string $array_text
|
||||
* @param integer $start
|
||||
* @param integer|null $end
|
||||
* @param int $start
|
||||
* @param int|null $end
|
||||
* @return array<mixed>|null
|
||||
*/
|
||||
public function __dbArrayParse(
|
||||
@@ -275,7 +275,7 @@ interface SqlFunctions
|
||||
* Undocumented function
|
||||
*
|
||||
* @param string $db_schema
|
||||
* @return integer
|
||||
* @return int
|
||||
*/
|
||||
public function __dbSetSchema(string $db_schema): int;
|
||||
|
||||
@@ -290,7 +290,7 @@ interface SqlFunctions
|
||||
* Undocumented function
|
||||
*
|
||||
* @param string $db_encoding
|
||||
* @return integer
|
||||
* @return int
|
||||
*/
|
||||
public function __dbSetEncoding(string $db_encoding): int;
|
||||
|
||||
@@ -51,12 +51,11 @@ namespace CoreLibs\DB\SQL;
|
||||
// as main system. Currently all @var sets are written as object
|
||||
/** @#phan-file-suppress PhanUndeclaredTypeProperty,PhanUndeclaredTypeParameter,PhanUndeclaredTypeReturnType */
|
||||
|
||||
class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
||||
class PgSQL implements Interface\SqlFunctions
|
||||
{
|
||||
/** @var string */
|
||||
private $last_error_query;
|
||||
// NOTE for PHP 8.1 this is no longer a resource
|
||||
/** @var object|resource|bool */ // replace object with PgSql\Connection
|
||||
/** @var \PgSql\Connection|false */
|
||||
private $dbh;
|
||||
|
||||
/**
|
||||
@@ -77,12 +76,12 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
||||
* wrapper for pg_query, catches error and stores it in class var
|
||||
*
|
||||
* @param string $query Query string
|
||||
* @return object|resource|bool query result (PgSql\Result)
|
||||
* @return \PgSql\Result|false query result
|
||||
*/
|
||||
public function __dbQuery(string $query)
|
||||
public function __dbQuery(string $query): \PgSql\Result|false
|
||||
{
|
||||
$this->last_error_query = '';
|
||||
if ($this->dbh === false || is_bool($this->dbh)) {
|
||||
if (is_bool($this->dbh)) {
|
||||
return false;
|
||||
}
|
||||
// read out the query status and save the query if needed
|
||||
@@ -100,12 +99,12 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
||||
*
|
||||
* @param string $query Query string with placeholders $1, ..
|
||||
* @param array<mixed> $params Matching parameters for each placerhold
|
||||
* @return object|resource|bool Query result (PgSql\Result)
|
||||
* @return \PgSql\Result|false Query result
|
||||
*/
|
||||
public function __dbQueryParams(string $query, array $params)
|
||||
public function __dbQueryParams(string $query, array $params): \PgSql\Result|false
|
||||
{
|
||||
$this->last_error_query = '';
|
||||
if ($this->dbh === false || is_bool($this->dbh)) {
|
||||
if (is_bool($this->dbh)) {
|
||||
return false;
|
||||
}
|
||||
// parse query and get all $n entries
|
||||
@@ -126,7 +125,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
||||
*/
|
||||
public function __dbSendQuery(string $query): bool
|
||||
{
|
||||
if ($this->dbh === false || is_bool($this->dbh)) {
|
||||
if (is_bool($this->dbh)) {
|
||||
return false;
|
||||
}
|
||||
$result = pg_send_query($this->dbh, $query);
|
||||
@@ -136,12 +135,12 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
||||
/**
|
||||
* wrapper for pg_get_result
|
||||
*
|
||||
* @return object|resource|bool resource handler or false for error (PgSql\Result)
|
||||
* @return \PgSql\Result|false resource handler or false for error
|
||||
*/
|
||||
public function __dbGetResult()
|
||||
public function __dbGetResult(): \PgSql\Result|false
|
||||
{
|
||||
$this->last_error_query = '';
|
||||
if ($this->dbh === false || is_bool($this->dbh)) {
|
||||
if (is_bool($this->dbh)) {
|
||||
return false;
|
||||
}
|
||||
$result = pg_get_result($this->dbh);
|
||||
@@ -161,7 +160,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
||||
*/
|
||||
public function __dbClose(): void
|
||||
{
|
||||
if ($this->dbh === false || is_bool($this->dbh)) {
|
||||
if (is_bool($this->dbh)) {
|
||||
return;
|
||||
}
|
||||
if (pg_connection_status($this->dbh) === PGSQL_CONNECTION_OK) {
|
||||
@@ -175,12 +174,12 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
||||
*
|
||||
* @param string $name statement name
|
||||
* @param string $query query string
|
||||
* @return object|resource|bool prepare statement handler or
|
||||
* false for error (PgSql\Result)
|
||||
* @return \PgSql\Result|false prepare statement handler or
|
||||
* false for error
|
||||
*/
|
||||
public function __dbPrepare(string $name, string $query)
|
||||
public function __dbPrepare(string $name, string $query): \PgSql\Result|false
|
||||
{
|
||||
if ($this->dbh === false || is_bool($this->dbh)) {
|
||||
if (is_bool($this->dbh)) {
|
||||
return false;
|
||||
}
|
||||
$result = pg_prepare($this->dbh, $name, $query);
|
||||
@@ -195,11 +194,11 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
||||
*
|
||||
* @param string $name statement name
|
||||
* @param array<mixed> $data data array
|
||||
* @return object|resource|bool returns status or false for error (PgSql\Result)
|
||||
* @return \PgSql\Result|false returns status or false for error
|
||||
*/
|
||||
public function __dbExecute(string $name, array $data)
|
||||
public function __dbExecute(string $name, array $data): \PgSql\Result|false
|
||||
{
|
||||
if ($this->dbh === false || is_bool($this->dbh)) {
|
||||
if (is_bool($this->dbh)) {
|
||||
return false;
|
||||
}
|
||||
$result = pg_execute($this->dbh, $name, $data);
|
||||
@@ -212,12 +211,12 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
||||
/**
|
||||
* wrapper for pg_num_rows
|
||||
*
|
||||
* @param object|resource|bool $cursor cursor PgSql\Result (former resource)
|
||||
* @return int number of rows, -1 on error
|
||||
* @param \PgSql\Result|false $cursor cursor
|
||||
* @return int number of rows, -1 on error
|
||||
*/
|
||||
public function __dbNumRows($cursor): int
|
||||
public function __dbNumRows(\PgSql\Result|false $cursor): int
|
||||
{
|
||||
if ($cursor === false || is_bool($cursor)) {
|
||||
if (is_bool($cursor)) {
|
||||
return -1;
|
||||
}
|
||||
return pg_num_rows($cursor);
|
||||
@@ -226,12 +225,12 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
||||
/**
|
||||
* wrapper for pg_num_fields
|
||||
*
|
||||
* @param object|resource|bool $cursor cursor PgSql\Result (former resource)
|
||||
* @return int number for fields in result, -1 on error
|
||||
* @param \PgSql\Result|false $cursor cursor
|
||||
* @return int number for fields in result, -1 on error
|
||||
*/
|
||||
public function __dbNumFields($cursor): int
|
||||
public function __dbNumFields(\PgSql\Result|false $cursor): int
|
||||
{
|
||||
if ($cursor === false || is_bool($cursor)) {
|
||||
if (is_bool($cursor)) {
|
||||
return -1;
|
||||
}
|
||||
return pg_num_fields($cursor);
|
||||
@@ -240,13 +239,13 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
||||
/**
|
||||
* wrapper for pg_field_name
|
||||
*
|
||||
* @param object|resource|bool $cursor cursor PgSql\Result (former resource)
|
||||
* @param int $i field position
|
||||
* @return string|bool name or false on error
|
||||
* @param \PgSql\Result|false $cursor cursor
|
||||
* @param int $i field position
|
||||
* @return string|false name or false on error
|
||||
*/
|
||||
public function __dbFieldName($cursor, int $i)
|
||||
public function __dbFieldName(\PgSql\Result|false $cursor, int $i): string|false
|
||||
{
|
||||
if ($cursor === false || is_bool($cursor)) {
|
||||
if (is_bool($cursor)) {
|
||||
return false;
|
||||
}
|
||||
return pg_field_name($cursor, $i);
|
||||
@@ -256,13 +255,13 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
||||
* wrapper for pg_fetch_array
|
||||
* if through/true false, use __dbResultType(true)
|
||||
*
|
||||
* @param object|resource|bool $cursor cursor PgSql\Result (former resource)
|
||||
* @param int $result_type result type as int number
|
||||
* @return array<mixed>|bool array result data or false on end/error
|
||||
* @param \PgSql\Result|false $cursor cursor
|
||||
* @param int $result_type result type as int number
|
||||
* @return array<mixed>|false array result data or false on end/error
|
||||
*/
|
||||
public function __dbFetchArray($cursor, int $result_type = PGSQL_BOTH)
|
||||
public function __dbFetchArray(\PgSql\Result|false $cursor, int $result_type = PGSQL_BOTH): array|false
|
||||
{
|
||||
if ($cursor === false || is_bool($cursor)) {
|
||||
if (is_bool($cursor)) {
|
||||
return false;
|
||||
}
|
||||
// result type is passed on as is [should be checked]
|
||||
@@ -287,12 +286,12 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
||||
/**
|
||||
* wrapper for pg_fetch_all
|
||||
*
|
||||
* @param object|resource|bool $cursor cursor PgSql\Result (former resource)
|
||||
* @return array<mixed>|bool data array or false for end/error
|
||||
* @param \PgSql\Result|false $cursor cursor
|
||||
* @return array<mixed>|false data array or false for end/error
|
||||
*/
|
||||
public function __dbFetchAll($cursor)
|
||||
public function __dbFetchAll(\PgSql\Result|false $cursor): array|false
|
||||
{
|
||||
if ($cursor === false || is_bool($cursor)) {
|
||||
if (is_bool($cursor)) {
|
||||
return false;
|
||||
}
|
||||
return pg_fetch_all($cursor);
|
||||
@@ -301,12 +300,12 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
||||
/**
|
||||
* wrapper for pg_affected_rows
|
||||
*
|
||||
* @param object|resource|bool $cursor cursor PgSql\Result (former resource)
|
||||
* @return int affected rows, 0 for none, -1 for error
|
||||
* @param \PgSql\Result|false $cursor cursor
|
||||
* @return int affected rows, 0 for none, -1 for error
|
||||
*/
|
||||
public function __dbAffectedRows($cursor): int
|
||||
public function __dbAffectedRows(\PgSql\Result|false $cursor): int
|
||||
{
|
||||
if ($cursor === false || is_bool($cursor)) {
|
||||
if (is_bool($cursor)) {
|
||||
return -1;
|
||||
}
|
||||
return pg_affected_rows($cursor);
|
||||
@@ -323,7 +322,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
||||
* @param string|null $pk_name primary key name, if '' then auto detect
|
||||
* @return string|int|false primary key value
|
||||
*/
|
||||
public function __dbInsertId(string $query, ?string $pk_name)
|
||||
public function __dbInsertId(string $query, ?string $pk_name): string|int|false
|
||||
{
|
||||
// only if an insert has been done
|
||||
if (preg_match("/^insert /i", $query)) {
|
||||
@@ -371,7 +370,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
||||
* @param string $schema optional schema name, '' for default
|
||||
* @return string|bool primary key name or false if not found
|
||||
*/
|
||||
public function __dbPrimaryKey(string $table, string $schema = '')
|
||||
public function __dbPrimaryKey(string $table, string $schema = ''): string|bool
|
||||
{
|
||||
if ($table) {
|
||||
// check if schema set is different from schema given,
|
||||
@@ -426,7 +425,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
||||
* @param string $db_name databse name
|
||||
* @param integer $db_port port (int, 5432 is default)
|
||||
* @param string $db_ssl SSL (allow is default)
|
||||
* @return object|resource|bool db handler PgSql\Connection or false on error
|
||||
* @return \PgSql\Connection|false db handler or false on error
|
||||
*/
|
||||
public function __dbConnect(
|
||||
string $db_host,
|
||||
@@ -435,7 +434,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
||||
string $db_name,
|
||||
int $db_port,
|
||||
string $db_ssl = 'allow'
|
||||
) {
|
||||
): \PgSql\Connection|false {
|
||||
if (empty($db_name)) {
|
||||
return false;
|
||||
}
|
||||
@@ -470,22 +469,22 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
||||
* reads the last error for this cursor and returns
|
||||
* html formatted string with error name
|
||||
*
|
||||
* @param bool|object|resource $cursor cursor PgSql\Result (former resource)
|
||||
* @param \PgSql\Result|false $cursor cursor
|
||||
* or null
|
||||
* @return string error string
|
||||
*/
|
||||
public function __dbPrintError($cursor = false): string
|
||||
public function __dbPrintError(\PgSql\Result|false $cursor = false): string
|
||||
{
|
||||
if ($this->dbh === false || is_bool($this->dbh)) {
|
||||
if (is_bool($this->dbh)) {
|
||||
return '';
|
||||
}
|
||||
// run the query again for the error result here
|
||||
if (($cursor === false || is_bool($cursor)) && $this->last_error_query) {
|
||||
if ((is_bool($cursor)) && $this->last_error_query) {
|
||||
pg_send_query($this->dbh, $this->last_error_query);
|
||||
$this->last_error_query = '';
|
||||
$cursor = pg_get_result($this->dbh);
|
||||
}
|
||||
if ($cursor && !is_bool($cursor) && $error_str = pg_result_error($cursor)) {
|
||||
if ($cursor && $error_str = pg_result_error($cursor)) {
|
||||
return '-PostgreSQL-Error- '
|
||||
. $error_str;
|
||||
} else {
|
||||
@@ -500,9 +499,9 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
||||
* @param bool $extended show extended info (default true)
|
||||
* @return array<mixed>|bool array data for the table info or false on error
|
||||
*/
|
||||
public function __dbMetaData(string $table, $extended = true)
|
||||
public function __dbMetaData(string $table, bool $extended = true): array|bool
|
||||
{
|
||||
if ($this->dbh === false || is_bool($this->dbh)) {
|
||||
if (is_bool($this->dbh)) {
|
||||
return false;
|
||||
}
|
||||
// needs to prefixed with @ or it throws a warning on not existing table
|
||||
@@ -515,9 +514,9 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
||||
* @param string|int|float|bool $string any string/int/float/bool
|
||||
* @return string excaped string
|
||||
*/
|
||||
public function __dbEscapeString($string): string
|
||||
public function __dbEscapeString(string|int|float|bool $string): string
|
||||
{
|
||||
if ($this->dbh === false || is_bool($this->dbh)) {
|
||||
if (is_bool($this->dbh)) {
|
||||
return '';
|
||||
}
|
||||
return pg_escape_string($this->dbh, (string)$string);
|
||||
@@ -531,9 +530,9 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
||||
* @param string|int|float|bool $string any string/int/float/bool
|
||||
* @return string excaped string including quites
|
||||
*/
|
||||
public function __dbEscapeLiteral($string): string
|
||||
public function __dbEscapeLiteral(string|int|float|bool $string): string
|
||||
{
|
||||
if ($this->dbh === false || is_bool($this->dbh)) {
|
||||
if (is_bool($this->dbh)) {
|
||||
return (string)'';
|
||||
}
|
||||
// for phpstan, thinks this is string|false?
|
||||
@@ -549,7 +548,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
||||
*/
|
||||
public function __dbEscapeIdentifier(string $string): string
|
||||
{
|
||||
if ($this->dbh === false || is_bool($this->dbh)) {
|
||||
if (is_bool($this->dbh)) {
|
||||
return '';
|
||||
}
|
||||
// for phpstan, thinks this is string|false?
|
||||
@@ -564,7 +563,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
||||
*/
|
||||
public function __dbEscapeBytea(string $data): string
|
||||
{
|
||||
if ($this->dbh === false || is_bool($this->dbh)) {
|
||||
if (is_bool($this->dbh)) {
|
||||
return '';
|
||||
}
|
||||
return pg_escape_bytea($this->dbh, $data);
|
||||
@@ -584,11 +583,12 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
||||
/**
|
||||
* wrapper for pg_connection_busy
|
||||
*
|
||||
* @return bool True if connection is busy, False if not or no db connection at all
|
||||
* @return bool True if connection is busy
|
||||
* False if not or no db connection at all
|
||||
*/
|
||||
public function __dbConnectionBusy(): bool
|
||||
{
|
||||
if ($this->dbh === false || is_bool($this->dbh)) {
|
||||
if (is_bool($this->dbh)) {
|
||||
return false;
|
||||
}
|
||||
return pg_connection_busy($this->dbh);
|
||||
@@ -597,13 +597,13 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
||||
/**
|
||||
* Experimental wrapper with scoket timetout
|
||||
*
|
||||
* @param integer $timeout_seconds Wait how many seconds on timeout
|
||||
* @return boolean True if connection is busy, or false on
|
||||
* not busy or no db connection at all
|
||||
* @param integer $timeout_seconds Wait how many seconds on timeout
|
||||
* @return bool True if connection is busy, or false on
|
||||
* not busy or no db connection at all
|
||||
*/
|
||||
public function __dbConnectionBusySocketWait(int $timeout_seconds = 3): bool
|
||||
{
|
||||
if ($this->dbh === false || is_bool($this->dbh)) {
|
||||
if (is_bool($this->dbh)) {
|
||||
return false;
|
||||
}
|
||||
$busy = pg_connection_busy($this->dbh);
|
||||
@@ -626,14 +626,14 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
||||
* On default 'version' will be stripped of any space attached info
|
||||
* eg 13.5 (other info) will return only 13.5
|
||||
*
|
||||
* @param string $parameter Parameter string to extract from array
|
||||
* @param boolean $strip If parameter is server strip out on default
|
||||
* Set to false to get original string AS is
|
||||
* @return string The parameter value
|
||||
* @param string $parameter Parameter string to extract from array
|
||||
* @param bool $strip If parameter is server strip out on default
|
||||
* Set to false to get original string AS is
|
||||
* @return string The parameter value
|
||||
*/
|
||||
public function __dbVersionInfo(string $parameter, bool $strip = true): string
|
||||
{
|
||||
if ($this->dbh === false || is_bool($this->dbh)) {
|
||||
if (is_bool($this->dbh)) {
|
||||
return '';
|
||||
}
|
||||
// extract element
|
||||
@@ -655,7 +655,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
||||
*/
|
||||
public function __dbVersionInfoParameterList(): array
|
||||
{
|
||||
if ($this->dbh === false || is_bool($this->dbh)) {
|
||||
if (is_bool($this->dbh)) {
|
||||
return [];
|
||||
}
|
||||
return array_keys(pg_version($this->dbh));
|
||||
@@ -670,7 +670,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
||||
*/
|
||||
public function __dbVersion(): string
|
||||
{
|
||||
if ($this->dbh === false || is_bool($this->dbh)) {
|
||||
if (is_bool($this->dbh)) {
|
||||
return '';
|
||||
}
|
||||
// array has client, protocol, server, we just return server stripped
|
||||
@@ -762,9 +762,9 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
||||
* @param string $parameter Parameter to query
|
||||
* @return string|bool Settings value as string
|
||||
*/
|
||||
public function __dbParameter(string $parameter)
|
||||
public function __dbParameter(string $parameter): string|bool
|
||||
{
|
||||
if ($this->dbh === false || is_bool($this->dbh)) {
|
||||
if (is_bool($this->dbh)) {
|
||||
return false;
|
||||
}
|
||||
if (empty($parameter)) {
|
||||
|
||||
@@ -75,6 +75,11 @@ class FileWriter
|
||||
empty(self::$debug_folder) &&
|
||||
defined('BASE') && defined('LOG')
|
||||
) {
|
||||
/** @deprecated Do not use this anymore, define path with fsetFolder */
|
||||
trigger_error(
|
||||
'fsetFolder must be set first. Setting via LOG_FILE_ID and LOg constants is deprecated',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
self::$debug_folder = BASE . LOG;
|
||||
}
|
||||
if (!is_writeable(self::$debug_folder)) {
|
||||
|
||||
@@ -136,6 +136,11 @@ class Logging
|
||||
$this->log_folder = $this->options['log_folder'] ?? '';
|
||||
// legacy flow, check must set constants
|
||||
if (empty($this->log_folder) && defined('BASE') && defined('LOG')) {
|
||||
/** @deprecated Do not use this anymore, define path on class load */
|
||||
trigger_error(
|
||||
'options: log_folder must be set. Setting via BASE and LOG constants is deprecated',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
// make sure this is writeable, else skip
|
||||
$this->log_folder = BASE . LOG;
|
||||
}
|
||||
@@ -175,6 +180,11 @@ class Logging
|
||||
if (!empty($this->options['file_id'])) {
|
||||
$this->setLogId($this->options['file_id']);
|
||||
} elseif (!empty($GLOBALS['LOG_FILE_ID'])) {
|
||||
/** @deprecated Do not use this anymore, define file_id on class load */
|
||||
trigger_error(
|
||||
'options: file_id must be set. Setting via LOG_FILE_ID global variable is deprecated',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
// legacy flow, should be removed and only set via options
|
||||
$this->setLogId($GLOBALS['LOG_FILE_ID']);
|
||||
// TODO trigger deprecation error
|
||||
@@ -183,6 +193,11 @@ class Logging
|
||||
// E_USER_DEPRECATED
|
||||
// );
|
||||
} elseif (defined('LOG_FILE_ID')) {
|
||||
/** @deprecated Do not use this anymore, define file_id on class load */
|
||||
trigger_error(
|
||||
'options: file_id must be set. Setting via LOG_FILE_ID constant is deprecated',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
// legacy flow, should be removed and only set via options
|
||||
$this->setLogId(LOG_FILE_ID);
|
||||
// trigger deprecation error
|
||||
@@ -236,22 +251,22 @@ class Logging
|
||||
'debug',
|
||||
$this->options['debug_all'] ??
|
||||
// for user login, should be handled outside like globals
|
||||
$_SESSION['DEBUG_ALL'] ??
|
||||
$GLOBALS['DEBUG_ALL'] ??
|
||||
$_SESSION['DEBUG_ALL'] ?? // DEPRECATED
|
||||
$GLOBALS['DEBUG_ALL'] ?? // DEPRECATED
|
||||
false
|
||||
);
|
||||
$this->setLogLevelAll(
|
||||
'print',
|
||||
$this->options['print_all'] ??
|
||||
// for user login, should be handled outside like globals
|
||||
$_SESSION['DEBUG_ALL'] ??
|
||||
$GLOBALS['PRINT_ALL'] ??
|
||||
$_SESSION['DEBUG_ALL'] ?? // DEPRECATED
|
||||
$GLOBALS['PRINT_ALL'] ?? // DEPRECATED
|
||||
false
|
||||
);
|
||||
$this->setLogLevelAll(
|
||||
'echo',
|
||||
$this->options['echo_all'] ??
|
||||
$GLOBALS['ECHO_ALL'] ??
|
||||
$GLOBALS['ECHO_ALL'] ?? // DEPRECATED
|
||||
false
|
||||
);
|
||||
|
||||
@@ -259,32 +274,32 @@ class Logging
|
||||
// add file date is default on
|
||||
$this->setGetLogPrintFileDate(
|
||||
$this->options['print_file_date'] ??
|
||||
$GLOBALS['LOG_PRINT_FILE_DATE'] ??
|
||||
$GLOBALS['LOG_PRINT_FILE_DATE'] ?? // DEPRECATED
|
||||
true
|
||||
);
|
||||
// all other logging file name flags are off
|
||||
$this->setLogPer(
|
||||
'level',
|
||||
$this->options['per_level'] ??
|
||||
$GLOBALS['LOG_PER_LEVEL'] ??
|
||||
$GLOBALS['LOG_PER_LEVEL'] ?? // DEPRECATED
|
||||
false
|
||||
);
|
||||
$this->setLogPer(
|
||||
'class',
|
||||
$this->options['per_class'] ??
|
||||
$GLOBALS['LOG_PER_CLASS'] ??
|
||||
$GLOBALS['LOG_PER_CLASS'] ?? // DEPRECATED
|
||||
false
|
||||
);
|
||||
$this->setLogPer(
|
||||
'page',
|
||||
$this->options['per_page'] ??
|
||||
$GLOBALS['LOG_PER_PAGE'] ??
|
||||
$GLOBALS['LOG_PER_PAGE'] ?? // DEPRECATED
|
||||
false
|
||||
);
|
||||
$this->setLogPer(
|
||||
'run',
|
||||
$this->options['per_run'] ??
|
||||
$GLOBALS['LOG_PER_RUN'] ??
|
||||
$GLOBALS['LOG_PER_RUN'] ?? // DEPRECATED
|
||||
false
|
||||
);
|
||||
// set log per date
|
||||
@@ -413,7 +428,7 @@ class Logging
|
||||
* @param string $name what variable to return
|
||||
* @return mixed can be anything, bool, string, int, array
|
||||
*/
|
||||
public function getSetting(string $name) //:mixed DOES not work with PHP 7.4
|
||||
public function getSetting(string $name): mixed
|
||||
{
|
||||
// for debug purpose only
|
||||
return $this->{$name};
|
||||
@@ -550,9 +565,9 @@ class Logging
|
||||
* @param string $flag on/off
|
||||
* @param string|null $level if not null then check if this array entry is set
|
||||
* else return false
|
||||
* @return bool|array<mixed> if $level is null, return array, else boolean true/false
|
||||
* @return array<mixed>|bool if $level is null, return array, else boolean true/false
|
||||
*/
|
||||
public function getLogLevel(string $type, string $flag, ?string $level = null)
|
||||
public function getLogLevel(string $type, string $flag, ?string $level = null): array|bool
|
||||
{
|
||||
// abort if not valid type
|
||||
if (!in_array($type, ['debug', 'echo', 'print'])) {
|
||||
|
||||
@@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace CoreLibs\Get;
|
||||
|
||||
// NOTE: it is recommended to use gullvek\dotenv instead which is a copy of this
|
||||
|
||||
class DotEnv
|
||||
{
|
||||
/** @var string constant comment char, set to # */
|
||||
@@ -29,11 +31,17 @@ class DotEnv
|
||||
* 1 for file loadable, no data or data already loaded
|
||||
* 2 for file not readable or open failed
|
||||
* 3 for file not found
|
||||
* @deprecated Use composer package gullevek\dotenv instead -> \gullevek\dotenv\DotEnv::readEnvFile(...)
|
||||
*/
|
||||
public static function readEnvFile(
|
||||
string $path = __DIR__,
|
||||
string $env_file = '.env'
|
||||
): int {
|
||||
trigger_error(
|
||||
'\CoreLibs\Get\DotEnv is deprecated in favor for '
|
||||
. 'composer package gullevek\dotenv which is a copy of this',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
// default -1;
|
||||
$status = -1;
|
||||
$env_file_target = $path . DIRECTORY_SEPARATOR . $env_file;
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CoreLibs\Get;
|
||||
|
||||
/**
|
||||
* @deprecated use \CoreLibs\Get\DotEnv instead
|
||||
*/
|
||||
class ReadEnvFile
|
||||
{
|
||||
/**
|
||||
* parses .env file
|
||||
*
|
||||
* Rules for .env file
|
||||
* variable is any alphanumeric string followed by = on the same line
|
||||
* content starts with the first non space part
|
||||
* strings can be contained in "
|
||||
* strings MUST be contained in " if they are multiline
|
||||
* if string starts with " it will match until another " is found
|
||||
* anything AFTER " is ignored
|
||||
* if there are two variables with the same name only the first is used
|
||||
* variables are case sensitive
|
||||
*
|
||||
* @param string $path Folder to file, default is __DIR__
|
||||
* @param string $env_file What file to load, default is .env
|
||||
* @return int -1 other error
|
||||
* 0 for success full load
|
||||
* 1 for file loadable, but no data inside
|
||||
* 2 for file not readable or open failed
|
||||
* 3 for file not found
|
||||
* @deprecated Use \CoreLibs\Get\DotEnv::readEnvFile() instead
|
||||
*/
|
||||
public static function readEnvFile(
|
||||
string $path = __DIR__,
|
||||
string $env_file = '.env'
|
||||
): int {
|
||||
return \CoreLibs\Get\DotEnv::readEnvFile($path, $env_file);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -122,7 +122,7 @@ class GetTextReader
|
||||
* @param bool $enable_cache Enable or disable caching
|
||||
* of strings (default on)
|
||||
*/
|
||||
public function __construct($Reader, bool $enable_cache = true)
|
||||
public function __construct(FileReader|bool $Reader, bool $enable_cache = true)
|
||||
{
|
||||
// If there isn't a StreamReader, turn on short circuit mode.
|
||||
if ((!is_object($Reader) && !$Reader) || (is_object($Reader) && $Reader->error)) {
|
||||
|
||||
@@ -1,127 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* deprecated function calls
|
||||
* Language\Encoding::__mbMimeEncode -> Convert\MimeEncode::__mbMimeEncode
|
||||
* Langauge\Encoding::checkConvertEncoding -> Check\Encoding::checkConvertEncoding
|
||||
* Langauge\Encoding::setErrorChar -> Check\Encoding::setErrorChar
|
||||
* Langauge\Encoding::getErrorChar -> Check\Encoding::getErrorChar
|
||||
* Langauge\Encoding::convertEncoding -> Convert\Encoding::convertEncoding
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CoreLibs\Language;
|
||||
|
||||
class Encoding
|
||||
{
|
||||
/**
|
||||
* wrapper function for mb mime convert
|
||||
* for correct conversion with long strings
|
||||
*
|
||||
* @param string $string string to encode
|
||||
* @param string $encoding target encoding
|
||||
* @param string $line_break default line break is \r\n
|
||||
* @return string encoded string
|
||||
* @deprecated Use \CoreLibs\Convert\MimeEncode::__mbMimeEncode();
|
||||
*/
|
||||
public static function __mbMimeEncode(
|
||||
string $string,
|
||||
string $encoding,
|
||||
string $line_break = "\r\n"
|
||||
): string {
|
||||
return \CoreLibs\Convert\MimeEncode::__mbMimeEncode($string, $encoding, $line_break);
|
||||
}
|
||||
|
||||
/**
|
||||
* set error char
|
||||
*
|
||||
* @param string|int|null $string The character to use to represent
|
||||
* error chars
|
||||
* "long" for long, "none" for none
|
||||
* or a valid code point in int
|
||||
* like 0x2234 (8756, ∴)
|
||||
* default character is ? (63)
|
||||
* if null is set then "none"
|
||||
* @return void
|
||||
* @deprecated Use \CoreLibs\Check\Encoding::setErrorChar();
|
||||
*/
|
||||
public static function setErrorChar($string): void
|
||||
{
|
||||
\CoreLibs\Check\Encoding::setErrorChar($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* get the current set error character
|
||||
*
|
||||
* @param bool $return_substitute_func if set to true return the set
|
||||
* character from the php function
|
||||
* directly
|
||||
* @return string|int Set error character
|
||||
* @deprecated Use \CoreLibs\Check\Encoding::getErrorChar();
|
||||
*/
|
||||
public static function getErrorChar(bool $return_substitute_func = false)
|
||||
{
|
||||
return \CoreLibs\Check\Encoding::getErrorChar($return_substitute_func);
|
||||
}
|
||||
|
||||
/**
|
||||
* test if a string can be safely convert between encodings.
|
||||
* mostly utf8 to shift jis
|
||||
* the default compare has a possibility of failure, especially with windows
|
||||
* it is recommended to the following in the script which uses this method:
|
||||
* mb_substitute_character(0x2234);
|
||||
* $class->mb_error_char = '∴';
|
||||
* if check to Shift JIS
|
||||
* if check to ISO-2022-JP
|
||||
* if check to ISO-2022-JP-MS
|
||||
* set three dots (∴) as wrong character for correct convert error detect
|
||||
* (this char is used, because it is one of the least used ones)
|
||||
*
|
||||
* @param string $string string to test
|
||||
* @param string $from_encoding encoding of string to test
|
||||
* @param string $to_encoding target encoding
|
||||
* @return bool|array<string> false if no error or
|
||||
* array with failed characters
|
||||
* @deprecated Use \CoreLibs\Check\Encoding::checkConvertEncoding();
|
||||
*/
|
||||
public static function checkConvertEncoding(
|
||||
string $string,
|
||||
string $from_encoding,
|
||||
string $to_encoding
|
||||
) {
|
||||
return \CoreLibs\Check\Encoding::checkConvertEncoding($string, $from_encoding, $to_encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* detects the source encoding of the string and if doesn't match
|
||||
* to the given target encoding it convert is
|
||||
* if source encoding is set and auto check is true (default) a second
|
||||
* check is done so that the source string encoding actually matches
|
||||
* will be skipped if source encoding detection is ascii
|
||||
*
|
||||
* @param string $string string to convert
|
||||
* @param string $to_encoding target encoding
|
||||
* @param string $source_encoding optional source encoding, will try to auto detect
|
||||
* @param bool $auto_check default true, if source encoding is set
|
||||
* check that the source is actually matching
|
||||
* to what we sav the source is
|
||||
* @return string encoding converted string
|
||||
* @deprecated Use \CoreLibs\Convert\Encoding::convertEncoding();
|
||||
*/
|
||||
public static function convertEncoding(
|
||||
string $string,
|
||||
string $to_encoding,
|
||||
string $source_encoding = '',
|
||||
bool $auto_check = true
|
||||
): string {
|
||||
return \CoreLibs\Convert\Encoding::convertEncoding(
|
||||
$string,
|
||||
$to_encoding,
|
||||
$source_encoding,
|
||||
$auto_check
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -14,12 +14,14 @@ class GetLocale
|
||||
/**
|
||||
* returns locale, lang, domain, encoding, path
|
||||
* from either parameter set or from sessions/config variables
|
||||
* NOTE: named constant usage is deprecated and will be removed in future
|
||||
*
|
||||
* @param string|null $locale override auto detect
|
||||
* @param string|null $domain override domain
|
||||
* @param string|null $encoding override encoding
|
||||
* @param string|null $path override path
|
||||
* @return array<string,string> locale, domain, encoding, path
|
||||
* @deprecated use GetLocale::setLocaleSession(...) instead
|
||||
*/
|
||||
public static function setLocale(
|
||||
?string $locale = null,
|
||||
@@ -27,6 +29,10 @@ class GetLocale
|
||||
?string $encoding = null,
|
||||
?string $path = null
|
||||
): array {
|
||||
trigger_error(
|
||||
'Use \CoreLibs\Language\GetLocale::setLocaleSession(...) instead',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
// locale must match at least basic rules
|
||||
if (
|
||||
empty($locale) ||
|
||||
@@ -36,6 +42,10 @@ class GetLocale
|
||||
// parse from session (logged in)
|
||||
$locale = $_SESSION['DEFAULT_LOCALE'];
|
||||
} else {
|
||||
trigger_error(
|
||||
'setLocale: Unset $locale or unset SESSION locale is deprecated',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
// else parse from site locale
|
||||
$locale = defined('SITE_LOCALE') && !empty(SITE_LOCALE) ?
|
||||
SITE_LOCALE :
|
||||
@@ -50,8 +60,16 @@ class GetLocale
|
||||
empty($domain) ||
|
||||
!preg_match("/^\w+$/", $domain)
|
||||
) {
|
||||
// if no domain is set, fall back to content path
|
||||
$domain = str_replace('/', '', CONTENT_PATH);
|
||||
if (!empty($_SESSION['DEFAULT_DOMAIN'])) {
|
||||
$domain = $_SESSION['DEFAULT_DOMAIN'];
|
||||
} else {
|
||||
trigger_error(
|
||||
'setLocale: Unset $domain is deprecated',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
// if no domain is set, fall back to content path
|
||||
$domain = str_replace(DIRECTORY_SEPARATOR, '', CONTENT_PATH);
|
||||
}
|
||||
}
|
||||
// check that override encoding matches locale encoding
|
||||
// if locale encoding is set
|
||||
@@ -71,6 +89,10 @@ class GetLocale
|
||||
// else set from session
|
||||
$encoding = $_SESSION['DEFAULT_CHARSET'];
|
||||
} else {
|
||||
trigger_error(
|
||||
'setLocale: Short $locale with unset $encoding or unset SESSION encoding is deprecated',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
// else set from site encoding
|
||||
$encoding = defined('SITE_ENCODING') && !empty(SITE_ENCODING) ?
|
||||
SITE_ENCODING :
|
||||
@@ -85,7 +107,15 @@ class GetLocale
|
||||
empty($path) ||
|
||||
!is_dir($path)
|
||||
) {
|
||||
$path = BASE . INCLUDES . LOCALE;
|
||||
if (!empty($_SESSION['LOCALE_PATH'])) {
|
||||
$path = $_SESSION['LOCALE_PATH'];
|
||||
} else {
|
||||
trigger_error(
|
||||
'setLocale: Unset $path is deprecated',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
$path = BASE . INCLUDES . LOCALE;
|
||||
}
|
||||
}
|
||||
// extract lang & country from locale string, else set to en
|
||||
if (
|
||||
@@ -112,6 +142,113 @@ class GetLocale
|
||||
'path' => $path,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* NOTE: For getting the login info via login class use ->loginGetLocale()
|
||||
*
|
||||
* Set locale from session or from override parameters
|
||||
* This is the prefered version to setLocale
|
||||
* It usese the following SESSION VARIABLES
|
||||
* DEFAULT_LOCALE
|
||||
* DEFAULT_DOMAIN
|
||||
* DEFAULT_CHARSET (should be set from DEFAULT_LOCALE)
|
||||
* LOCALE_PATH
|
||||
* in the return array, null set invalid information
|
||||
*
|
||||
* @param string $locale override locale
|
||||
* @param string $domain override domain
|
||||
* @param string $encoding override encoding
|
||||
* @param string $path override path
|
||||
* @return array<string,string> locale, domain, encoding, path
|
||||
* @return array<string,string|null> Return list of set locale information
|
||||
* @deprecated This version will be removed in a future version use ACL\Login->loginGetLocale() instead
|
||||
*/
|
||||
public static function setLocaleFromSession(
|
||||
string $locale,
|
||||
string $domain,
|
||||
string $encoding,
|
||||
string $path
|
||||
): array {
|
||||
// locale must match at least basic rules
|
||||
if (
|
||||
!empty($_SESSION['DEFAULT_LOCALE']) &&
|
||||
preg_match("/^[-A-Za-z0-9_.@]+$/", $_SESSION['DEFAULT_LOCALE'])
|
||||
) {
|
||||
// parse from session (logged in)
|
||||
$locale = $_SESSION['DEFAULT_LOCALE'];
|
||||
} elseif (
|
||||
empty($locale) ||
|
||||
!preg_match("/^[-A-Za-z0-9_.@]+$/", $locale)
|
||||
) {
|
||||
$locale = null;
|
||||
}
|
||||
// if domain is set, must be alphanumeric, if not unset
|
||||
if (
|
||||
!empty($_SESSION['DEFAULT_DOMAIN']) &&
|
||||
preg_match("/^\w+$/", $_SESSION['DEFAULT_DOMAIN'])
|
||||
) {
|
||||
$domain = $_SESSION['DEFAULT_DOMAIN'];
|
||||
} elseif (
|
||||
empty($domain) ||
|
||||
!preg_match("/^\w+$/", $domain)
|
||||
) {
|
||||
$domain = null;
|
||||
}
|
||||
// check that override encoding matches locale encoding
|
||||
// if locale encoding is set
|
||||
preg_match('/(?:\\.(?P<charset>[-A-Za-z0-9_]+))/', $locale ?? '', $matches);
|
||||
$locale_encoding = $matches['charset'] ?? null;
|
||||
if (!empty($locale_encoding)) {
|
||||
$encoding = strtoupper($locale_encoding);
|
||||
} elseif (
|
||||
!empty($_SESSION['DEFAULT_CHARSET']) &&
|
||||
preg_match("/^[-A-Za-z0-9_]+$/", $_SESSION['DEFAULT_CHARSET'])
|
||||
) {
|
||||
$encoding = $_SESSION['DEFAULT_CHARSET'];
|
||||
} elseif (
|
||||
empty($encoding) ||
|
||||
// not valid encoding
|
||||
!preg_match("/^[-A-Za-z0-9_]+$/", $encoding)
|
||||
) {
|
||||
$encoding = null;
|
||||
}
|
||||
// path checks if set, if not valid path unset to default BASE path
|
||||
if (
|
||||
!empty($_SESSION['LOCALE_PATH']) &&
|
||||
is_dir($_SESSION['LOCALE_PATH'])
|
||||
) {
|
||||
$path = $_SESSION['LOCALE_PATH'];
|
||||
} elseif (
|
||||
empty($path) ||
|
||||
!is_dir($path)
|
||||
) {
|
||||
$path = null;
|
||||
}
|
||||
// extract lang & country from locale string, else set to en
|
||||
if (
|
||||
preg_match(
|
||||
// lang
|
||||
'/^(?P<lang>[a-z]{2,3})'
|
||||
// country code
|
||||
. '(?:_(?P<country>[A-Z]{2}))?/',
|
||||
$locale ?? '',
|
||||
$matches
|
||||
)
|
||||
) {
|
||||
$lang = ($matches['lang'] ?? 'en')
|
||||
// add country only if set
|
||||
. (!empty($matches['country']) ? '_' . $matches['country'] : '');
|
||||
} else {
|
||||
$lang = null;
|
||||
}
|
||||
return [
|
||||
'locale' => $locale,
|
||||
'lang' => $lang,
|
||||
'domain' => $domain,
|
||||
'encoding' => $encoding,
|
||||
'path' => $path,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
|
||||
@@ -32,12 +32,18 @@ use CoreLibs\Language\Core\GetTextReader;
|
||||
|
||||
class L10n
|
||||
{
|
||||
/** @var string the default fallback encoding if nothing is set */
|
||||
public const DEFAULT_CHARSET = 'UTF-8';
|
||||
/** @var string the current locale */
|
||||
private $locale = '';
|
||||
/** @var string the SET locale as WHERE the domain file is */
|
||||
private $locale_set = '';
|
||||
/** @var string the default selected/active domain */
|
||||
private $domain = '';
|
||||
/** @var string encoding, as from locale or set from outside */
|
||||
private $override_encoding = self::DEFAULT_CHARSET;
|
||||
/** @var string encoding set during the parse Locale */
|
||||
private $encoding = '';
|
||||
/** @var array<string,array<string,GetTextReader>> locale > domain = translator */
|
||||
private $domains = [];
|
||||
/** @var array<string,string> bound paths for domains */
|
||||
@@ -71,26 +77,42 @@ class L10n
|
||||
* if locale is not empty will load translation
|
||||
* else getTranslator needs to be called
|
||||
*
|
||||
* @param string $locale language name, default empty string
|
||||
* will return self instance
|
||||
* @param string $domain override CONTENT_PATH . $encoding name for mo file
|
||||
* @param string $path path, if empty fallback on default internal path
|
||||
* @param string $locale language name, default empty string
|
||||
* will return self instance
|
||||
* @param string $domain override CONTENT_PATH . $encoding name for mo file
|
||||
* @param string $path path, if empty fallback on default internal path
|
||||
* @param string $encoding Optional encoding, should be set if locale has
|
||||
* no encoding, defaults to UTF-8
|
||||
*/
|
||||
public function __construct(
|
||||
string $locale = '',
|
||||
string $domain = '',
|
||||
string $path = ''
|
||||
string $path = '',
|
||||
string $encoding = ''
|
||||
) {
|
||||
// auto load language only if at least locale and domain is set
|
||||
if (!empty($locale) && !empty($domain)) {
|
||||
// New: path must be set too, or we fall through
|
||||
if (!empty($locale) && !empty($domain) && empty($path)) {
|
||||
/** @deprecated if locale and domain are set, path must be set too */
|
||||
trigger_error(
|
||||
'Empty path parameter is no longer allowed if locale and domain are set',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
}
|
||||
if (!empty($locale) && !empty($domain) && !empty($path)) {
|
||||
// check hack if domain and path is switched
|
||||
// Note this can be removed in future versions
|
||||
if (strstr($domain, DIRECTORY_SEPARATOR) !== false) {
|
||||
/** @deprecated domain must be 2nd and path must be third parameter */
|
||||
trigger_error(
|
||||
'L10n constructor parameter switch is no longer supported. domain is 2nd, path is 3rd parameter',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
$_domain = $path;
|
||||
$path = $domain;
|
||||
$domain = $_domain;
|
||||
}
|
||||
$this->getTranslator($locale, $domain, $path);
|
||||
$this->getTranslator($locale, $domain, $path, $encoding);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,15 +144,17 @@ class L10n
|
||||
/**
|
||||
* loads the mo file base on path, locale and domain set
|
||||
*
|
||||
* @param string $locale language name (optional), fallback is en
|
||||
* @param string $domain override CONTENT_PATH . $encoding name for mo file
|
||||
* @param string $path path, if empty fallback on default internal path
|
||||
* @param string $locale language name, if not set, try previous set
|
||||
* @param string $domain set name for mo file, if not set, try previous set
|
||||
* @param string $path path, if not set try to get from paths array, else self
|
||||
* @param string $override_encoding if locale does not env encoding set, use this one
|
||||
* @return GetTextReader the main gettext reader object
|
||||
*/
|
||||
public function getTranslator(
|
||||
string $locale = '',
|
||||
string $domain = '',
|
||||
string $path = ''
|
||||
string $path = '',
|
||||
string $override_encoding = '',
|
||||
): GetTextReader {
|
||||
// set local if not from parameter
|
||||
if (empty($locale)) {
|
||||
@@ -140,11 +164,16 @@ class L10n
|
||||
if (empty($domain)) {
|
||||
$domain = $this->domain;
|
||||
}
|
||||
// override encoding for unset
|
||||
if (!empty($override_encoding)) {
|
||||
$this->override_encoding = $override_encoding;
|
||||
}
|
||||
// store old settings
|
||||
$old_mofile = $this->mofile;
|
||||
$old_lang = $this->locale;
|
||||
$old_lang_set = $this->locale_set;
|
||||
$old_domain = $this->domain;
|
||||
$old_encoding = $this->encoding;
|
||||
$old_base_locale_path = $this->base_locale_path;
|
||||
$old_base_content_path = $this->base_content_path;
|
||||
|
||||
@@ -160,6 +189,11 @@ class L10n
|
||||
} elseif (
|
||||
defined('BASE') && defined('INCLUDES') && defined('LOCALE')
|
||||
) {
|
||||
/** @deprecated Do not use this anymore, define path on class load */
|
||||
trigger_error(
|
||||
'parameter $path must be set. Setting via BASE, INCLUDES and LOCALE constants is deprecated',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
// set fallback base path if constant set
|
||||
$this->base_locale_path = BASE . INCLUDES . LOCALE;
|
||||
} else {
|
||||
@@ -168,6 +202,7 @@ class L10n
|
||||
// now we loop over lang compositions to get the base path
|
||||
// then we check
|
||||
$locales = $this->listLocales($locale);
|
||||
$encoding = $this->getEncodingFromLocale($locale);
|
||||
foreach ($locales as $_locale) {
|
||||
$this->base_content_path = $_locale . DIRECTORY_SEPARATOR
|
||||
. 'LC_MESSAGES' . DIRECTORY_SEPARATOR;
|
||||
@@ -184,6 +219,7 @@ class L10n
|
||||
if (is_readable($this->mofile)) {
|
||||
// locale and domain current wanted
|
||||
$this->locale = $locale;
|
||||
$this->encoding = $encoding;
|
||||
$this->domain = $domain;
|
||||
// set empty domains path with current locale
|
||||
if (empty($this->domains[$locale])) {
|
||||
@@ -207,6 +243,7 @@ class L10n
|
||||
$this->mofile = $old_mofile;
|
||||
$this->locale = $old_lang;
|
||||
$this->locale_set = $old_lang_set;
|
||||
$this->encoding = $old_encoding;
|
||||
$this->domain = $old_domain;
|
||||
$this->base_locale_path = $old_base_locale_path;
|
||||
$this->base_content_path = $old_base_content_path;
|
||||
@@ -240,6 +277,40 @@ class L10n
|
||||
return $this->l10n;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract encoding from Locale, or fallback to override one if not set
|
||||
*
|
||||
* @param string $locale
|
||||
* @return string
|
||||
*/
|
||||
private function getEncodingFromLocale(string $locale): string
|
||||
{
|
||||
// extract charset from $locale
|
||||
// if not set get override encoding
|
||||
preg_match('/(?:\\.(?P<charset>[-A-Za-z0-9_]+))/', $locale, $matches);
|
||||
return $matches['charset'] ?? $this->override_encoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the local as array same to the GetLocale::setLocale return
|
||||
* This does not set from outside, but only what is set in the l10n class
|
||||
*
|
||||
* @return array{locale: string, lang: string, lang_short: string, domain: string, encoding: string, path: string}
|
||||
*/
|
||||
public function getLocaleAsArray(): array
|
||||
{
|
||||
$locale = L10n::parseLocale($this->getLocale());
|
||||
return [
|
||||
'locale' => $this->getLocale(),
|
||||
'lang' => ($locale['lang'] ?? '')
|
||||
. (!empty($locale['country']) ? '_' . $locale['country'] : ''),
|
||||
'lang_short' => $locale['lang'] ?? '',
|
||||
'domain' => $this->getDomain(),
|
||||
'encoding' => $this->getEncoding(),
|
||||
'path' => $this->getBaseLocalePath(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* parse the locale string for further processing
|
||||
*
|
||||
@@ -478,6 +549,37 @@ class L10n
|
||||
return $this->locale_set;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set override encoding
|
||||
*
|
||||
* @param string $encoding
|
||||
* @return void
|
||||
*/
|
||||
public function setOverrideEncoding(string $encoding): void
|
||||
{
|
||||
$this->override_encoding = $encoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* return current set override encoding
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getOverrideEncoding(): string
|
||||
{
|
||||
return $this->override_encoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Current set encoding
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEncoding(): string
|
||||
{
|
||||
return $this->encoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* get current set language
|
||||
*
|
||||
|
||||
@@ -13,27 +13,27 @@ class Elements
|
||||
/**
|
||||
* print the date/time drop downs, used in any queue/send/insert at date/time place
|
||||
*
|
||||
* @param int $year year YYYY
|
||||
* @param int $month month m
|
||||
* @param int $day day d
|
||||
* @param int $hour hour H
|
||||
* @param int $min min i
|
||||
* @param string $suffix additional info printed after the date time
|
||||
* variable in the drop down
|
||||
* also used for ID in the on change JS call
|
||||
* @param int $min_steps default is 1 (minute), can set to anything,
|
||||
* is used as sum up from 0
|
||||
* @param bool $name_pos_back default false, if set to true,
|
||||
* the name will be printend after the drop down
|
||||
* and not before the drop down
|
||||
* @return string HTML formated strings for drop down lists of date and time
|
||||
* @param int|string $year year YYYY
|
||||
* @param int|string $month month m
|
||||
* @param int|string $day day d
|
||||
* @param int|string $hour hour H
|
||||
* @param int|string $min min i
|
||||
* @param string $suffix additional info printed after the date time
|
||||
* variable in the drop down
|
||||
* also used for ID in the on change JS call
|
||||
* @param int $min_steps default is 1 (minute), can set to anything,
|
||||
* is used as sum up from 0
|
||||
* @param bool $name_pos_back default false, if set to true,
|
||||
* the name will be printend after the drop down
|
||||
* and not before the drop down
|
||||
* @return string HTML formated strings for drop down lists of date and time
|
||||
*/
|
||||
public static function printDateTime(
|
||||
$year,
|
||||
$month,
|
||||
$day,
|
||||
$hour,
|
||||
$min,
|
||||
int|string $year,
|
||||
int|string $month,
|
||||
int|string $day,
|
||||
int|string $hour,
|
||||
int|string $min,
|
||||
string $suffix = '',
|
||||
int $min_steps = 1,
|
||||
bool $name_pos_back = false
|
||||
|
||||
@@ -277,6 +277,8 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
private $acl_admin = 0;
|
||||
/** @var array<mixed> */
|
||||
public $security_level;
|
||||
/** @var array<string,mixed> Login ACL */
|
||||
public $login_acl = [];
|
||||
// layout publics
|
||||
/** @var int */
|
||||
public $table_width;
|
||||
@@ -305,50 +307,42 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
/**
|
||||
* construct form generator
|
||||
*
|
||||
* @param array<mixed> $db_config db config array, mandatory
|
||||
* @param \CoreLibs\Debug\Logging|null $log Logging class, null auto set
|
||||
* @param \CoreLibs\Language\L10n|null $l10n l10n language class, null auto set
|
||||
* @param array<string,string>|null $locale locale array from ::setLocale,
|
||||
* null auto set
|
||||
* @param array<mixed>|null $table_arrays Override table array data
|
||||
* instead of try to load from
|
||||
* include file
|
||||
* @throws \Exception 1: No table_arrays set/no class found for my page name
|
||||
* @param array<mixed> $db_config db config array, mandatory
|
||||
* @param \CoreLibs\Debug\Logging $log Logging class
|
||||
* @param \CoreLibs\Language\L10n $l10n l10n language class
|
||||
* @param array<string,mixed> $login_acl Login ACL array,
|
||||
* at least base/admin should be set
|
||||
* @param array<mixed>|null $table_arrays Override table array data
|
||||
* instead of try to load from
|
||||
* include file
|
||||
* @throws \Exception 1: No table_arrays set/no class found for my page name
|
||||
*/
|
||||
public function __construct(
|
||||
array $db_config,
|
||||
?\CoreLibs\Debug\Logging $log = null,
|
||||
?\CoreLibs\Language\L10n $l10n = null,
|
||||
?array $locale = null,
|
||||
\CoreLibs\Debug\Logging $log,
|
||||
\CoreLibs\Language\L10n $l10n,
|
||||
array $login_acl,
|
||||
?array $table_arrays = null,
|
||||
) {
|
||||
// init logger if not set
|
||||
$this->log = $log ?? new \CoreLibs\Debug\Logging();
|
||||
$this->log = $log;
|
||||
// don't log per class
|
||||
$this->log->setLogPer('class', false);
|
||||
// if pass on locale is null
|
||||
if ($locale === null) {
|
||||
$locale = \CoreLibs\Language\GetLocale::setLocale();
|
||||
}
|
||||
// init the language class
|
||||
$this->l = $l10n ?? new \CoreLibs\Language\L10n(
|
||||
$locale['locale'],
|
||||
$locale['domain'],
|
||||
$locale['path'],
|
||||
);
|
||||
// legacy lang vars set
|
||||
$this->l = $l10n;
|
||||
// parse and read, legacy stuff
|
||||
$locale = $this->l->getLocaleAsArray();
|
||||
$this->encoding = $locale['encoding'];
|
||||
$this->lang = $locale['lang'];
|
||||
// get first part from lang
|
||||
$this->lang_short = explode('_', $locale['lang'])[0];
|
||||
$this->domain = $this->l->getDomain();
|
||||
$this->lang_dir = $this->l->getBaseLocalePath();
|
||||
$this->lang_short = $locale['lang_short'];
|
||||
$this->domain = $locale['domain'];
|
||||
$this->lang_dir = $locale['path'];
|
||||
// load config array
|
||||
// get table array definitions for current page name
|
||||
|
||||
$this->login_acl = $login_acl;
|
||||
// security settings
|
||||
$this->base_acl_level = (int)$_SESSION['BASE_ACL_LEVEL'];
|
||||
$this->acl_admin = (int)$_SESSION['ADMIN'];
|
||||
$this->base_acl_level = $this->login_acl['base'] ?? 0;
|
||||
$this->acl_admin = $this->login_acl['admin'] ?? 0;
|
||||
|
||||
// replace any non valid variable names and set my page name
|
||||
$this->my_page_name = str_replace(
|
||||
@@ -366,7 +360,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
$config_array = $table_arrays[System::getPageName(1)];
|
||||
} else {
|
||||
// primary try to load the class
|
||||
/** @var \CoreLibs\Output\Form\TableArraysInterface|false $content_class */
|
||||
/** @var TableArrays\Interface\TableArraysInterface|false $content_class */
|
||||
$content_class = $this->loadTableArray();
|
||||
if (is_object($content_class)) {
|
||||
$config_array = $content_class->setTableArray();
|
||||
@@ -386,7 +380,6 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
$this->base_acl_level,
|
||||
$this->acl_admin
|
||||
);
|
||||
// $this->log->debug('SESSION FORM', 'sessin: ' . $this->log->prAr($_SESSION));
|
||||
// here should be a check if the config_array is correct ...
|
||||
if (isset($config_array['show_fields']) && is_array($config_array['show_fields'])) {
|
||||
$this->field_array = $config_array['show_fields'];
|
||||
@@ -468,9 +461,9 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
/**
|
||||
* load table array class based on my page name converted to camel case
|
||||
* class files are in \TableArrays folder in \Output\Form
|
||||
* @return object|bool Return class object or false on failure
|
||||
* @return TableArrays\Interface\TableArraysInterface|false Return class object or false on failure
|
||||
*/
|
||||
private function loadTableArray()
|
||||
private function loadTableArray(): TableArrays\Interface\TableArraysInterface|false
|
||||
{
|
||||
// note: it schould be Schemas but an original type made it to this
|
||||
// this file is kept for the old usage, new one should be EditSchemas
|
||||
@@ -489,7 +482,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
$page_name_camel_case
|
||||
);
|
||||
try {
|
||||
/** @var \CoreLibs\Output\Form\TableArraysInterface|false $class */
|
||||
/** @var TableArrays\Interface\TableArraysInterface|false $class */
|
||||
$class = new $class_string($this);
|
||||
} catch (\Throwable $t) {
|
||||
$this->log->debug('CLASS LOAD', 'Failed loading: ' . $class_string . ' => ' . $t->getMessage());
|
||||
@@ -651,7 +644,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
$this->base_acl_level >= $this->security_level['new']
|
||||
) {
|
||||
if ($this->really_new == 'yes') {
|
||||
$this->formUnsetTablearray();
|
||||
$this->formUnsetTableArray();
|
||||
} else {
|
||||
$this->msg .= $this->l->__('You have to select the <b>Checkbox for New</b>!<br>');
|
||||
$this->error = 2;
|
||||
@@ -731,9 +724,6 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
empty($this->table_array['protected']['value']) &&
|
||||
!$this->error
|
||||
) {
|
||||
if (!is_array($element_list)) {
|
||||
$element_list = [];
|
||||
}
|
||||
for ($i = 0, $i_max = count($element_list); $i < $i_max; $i++) {
|
||||
// $this->log->debug('form_error', 'Array: '
|
||||
// . is_array($this->element_list[$element_list[$i]]['read_data']) . ' | '
|
||||
@@ -2294,11 +2284,9 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
}
|
||||
}
|
||||
}
|
||||
if (is_array($hidden_array)) {
|
||||
reset($hidden_array);
|
||||
foreach ($hidden_array as $key => $value) {
|
||||
$hidden[] = ['key' => $key, 'value' => $value];
|
||||
}
|
||||
reset($hidden_array);
|
||||
foreach ($hidden_array as $key => $value) {
|
||||
$hidden[] = ['key' => $key, 'value' => $value];
|
||||
}
|
||||
return $hidden;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace CoreLibs\Output\Form\TableArrays;
|
||||
|
||||
class EditAccess implements \CoreLibs\Output\Form\TableArraysInterface
|
||||
class EditAccess implements Interface\TableArraysInterface
|
||||
{
|
||||
/** @var \CoreLibs\Output\Form\Generate */
|
||||
private $form;
|
||||
@@ -87,7 +87,9 @@ class EditAccess implements \CoreLibs\Output\Form\TableArraysInterface
|
||||
],
|
||||
],
|
||||
'table_name' => 'edit_access',
|
||||
"load_query" => "SELECT edit_access_id, name FROM edit_access ORDER BY name",
|
||||
"load_query" => "SELECT edit_access_id, name "
|
||||
. "FROM edit_access "
|
||||
. "ORDER BY name",
|
||||
'show_fields' => [
|
||||
[
|
||||
'name' => 'name'
|
||||
|
||||
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace CoreLibs\Output\Form\TableArrays;
|
||||
|
||||
class EditGroups implements \CoreLibs\Output\Form\TableArraysInterface
|
||||
class EditGroups implements Interface\TableArraysInterface
|
||||
{
|
||||
/** @var \CoreLibs\Output\Form\Generate */
|
||||
private $form;
|
||||
@@ -55,14 +55,19 @@ class EditGroups implements \CoreLibs\Output\Form\TableArraysInterface
|
||||
'mandatory' => 1,
|
||||
'int' => 1,
|
||||
'type' => 'drop_down_db',
|
||||
'query' => "SELECT edit_access_right_id, name FROM edit_access_right ORDER BY level"
|
||||
'query' => "SELECT edit_access_right_id, name "
|
||||
. "FROM edit_access_right "
|
||||
. "ORDER BY level"
|
||||
],
|
||||
'edit_scheme_id' => [
|
||||
'value' => $_POST['edit_scheme_id'] ?? '',
|
||||
'output_name' => 'Group Scheme',
|
||||
'int_null' => 1,
|
||||
'type' => 'drop_down_db',
|
||||
'query' => "SELECT edit_scheme_id, name FROM edit_scheme WHERE enabled = 1 ORDER BY name"
|
||||
'query' => "SELECT edit_scheme_id, name "
|
||||
. "FROM edit_scheme "
|
||||
. "WHERE enabled = 1 "
|
||||
. "ORDER BY name"
|
||||
],
|
||||
'additional_acl' => [
|
||||
'value' => $_POST['additional_acl'] ?? '',
|
||||
@@ -73,7 +78,9 @@ class EditGroups implements \CoreLibs\Output\Form\TableArraysInterface
|
||||
'cols' => 60
|
||||
],
|
||||
],
|
||||
'load_query' => "SELECT edit_group_id, name, enabled FROM edit_group ORDER BY name",
|
||||
'load_query' => "SELECT edit_group_id, name, enabled "
|
||||
. "FROM edit_group "
|
||||
. "ORDER BY name",
|
||||
'table_name' => 'edit_group',
|
||||
'show_fields' => [
|
||||
[
|
||||
@@ -115,7 +122,9 @@ class EditGroups implements \CoreLibs\Output\Form\TableArraysInterface
|
||||
'output_name' => 'Access Level',
|
||||
'int' => 1,
|
||||
'preset' => 1, // first of the select
|
||||
'query' => "SELECT edit_access_right_id, name FROM edit_access_right ORDER BY level"
|
||||
'query' => "SELECT edit_access_right_id, name "
|
||||
. "FROM edit_access_right "
|
||||
. "ORDER BY level"
|
||||
],
|
||||
'edit_page_id' => [
|
||||
'int' => 1,
|
||||
|
||||
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace CoreLibs\Output\Form\TableArrays;
|
||||
|
||||
class EditLanguages implements \CoreLibs\Output\Form\TableArraysInterface
|
||||
class EditLanguages implements Interface\TableArraysInterface
|
||||
{
|
||||
/** @var \CoreLibs\Output\Form\Generate */
|
||||
private $form;
|
||||
|
||||
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace CoreLibs\Output\Form\TableArrays;
|
||||
|
||||
class EditMenuGroup implements \CoreLibs\Output\Form\TableArraysInterface
|
||||
class EditMenuGroup implements Interface\TableArraysInterface
|
||||
{
|
||||
/** @var \CoreLibs\Output\Form\Generate */
|
||||
private $form;
|
||||
@@ -55,7 +55,9 @@ class EditMenuGroup implements \CoreLibs\Output\Form\TableArraysInterface
|
||||
],
|
||||
],
|
||||
'table_name' => 'edit_menu_group',
|
||||
'load_query' => "SELECT edit_menu_group_id, name FROM edit_menu_group ORDER BY name",
|
||||
'load_query' => "SELECT edit_menu_group_id, name "
|
||||
. "FROM edit_menu_group "
|
||||
. "ORDER BY name",
|
||||
'show_fields' => [
|
||||
[
|
||||
'name' => 'name'
|
||||
|
||||
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace CoreLibs\Output\Form\TableArrays;
|
||||
|
||||
class EditPages implements \CoreLibs\Output\Form\TableArraysInterface
|
||||
class EditPages implements Interface\TableArraysInterface
|
||||
{
|
||||
/** @var \CoreLibs\Output\Form\Generate */
|
||||
private $form;
|
||||
@@ -140,7 +140,10 @@ class EditPages implements \CoreLibs\Output\Form\TableArraysInterface
|
||||
],
|
||||
],
|
||||
'load_query' => "SELECT edit_page_id, "
|
||||
. "CASE WHEN hostname IS NOT NULL THEN hostname ELSE ''::VARCHAR END || filename AS filename, "
|
||||
. "CASE "
|
||||
. "WHEN hostname IS NOT NULL THEN hostname "
|
||||
. "ELSE ''::VARCHAR "
|
||||
. "END || filename AS filename, "
|
||||
. "name, online, menu, popup "
|
||||
. "FROM edit_page "
|
||||
. "ORDER BY order_number",
|
||||
@@ -178,7 +181,8 @@ class EditPages implements \CoreLibs\Output\Form\TableArraysInterface
|
||||
'select_size' => 10,
|
||||
'selected' => $_POST['edit_visible_group_id'] ?? '',
|
||||
'query' => "SELECT edit_visible_group_id, 'Name: ' || name || ', ' || 'Flag: ' || flag "
|
||||
. "FROM edit_visible_group ORDER BY name"
|
||||
. "FROM edit_visible_group "
|
||||
. "ORDER BY name"
|
||||
],
|
||||
'edit_menu_group' => [
|
||||
'table_name' => 'edit_page_menu_group',
|
||||
@@ -188,7 +192,8 @@ class EditPages implements \CoreLibs\Output\Form\TableArraysInterface
|
||||
'select_size' => 10,
|
||||
'selected' => $_POST['edit_menu_group_id'] ?? '',
|
||||
'query' => "SELECT edit_menu_group_id, 'Name: ' || name || ', ' || 'Flag: ' || flag "
|
||||
. "FROM edit_menu_group ORDER BY order_number"
|
||||
. "FROM edit_menu_group "
|
||||
. "ORDER BY order_number"
|
||||
],
|
||||
],
|
||||
'element_list' => [
|
||||
@@ -259,7 +264,9 @@ class EditPages implements \CoreLibs\Output\Form\TableArraysInterface
|
||||
'output_name' => 'Access Level',
|
||||
'int' => 1,
|
||||
'preset' => 1, // first of the select
|
||||
'query' => "SELECT edit_access_right_id, name FROM edit_access_right ORDER BY level"
|
||||
'query' => "SELECT edit_access_right_id, name "
|
||||
. "FROM edit_access_right "
|
||||
. "ORDER BY level"
|
||||
],
|
||||
'edit_page_content_id' => [
|
||||
'type' => 'hidden',
|
||||
|
||||
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace CoreLibs\Output\Form\TableArrays;
|
||||
|
||||
class EditSchemas implements \CoreLibs\Output\Form\TableArraysInterface
|
||||
class EditSchemas implements Interface\TableArraysInterface
|
||||
{
|
||||
/** @var \CoreLibs\Output\Form\Generate */
|
||||
private $form;
|
||||
@@ -68,7 +68,9 @@ class EditSchemas implements \CoreLibs\Output\Form\TableArraysInterface
|
||||
],
|
||||
],
|
||||
'table_name' => 'edit_scheme',
|
||||
'load_query' => "SELECT edit_scheme_id, name, enabled FROM edit_scheme ORDER BY name",
|
||||
'load_query' => "SELECT edit_scheme_id, name, enabled "
|
||||
. "FROM edit_scheme "
|
||||
. "ORDER BY name",
|
||||
'show_fields' => [
|
||||
[
|
||||
'name' => 'name'
|
||||
|
||||
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace CoreLibs\Output\Form\TableArrays;
|
||||
|
||||
class EditUsers implements \CoreLibs\Output\Form\TableArraysInterface
|
||||
class EditUsers implements Interface\TableArraysInterface
|
||||
{
|
||||
/** @var \CoreLibs\Output\Form\Generate */
|
||||
private $form;
|
||||
@@ -274,7 +274,7 @@ class EditUsers implements \CoreLibs\Output\Form\TableArraysInterface
|
||||
'type' => 'drop_down_db',
|
||||
'query' => "SELECT edit_language_id, long_name "
|
||||
. "FROM edit_language "
|
||||
. "WHERE enabled = 1"
|
||||
. "WHERE enabled = 1 "
|
||||
. "ORDER BY order_number",
|
||||
'min_edit_acl' => '100',
|
||||
'min_show_acl' => '100',
|
||||
@@ -284,7 +284,10 @@ class EditUsers implements \CoreLibs\Output\Form\TableArraysInterface
|
||||
'output_name' => 'Scheme',
|
||||
'int_null' => 1,
|
||||
'type' => 'drop_down_db',
|
||||
'query' => "SELECT edit_scheme_id, name FROM edit_scheme WHERE enabled = 1 ORDER BY name",
|
||||
'query' => "SELECT edit_scheme_id, name "
|
||||
. "FROM edit_scheme "
|
||||
. "WHERE enabled = 1 "
|
||||
. "ORDER BY name",
|
||||
'min_edit_acl' => '100',
|
||||
'min_show_acl' => '100',
|
||||
],
|
||||
@@ -293,7 +296,10 @@ class EditUsers implements \CoreLibs\Output\Form\TableArraysInterface
|
||||
'output_name' => 'Group',
|
||||
'int' => 1,
|
||||
'type' => 'drop_down_db',
|
||||
'query' => "SELECT edit_group_id, name FROM edit_group WHERE enabled = 1 ORDER BY name",
|
||||
'query' => "SELECT edit_group_id, name "
|
||||
. "FROM edit_group "
|
||||
. "WHERE enabled = 1 "
|
||||
. "ORDER BY name",
|
||||
'mandatory' => 1,
|
||||
'min_edit_acl' => '100',
|
||||
'min_show_acl' => '100',
|
||||
@@ -304,7 +310,9 @@ class EditUsers implements \CoreLibs\Output\Form\TableArraysInterface
|
||||
'mandatory' => 1,
|
||||
'int' => 1,
|
||||
'type' => 'drop_down_db',
|
||||
'query' => "SELECT edit_access_right_id, name FROM edit_access_right ORDER BY level",
|
||||
'query' => "SELECT edit_access_right_id, name "
|
||||
. "FROM edit_access_right "
|
||||
. "ORDER BY level",
|
||||
'min_edit_acl' => '100',
|
||||
'min_show_acl' => '100',
|
||||
],
|
||||
@@ -434,7 +442,9 @@ class EditUsers implements \CoreLibs\Output\Form\TableArraysInterface
|
||||
'output_name' => 'Access Level',
|
||||
'preset' => 1, // first of the select
|
||||
'int' => 1,
|
||||
'query' => "SELECT edit_access_right_id, name FROM edit_access_right ORDER BY level"
|
||||
'query' => "SELECT edit_access_right_id, name "
|
||||
. "FROM edit_access_right "
|
||||
. "ORDER BY level"
|
||||
],
|
||||
'edit_default' => [
|
||||
'type' => 'radio_group',
|
||||
|
||||
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace CoreLibs\Output\Form\TableArrays;
|
||||
|
||||
class EditVisibleGroup implements \CoreLibs\Output\Form\TableArraysInterface
|
||||
class EditVisibleGroup implements Interface\TableArraysInterface
|
||||
{
|
||||
/** @var \CoreLibs\Output\Form\Generate */
|
||||
private $form;
|
||||
@@ -48,7 +48,9 @@ class EditVisibleGroup implements \CoreLibs\Output\Form\TableArraysInterface
|
||||
],
|
||||
],
|
||||
'table_name' => 'edit_visible_group',
|
||||
'load_query' => "SELECT edit_visible_group_id, name FROM edit_visible_group ORDER BY name",
|
||||
'load_query' => "SELECT edit_visible_group_id, name "
|
||||
. "FROM edit_visible_group "
|
||||
. "ORDER BY name",
|
||||
'show_fields' => [
|
||||
[
|
||||
'name' => 'name'
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CoreLibs\Output\Form;
|
||||
namespace CoreLibs\Output\Form\TableArrays\Interface;
|
||||
|
||||
interface TableArraysInterface
|
||||
{
|
||||
@@ -12,6 +12,7 @@ class Image
|
||||
{
|
||||
/**
|
||||
* converts picture to a thumbnail with max x and max y size
|
||||
* TOOD: needs mandatory options for ImageMagic convert, paths, etc folders
|
||||
*
|
||||
* @param string $pic source image file with or without path
|
||||
* @param int $size_x maximum size width
|
||||
@@ -22,7 +23,7 @@ class Image
|
||||
* if empty ROOT is choosen
|
||||
* @param string $cache_source cache path, if not given TMP is used
|
||||
* @param bool $clear_cache if set to true, will create thumb all the tame
|
||||
* @return string|bool thumbnail name, or false for error
|
||||
* @return string|false thumbnail name, or false for error
|
||||
*/
|
||||
public static function createThumbnail(
|
||||
string $pic,
|
||||
@@ -32,7 +33,7 @@ class Image
|
||||
string $path = '',
|
||||
string $cache_source = '',
|
||||
bool $clear_cache = false
|
||||
) {
|
||||
): string|false {
|
||||
// get image type flags
|
||||
$image_types = [
|
||||
1 => 'gif',
|
||||
@@ -73,7 +74,7 @@ class Image
|
||||
$create_file = false;
|
||||
$delete_filename = '';
|
||||
// check if we can skip the PDF creation: if we have size, if do not have type, we assume type png
|
||||
if (!$type && is_numeric($size_x) && is_numeric($size_y)) {
|
||||
if (!$type) {
|
||||
$check_thumb = $tmp_src . 'thumb_' . $pic . '_' . $size_x . 'x' . $size_y . '.' . $image_types[3];
|
||||
if (!is_file($check_thumb)) {
|
||||
$create_file = true;
|
||||
@@ -100,10 +101,10 @@ class Image
|
||||
[$width, $height, $type] = getimagesize($filename) ?: [];
|
||||
}
|
||||
// if no size given, set size to original
|
||||
if (!$size_x || $size_x < 1 || !is_numeric($size_x)) {
|
||||
if (!$size_x || $size_x < 1) {
|
||||
$size_x = $width;
|
||||
}
|
||||
if (!$size_y || $size_y < 1 || !is_numeric($size_y)) {
|
||||
if (!$size_y || $size_y < 1) {
|
||||
$size_y = $height;
|
||||
}
|
||||
$thumb = 'thumb_' . $pic . '_' . $size_x . 'x' . $size_y . '.' . $image_types[$type];
|
||||
@@ -158,260 +159,275 @@ class Image
|
||||
* if both are set, those are the max sizes (aspect ration is always ekpt)
|
||||
* - if path is not given will cache folder for current path set
|
||||
*
|
||||
* @param string $filename source file name with full path
|
||||
* @param int $thumb_width thumbnail width
|
||||
* @param int $thumb_height thumbnail height
|
||||
* @param string|null $thumbnail_path altnerative path for thumbnails
|
||||
* @param bool $create_dummy if we encounter an invalid file
|
||||
* create a dummy image file and return it
|
||||
* @param bool $use_cache default to true, set to false to skip
|
||||
* creating new image if exists
|
||||
* @param bool $high_quality default to true, uses sample version,
|
||||
* set to false to not use (default true)
|
||||
* to use quick but less nice version
|
||||
* @param int $jpeg_quality default 80, set image quality for jpeg only
|
||||
* @return string|bool thumbnail with path
|
||||
* @param string $filename source file name with full path
|
||||
* @param int $thumb_width thumbnail width
|
||||
* @param int $thumb_height thumbnail height
|
||||
* @param string|null $cache_folder path for thumbnail cache
|
||||
* @param string|null $web_folder frontend path for output
|
||||
* @param bool $create_dummy if we encounter an invalid file
|
||||
* create a dummy image file and return it
|
||||
* @param bool $use_cache default to true, set to false to skip
|
||||
* creating new image if exists
|
||||
* @param bool $high_quality default to true, uses sample version,
|
||||
* set to false to not use (default true)
|
||||
* to use quick but less nice version
|
||||
* @param int $jpeg_quality default 80, set image quality for jpeg only
|
||||
* @return string|false thumbnail with path
|
||||
*/
|
||||
public static function createThumbnailSimple(
|
||||
string $filename,
|
||||
int $thumb_width = 0,
|
||||
int $thumb_height = 0,
|
||||
?string $thumbnail_path = null,
|
||||
?string $cache_folder = null, // will be not null in future
|
||||
?string $web_folder = null,
|
||||
bool $create_dummy = true,
|
||||
bool $use_cache = true,
|
||||
bool $high_quality = true,
|
||||
int $jpeg_quality = 80
|
||||
) {
|
||||
): string|false {
|
||||
$thumbnail = false;
|
||||
// $this->debug('IMAGE PREPARE', "FILE: $filename (exists "
|
||||
// .(string)file_exists($filename)."), WIDTH: $thumb_width, HEIGHT: $thumb_height");
|
||||
if (
|
||||
$cache_folder === null ||
|
||||
$web_folder === null
|
||||
) {
|
||||
/** @deprecated Do use cache folder and web folder parameters */
|
||||
trigger_error(
|
||||
'params $cache_folder and $web_folder must be set. Setting via constants is deprecated',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
// NOTE: we need to depracte this
|
||||
$cache_folder = BASE . LAYOUT . CONTENT_PATH . CACHE . IMAGES;
|
||||
$web_folder = LAYOUT . CACHE . IMAGES;
|
||||
if (!is_dir($cache_folder)) {
|
||||
if (false === mkdir($cache_folder)) {
|
||||
$cache_folder = BASE . LAYOUT . CONTENT_PATH . CACHE;
|
||||
$web_folder = LAYOUT . CACHE;
|
||||
}
|
||||
}
|
||||
}
|
||||
// check that input image exists and is either jpeg or png
|
||||
// also fail if the basic CACHE folder does not exist at all
|
||||
if (
|
||||
file_exists($filename) &&
|
||||
is_dir(BASE . LAYOUT . CONTENT_PATH . CACHE) &&
|
||||
is_writable(BASE . LAYOUT . CONTENT_PATH . CACHE)
|
||||
!file_exists($filename) ||
|
||||
!is_dir($cache_folder) ||
|
||||
!is_writable($cache_folder)
|
||||
) {
|
||||
// $this->debug('IMAGE PREPARE', "FILENAME OK, THUMB WIDTH/HEIGHT OK");
|
||||
[$inc_width, $inc_height, $img_type] = getimagesize($filename) ?: [];
|
||||
$thumbnail_write_path = null;
|
||||
$thumbnail_web_path = null;
|
||||
// path set first
|
||||
if (
|
||||
$img_type == IMAGETYPE_JPEG ||
|
||||
$img_type == IMAGETYPE_PNG ||
|
||||
$create_dummy === true
|
||||
) {
|
||||
// $this->debug('IMAGE PREPARE', "IMAGE TYPE OK: ".$inc_width.'x'.$inc_height);
|
||||
// set thumbnail paths
|
||||
$thumbnail_write_path = BASE . LAYOUT . CONTENT_PATH . CACHE . IMAGES;
|
||||
$thumbnail_web_path = LAYOUT . CACHE . IMAGES;
|
||||
// if images folder in cache does not exist create it, if failed, fall back to base cache folder
|
||||
if (!is_dir($thumbnail_write_path)) {
|
||||
if (false === mkdir($thumbnail_write_path)) {
|
||||
$thumbnail_write_path = BASE . LAYOUT . CONTENT_PATH . CACHE;
|
||||
$thumbnail_web_path = LAYOUT . CACHE;
|
||||
}
|
||||
}
|
||||
return $thumbnail;
|
||||
}
|
||||
// $this->debug('IMAGE PREPARE', "FILENAME OK, THUMB WIDTH/HEIGHT OK");
|
||||
[$inc_width, $inc_height, $img_type] = getimagesize($filename) ?: [];
|
||||
$thumbnail_write_path = null;
|
||||
$thumbnail_web_path = null;
|
||||
// path set first
|
||||
if (
|
||||
$img_type == IMAGETYPE_JPEG ||
|
||||
$img_type == IMAGETYPE_PNG ||
|
||||
$create_dummy === true
|
||||
) {
|
||||
// $this->debug('IMAGE PREPARE', "IMAGE TYPE OK: ".$inc_width.'x'.$inc_height);
|
||||
// set thumbnail paths
|
||||
$thumbnail_write_path = $cache_folder;
|
||||
$thumbnail_web_path = $web_folder;
|
||||
}
|
||||
// do resize or fall back on dummy run
|
||||
if (
|
||||
$img_type == IMAGETYPE_JPEG ||
|
||||
$img_type == IMAGETYPE_PNG
|
||||
) {
|
||||
// if missing width or height in thumb, use the set one
|
||||
if ($thumb_width == 0) {
|
||||
$thumb_width = $inc_width;
|
||||
}
|
||||
// do resize or fall back on dummy run
|
||||
if (
|
||||
$img_type == IMAGETYPE_JPEG ||
|
||||
$img_type == IMAGETYPE_PNG
|
||||
) {
|
||||
// if missing width or height in thumb, use the set one
|
||||
if ($thumb_width == 0) {
|
||||
$thumb_width = $inc_width;
|
||||
}
|
||||
if ($thumb_height == 0) {
|
||||
$thumb_height = $inc_height;
|
||||
}
|
||||
// check resize parameters
|
||||
if ($inc_width > $thumb_width || $inc_height > $thumb_height) {
|
||||
$thumb_width_r = 0;
|
||||
$thumb_height_r = 0;
|
||||
// we need to keep the aspect ration on longest side
|
||||
if (
|
||||
($inc_height > $inc_width &&
|
||||
// and the height is bigger than thumb set
|
||||
$inc_height > $thumb_height) ||
|
||||
// or the height is smaller or equal width
|
||||
// but the width for the thumb is equal to the image height
|
||||
($inc_height <= $inc_width &&
|
||||
$inc_width == $thumb_width
|
||||
)
|
||||
) {
|
||||
// $this->debug('IMAGE PREPARE', 'HEIGHT > WIDTH');
|
||||
$ratio = $inc_height / $thumb_height;
|
||||
$thumb_width_r = (int)ceil($inc_width / $ratio);
|
||||
$thumb_height_r = $thumb_height;
|
||||
} else {
|
||||
// $this->debug('IMAGE PREPARE', 'WIDTH > HEIGHT');
|
||||
$ratio = $inc_width / $thumb_width;
|
||||
$thumb_width_r = $thumb_width;
|
||||
$thumb_height_r = (int)ceil($inc_height / $ratio);
|
||||
}
|
||||
// $this->debug('IMAGE PREPARE', "Ratio: $ratio, Target size $thumb_width_r x $thumb_height_r");
|
||||
// set output thumbnail name
|
||||
$thumbnail = 'thumb-' . pathinfo($filename)['filename'] . '-'
|
||||
. $thumb_width_r . 'x' . $thumb_height_r;
|
||||
if (
|
||||
$use_cache === false ||
|
||||
!file_exists($thumbnail_write_path . $thumbnail)
|
||||
) {
|
||||
// image, copy source image, offset in image, source x/y, new size, source image size
|
||||
$thumb = imagecreatetruecolor($thumb_width_r, $thumb_height_r);
|
||||
if ($thumb === false) {
|
||||
return false;
|
||||
}
|
||||
if ($img_type == IMAGETYPE_PNG) {
|
||||
$imagecolorallocatealpha = imagecolorallocatealpha($thumb, 0, 0, 0, 127);
|
||||
if ($imagecolorallocatealpha === false) {
|
||||
return false;
|
||||
}
|
||||
// preservere transaprency
|
||||
imagecolortransparent(
|
||||
$thumb,
|
||||
$imagecolorallocatealpha
|
||||
);
|
||||
imagealphablending($thumb, false);
|
||||
imagesavealpha($thumb, true);
|
||||
}
|
||||
$source = null;
|
||||
switch ($img_type) {
|
||||
case IMAGETYPE_JPEG:
|
||||
$source = imagecreatefromjpeg($filename);
|
||||
break;
|
||||
case IMAGETYPE_PNG:
|
||||
$source = imagecreatefrompng($filename);
|
||||
break;
|
||||
}
|
||||
// check that we have a source image resource
|
||||
if ($source !== null && $source !== false) {
|
||||
// resize no shift
|
||||
if ($high_quality === true) {
|
||||
imagecopyresized(
|
||||
$thumb,
|
||||
$source,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
$thumb_width_r,
|
||||
$thumb_height_r,
|
||||
$inc_width,
|
||||
$inc_height
|
||||
);
|
||||
} else {
|
||||
imagecopyresampled(
|
||||
$thumb,
|
||||
$source,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
$thumb_width_r,
|
||||
$thumb_height_r,
|
||||
$inc_width,
|
||||
$inc_height
|
||||
);
|
||||
}
|
||||
// write file
|
||||
switch ($img_type) {
|
||||
case IMAGETYPE_JPEG:
|
||||
imagejpeg($thumb, $thumbnail_write_path . $thumbnail, $jpeg_quality);
|
||||
break;
|
||||
case IMAGETYPE_PNG:
|
||||
imagepng($thumb, $thumbnail_write_path . $thumbnail);
|
||||
break;
|
||||
}
|
||||
// free up resources (in case we are called in a loop)
|
||||
imagedestroy($source);
|
||||
imagedestroy($thumb);
|
||||
} else {
|
||||
$thumbnail = false;
|
||||
}
|
||||
}
|
||||
if ($thumb_height == 0) {
|
||||
$thumb_height = $inc_height;
|
||||
}
|
||||
// check resize parameters
|
||||
if ($inc_width > $thumb_width || $inc_height > $thumb_height) {
|
||||
$thumb_width_r = 0;
|
||||
$thumb_height_r = 0;
|
||||
// we need to keep the aspect ration on longest side
|
||||
if (
|
||||
($inc_height > $inc_width &&
|
||||
// and the height is bigger than thumb set
|
||||
$inc_height > $thumb_height) ||
|
||||
// or the height is smaller or equal width
|
||||
// but the width for the thumb is equal to the image height
|
||||
($inc_height <= $inc_width &&
|
||||
$inc_width == $thumb_width
|
||||
)
|
||||
) {
|
||||
// $this->debug('IMAGE PREPARE', 'HEIGHT > WIDTH');
|
||||
$ratio = $inc_height / $thumb_height;
|
||||
$thumb_width_r = (int)ceil($inc_width / $ratio);
|
||||
$thumb_height_r = $thumb_height;
|
||||
} else {
|
||||
// we just copy over the image as is, we never upscale
|
||||
$thumbnail = 'thumb-' . pathinfo($filename)['filename'] . '-' . $inc_width . 'x' . $inc_height;
|
||||
if (
|
||||
$use_cache === false ||
|
||||
!file_exists($thumbnail_write_path . $thumbnail)
|
||||
) {
|
||||
copy($filename, $thumbnail_write_path . $thumbnail);
|
||||
}
|
||||
// $this->debug('IMAGE PREPARE', 'WIDTH > HEIGHT');
|
||||
$ratio = $inc_width / $thumb_width;
|
||||
$thumb_width_r = $thumb_width;
|
||||
$thumb_height_r = (int)ceil($inc_height / $ratio);
|
||||
}
|
||||
// add output path
|
||||
if ($thumbnail !== false) {
|
||||
$thumbnail = $thumbnail_web_path . $thumbnail;
|
||||
}
|
||||
} elseif ($create_dummy === true) {
|
||||
// create dummy image in the thumbnail size
|
||||
// if one side is missing, use the other side to create a square
|
||||
if (!$thumb_width) {
|
||||
$thumb_width = $thumb_height;
|
||||
}
|
||||
if (!$thumb_height) {
|
||||
$thumb_height = $thumb_width;
|
||||
}
|
||||
// do we have an image already?
|
||||
$thumbnail = 'thumb-' . pathinfo($filename)['filename'] . '-' . $thumb_width . 'x' . $thumb_height;
|
||||
// $this->debug('IMAGE PREPARE', "Ratio: $ratio, Target size $thumb_width_r x $thumb_height_r");
|
||||
// set output thumbnail name
|
||||
$thumbnail = 'thumb-' . pathinfo($filename)['filename'] . '-'
|
||||
. $thumb_width_r . 'x' . $thumb_height_r;
|
||||
if (
|
||||
$use_cache === false ||
|
||||
!file_exists($thumbnail_write_path . $thumbnail)
|
||||
) {
|
||||
// if both are unset, set to 250
|
||||
if ($thumb_height == 0) {
|
||||
$thumb_height = 250;
|
||||
}
|
||||
if ($thumb_width == 0) {
|
||||
$thumb_width = 250;
|
||||
}
|
||||
$thumb = imagecreatetruecolor($thumb_width, $thumb_height);
|
||||
// image, copy source image, offset in image, source x/y, new size, source image size
|
||||
$thumb = imagecreatetruecolor($thumb_width_r, $thumb_height_r);
|
||||
if ($thumb === false) {
|
||||
return false;
|
||||
}
|
||||
// add outside border px = 5% (rounded up)
|
||||
// eg 50px -> 2.5px
|
||||
$gray = imagecolorallocate($thumb, 200, 200, 200);
|
||||
$white = imagecolorallocate($thumb, 255, 255, 255);
|
||||
if ($gray === false || $white === false) {
|
||||
return false;
|
||||
if ($img_type == IMAGETYPE_PNG) {
|
||||
$imagecolorallocatealpha = imagecolorallocatealpha($thumb, 0, 0, 0, 127);
|
||||
if ($imagecolorallocatealpha === false) {
|
||||
return false;
|
||||
}
|
||||
// preservere transaprency
|
||||
imagecolortransparent(
|
||||
$thumb,
|
||||
$imagecolorallocatealpha
|
||||
);
|
||||
imagealphablending($thumb, false);
|
||||
imagesavealpha($thumb, true);
|
||||
}
|
||||
// fill gray background
|
||||
imagefill($thumb, 0, 0, $gray);
|
||||
// now create rectangle
|
||||
if (imagesx($thumb) < imagesy($thumb)) {
|
||||
$width = (int)round(imagesx($thumb) / 100 * 5);
|
||||
$source = null;
|
||||
switch ($img_type) {
|
||||
case IMAGETYPE_JPEG:
|
||||
$source = imagecreatefromjpeg($filename);
|
||||
break;
|
||||
case IMAGETYPE_PNG:
|
||||
$source = imagecreatefrompng($filename);
|
||||
break;
|
||||
}
|
||||
// check that we have a source image resource
|
||||
if ($source !== null && $source !== false) {
|
||||
// resize no shift
|
||||
if ($high_quality === true) {
|
||||
imagecopyresized(
|
||||
$thumb,
|
||||
$source,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
$thumb_width_r,
|
||||
$thumb_height_r,
|
||||
$inc_width,
|
||||
$inc_height
|
||||
);
|
||||
} else {
|
||||
imagecopyresampled(
|
||||
$thumb,
|
||||
$source,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
$thumb_width_r,
|
||||
$thumb_height_r,
|
||||
$inc_width,
|
||||
$inc_height
|
||||
);
|
||||
}
|
||||
// write file
|
||||
switch ($img_type) {
|
||||
case IMAGETYPE_JPEG:
|
||||
imagejpeg($thumb, $thumbnail_write_path . $thumbnail, $jpeg_quality);
|
||||
break;
|
||||
case IMAGETYPE_PNG:
|
||||
imagepng($thumb, $thumbnail_write_path . $thumbnail);
|
||||
break;
|
||||
}
|
||||
// free up resources (in case we are called in a loop)
|
||||
imagedestroy($source);
|
||||
imagedestroy($thumb);
|
||||
} else {
|
||||
$width = (int)round(imagesy($thumb) / 100 * 5);
|
||||
$thumbnail = false;
|
||||
}
|
||||
imagefilledrectangle(
|
||||
$thumb,
|
||||
0 + $width,
|
||||
0 + $width,
|
||||
imagesx($thumb) - $width,
|
||||
imagesy($thumb) - $width,
|
||||
$white
|
||||
);
|
||||
// add "No valid images source"
|
||||
// OR add circle
|
||||
// * find center
|
||||
// * width/height is 75% of size - border
|
||||
// smaller size is taken
|
||||
$base_width = imagesx($thumb) > imagesy($thumb) ? imagesy($thumb) : imagesx($thumb);
|
||||
// get 75% width
|
||||
$cross_width = (int)round((($base_width - ($width * 2)) / 100 * 75) / 2);
|
||||
$center_x = (int)round(imagesx($thumb) / 2);
|
||||
$center_y = (int)round(imagesy($thumb) / 2);
|
||||
imagefilledellipse($thumb, $center_x, $center_y, $cross_width, $cross_width, $gray);
|
||||
// find top left and bottom left for first line
|
||||
imagepng($thumb, $thumbnail_write_path . $thumbnail);
|
||||
}
|
||||
// add web path
|
||||
} else {
|
||||
// we just copy over the image as is, we never upscale
|
||||
$thumbnail = 'thumb-' . pathinfo($filename)['filename'] . '-' . $inc_width . 'x' . $inc_height;
|
||||
if (
|
||||
$use_cache === false ||
|
||||
!file_exists($thumbnail_write_path . $thumbnail)
|
||||
) {
|
||||
copy($filename, $thumbnail_write_path . $thumbnail);
|
||||
}
|
||||
}
|
||||
// add output path
|
||||
if ($thumbnail !== false) {
|
||||
$thumbnail = $thumbnail_web_path . $thumbnail;
|
||||
}
|
||||
} elseif ($create_dummy === true) {
|
||||
// create dummy image in the thumbnail size
|
||||
// if one side is missing, use the other side to create a square
|
||||
if (!$thumb_width) {
|
||||
$thumb_width = $thumb_height;
|
||||
}
|
||||
if (!$thumb_height) {
|
||||
$thumb_height = $thumb_width;
|
||||
}
|
||||
// do we have an image already?
|
||||
$thumbnail = 'thumb-' . pathinfo($filename)['filename'] . '-' . $thumb_width . 'x' . $thumb_height;
|
||||
if (
|
||||
$use_cache === false ||
|
||||
!file_exists($thumbnail_write_path . $thumbnail)
|
||||
) {
|
||||
// if both are unset, set to 250
|
||||
if ($thumb_height == 0) {
|
||||
$thumb_height = 250;
|
||||
}
|
||||
if ($thumb_width == 0) {
|
||||
$thumb_width = 250;
|
||||
}
|
||||
$thumb = imagecreatetruecolor($thumb_width, $thumb_height);
|
||||
if ($thumb === false) {
|
||||
return false;
|
||||
}
|
||||
// add outside border px = 5% (rounded up)
|
||||
// eg 50px -> 2.5px
|
||||
$gray = imagecolorallocate($thumb, 200, 200, 200);
|
||||
$white = imagecolorallocate($thumb, 255, 255, 255);
|
||||
if ($gray === false || $white === false) {
|
||||
return false;
|
||||
}
|
||||
// fill gray background
|
||||
imagefill($thumb, 0, 0, $gray);
|
||||
// now create rectangle
|
||||
if (imagesx($thumb) < imagesy($thumb)) {
|
||||
$width = (int)round(imagesx($thumb) / 100 * 5);
|
||||
} else {
|
||||
$width = (int)round(imagesy($thumb) / 100 * 5);
|
||||
}
|
||||
imagefilledrectangle(
|
||||
$thumb,
|
||||
0 + $width,
|
||||
0 + $width,
|
||||
imagesx($thumb) - $width,
|
||||
imagesy($thumb) - $width,
|
||||
$white
|
||||
);
|
||||
// add "No valid images source"
|
||||
// OR add circle
|
||||
// * find center
|
||||
// * width/height is 75% of size - border
|
||||
// smaller size is taken
|
||||
$base_width = imagesx($thumb) > imagesy($thumb) ? imagesy($thumb) : imagesx($thumb);
|
||||
// get 75% width
|
||||
$cross_width = (int)round((($base_width - ($width * 2)) / 100 * 75) / 2);
|
||||
$center_x = (int)round(imagesx($thumb) / 2);
|
||||
$center_y = (int)round(imagesy($thumb) / 2);
|
||||
imagefilledellipse($thumb, $center_x, $center_y, $cross_width, $cross_width, $gray);
|
||||
// find top left and bottom left for first line
|
||||
imagepng($thumb, $thumbnail_write_path . $thumbnail);
|
||||
}
|
||||
// add web path
|
||||
$thumbnail = $thumbnail_web_path . $thumbnail;
|
||||
}
|
||||
// either return false or the thumbnail name + output path web
|
||||
return $thumbnail;
|
||||
@@ -425,7 +441,7 @@ class Image
|
||||
* @param string $filename path + filename to rotate. This file must be writeable
|
||||
* @return void
|
||||
*/
|
||||
public static function correctImageOrientation($filename): void
|
||||
public static function correctImageOrientation(string $filename): void
|
||||
{
|
||||
// function exists & file is writeable, else do nothing
|
||||
if (!function_exists('exif_read_data') || !is_writeable($filename)) {
|
||||
|
||||
@@ -160,23 +160,42 @@ class SmartyExtend extends \Smarty
|
||||
* also registers the getvar caller plugin
|
||||
*
|
||||
* @param \CoreLibs\Language\L10n $l10n l10n language class
|
||||
* @param array<string,string> $locale locale data read from setLocale
|
||||
* @param string|null $cache_id
|
||||
* @param string|null $compile_id
|
||||
*/
|
||||
public function __construct(\CoreLibs\Language\L10n $l10n, array $locale)
|
||||
{
|
||||
public function __construct(
|
||||
\CoreLibs\Language\L10n $l10n,
|
||||
?string $cache_id = null,
|
||||
?string $compile_id = null
|
||||
) {
|
||||
// trigger deprecation
|
||||
if (
|
||||
$cache_id === null ||
|
||||
$compile_id === null
|
||||
) {
|
||||
/** @deprecated SmartyExtend::__construct call without parameters */
|
||||
trigger_error(
|
||||
'Calling SmartyExtend::__construct without paramters is deprecated',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
}
|
||||
// set variables (to be deprecated)
|
||||
$cache_id = $cache_id ??
|
||||
(defined('CACHE_ID') ? CACHE_ID : '');
|
||||
$compile_id = $compile_id ??
|
||||
(defined('COMPILE_ID') ? COMPILE_ID : '');
|
||||
// call basic smarty
|
||||
// or Smarty::__construct();
|
||||
parent::__construct();
|
||||
// iinit lang
|
||||
$this->l10n = $l10n;
|
||||
// parse and read, legacy stuff
|
||||
$locale = $this->l10n->getLocaleAsArray();
|
||||
$this->encoding = $locale['encoding'];
|
||||
$this->lang = $locale['lang'];
|
||||
// get first part from lang
|
||||
$this->lang_short = explode('_', $locale['lang'])[0];
|
||||
$this->domain = $this->l10n->getDomain();
|
||||
$this->locale_set = $this->l10n->getLocaleSet();
|
||||
$this->lang_dir = $this->l10n->getBaseLocalePath();
|
||||
$this->lang_short = $locale['lang_short'];
|
||||
$this->domain = $locale['domain'];
|
||||
$this->lang_dir = $locale['path'];
|
||||
|
||||
// opt load functions so we can use legacy init for smarty run perhaps
|
||||
\CoreLibs\Language\L10n::loadFunctions();
|
||||
@@ -191,8 +210,8 @@ class SmartyExtend extends \Smarty
|
||||
$this->page_name = \CoreLibs\Get\System::getPageName();
|
||||
|
||||
// set internal settings
|
||||
$this->CACHE_ID = defined('CACHE_ID') ? CACHE_ID : '';
|
||||
$this->COMPILE_ID = defined('COMPILE_ID') ? COMPILE_ID : '';
|
||||
$this->CACHE_ID = $cache_id;
|
||||
$this->COMPILE_ID = $compile_id;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -256,11 +275,70 @@ class SmartyExtend extends \Smarty
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setSmartyPaths(): void
|
||||
{
|
||||
|
||||
/**
|
||||
* sets all internal paths and names that need to be passed on
|
||||
* to the smarty template
|
||||
*
|
||||
* @param string|null $set_includes INCLUDES
|
||||
* @param string|null $set_template_path TEMPLATE_PATH
|
||||
* @param string|null $set_javascript JAVASCRIPT
|
||||
* @param string|null $set_css CSS
|
||||
* @param string|null $set_font FONT
|
||||
* @param string|null $set_pictures PICTURES
|
||||
* @param string|null $set_cache_pictures CACHE_PICTURES
|
||||
* @param string|null $set_cache_pictures_root CACHE_PICTURES_ROOT
|
||||
* @param string|null $set_master_template_name MASTAER_TEMPLATE_NAME
|
||||
* @return void
|
||||
*/
|
||||
public function setSmartyPaths(
|
||||
?string $set_includes = null,
|
||||
?string $set_template_path = null,
|
||||
?string $set_javascript = null,
|
||||
?string $set_css = null,
|
||||
?string $set_font = null,
|
||||
?string $set_pictures = null,
|
||||
?string $set_cache_pictures = null,
|
||||
?string $set_cache_pictures_root = null,
|
||||
?string $set_master_template_name = null,
|
||||
): void {
|
||||
// trigger deprecation
|
||||
if (
|
||||
$set_includes === null ||
|
||||
$set_template_path === null ||
|
||||
$set_javascript === null ||
|
||||
$set_css === null ||
|
||||
$set_font === null ||
|
||||
$set_pictures === null ||
|
||||
$set_cache_pictures === null ||
|
||||
$set_cache_pictures_root === null
|
||||
) {
|
||||
/** @deprecated setSmartyPaths call without parameters */
|
||||
trigger_error(
|
||||
'Calling setSmartyPaths without paramters is deprecated',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
}
|
||||
// set variables (to be deprecated)
|
||||
$set_master_template_name = $set_master_template_name ??
|
||||
(defined('MASTER_TEMPLATE_NAME') ? MASTER_TEMPLATE_NAME : '');
|
||||
$set_includes = $set_includes ??
|
||||
BASE . INCLUDES;
|
||||
$set_template_path = $set_template_path ??
|
||||
BASE . INCLUDES . TEMPLATES . CONTENT_PATH;
|
||||
$set_javascript = $set_javascript ?? LAYOUT . JS;
|
||||
$set_css = $set_css ?? LAYOUT . CSS;
|
||||
$set_font = $set_font ?? LAYOUT . FONT;
|
||||
$set_pictures = $set_pictures ?? LAYOUT . IMAGES;
|
||||
$set_cache_pictures = $set_cache_pictures ?? LAYOUT . CACHE;
|
||||
$set_cache_pictures_root = $set_cache_pictures_root ??
|
||||
ROOT . $set_cache_pictures;
|
||||
|
||||
// master template
|
||||
if (empty($this->MASTER_TEMPLATE_NAME)) {
|
||||
$this->MASTER_TEMPLATE_NAME = MASTER_TEMPLATE_NAME;
|
||||
if (
|
||||
empty($this->MASTER_TEMPLATE_NAME)
|
||||
) {
|
||||
$this->MASTER_TEMPLATE_NAME = $set_master_template_name;
|
||||
}
|
||||
|
||||
// set include & template names
|
||||
@@ -276,15 +354,15 @@ class SmartyExtend extends \Smarty
|
||||
$this->CSS_TEMPLATE_NAME = str_replace('.tpl', '.css', $this->CONTENT_INCLUDE);
|
||||
|
||||
// set basic template path (tmp)
|
||||
$this->INCLUDES = BASE . INCLUDES; // no longer in templates, only global
|
||||
$this->TEMPLATE_PATH = BASE . INCLUDES . TEMPLATES . CONTENT_PATH;
|
||||
$this->INCLUDES = $set_includes; // no longer in templates, only global
|
||||
$this->TEMPLATE_PATH = $set_template_path;
|
||||
$this->setTemplateDir($this->TEMPLATE_PATH);
|
||||
$this->JAVASCRIPT = LAYOUT . JS;
|
||||
$this->CSS = LAYOUT . CSS;
|
||||
$this->FONT = LAYOUT . FONT;
|
||||
$this->PICTURES = LAYOUT . IMAGES;
|
||||
$this->CACHE_PICTURES = LAYOUT . CACHE;
|
||||
$this->CACHE_PICTURES_ROOT = ROOT . $this->CACHE_PICTURES;
|
||||
$this->JAVASCRIPT = $set_javascript;
|
||||
$this->CSS = $set_css;
|
||||
$this->FONT = $set_font;
|
||||
$this->PICTURES = $set_pictures;
|
||||
$this->CACHE_PICTURES = $set_cache_pictures;
|
||||
$this->CACHE_PICTURES_ROOT = $set_cache_pictures_root;
|
||||
// check if we have an external file with the template name
|
||||
if (
|
||||
file_exists($this->INCLUDES . $this->INC_TEMPLATE_NAME) &&
|
||||
@@ -305,7 +383,7 @@ class SmartyExtend extends \Smarty
|
||||
// set all the additional CSS/JS parths
|
||||
$this->setSmartCoreIncludeCssJs();
|
||||
// check if template names exist
|
||||
if (!$this->MASTER_TEMPLATE_NAME) {
|
||||
if (empty($this->MASTER_TEMPLATE_NAME)) {
|
||||
exit('MASTER TEMPLATE is not set');
|
||||
} elseif (!file_exists($this->getTemplateDir()[0] . DIRECTORY_SEPARATOR . $this->MASTER_TEMPLATE_NAME)) {
|
||||
// abort if master template could not be found
|
||||
@@ -374,33 +452,195 @@ class SmartyExtend extends \Smarty
|
||||
* wrapper call for setSmartyVars
|
||||
* this is for frontend type and will not set any only admin needed variables
|
||||
*
|
||||
* @param string|null $compile_dir BASE . TEMPLATES_C
|
||||
* @param string|null $cache_dir BASE . CACHE
|
||||
* @param string|null $set_js JS
|
||||
* @param string|null $set_css CSS
|
||||
* @param string|null $set_font FONT
|
||||
* @param string|null $set_default_encoding DEFAULT_ENCODING
|
||||
* @param string|null $set_g_title G_TITLE
|
||||
* @param string|null $set_stylesheet STYLESHEET
|
||||
* @param string|null $set_javascript JAVASCRIPT
|
||||
* @param \CoreLibs\Admin\Backend|null $cms Optinal Admin Backend for
|
||||
* smarty variables merge
|
||||
* @return void
|
||||
*/
|
||||
public function setSmartyVarsFrontend(): void
|
||||
{
|
||||
$this->setSmartyVars();
|
||||
public function setSmartyVarsFrontend(
|
||||
?string $compile_dir = null,
|
||||
?string $cache_dir = null,
|
||||
?string $set_js = null,
|
||||
?string $set_css = null,
|
||||
?string $set_font = null,
|
||||
?string $set_default_encoding = null,
|
||||
?string $set_g_title = null,
|
||||
?string $set_stylesheet = null,
|
||||
?string $set_javascript = null,
|
||||
?\CoreLibs\Admin\Backend $cms = null
|
||||
): void {
|
||||
$this->setSmartyVars(
|
||||
false,
|
||||
$cms,
|
||||
$compile_dir,
|
||||
$cache_dir,
|
||||
$set_js,
|
||||
$set_css,
|
||||
$set_font,
|
||||
$set_default_encoding,
|
||||
$set_g_title,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
$set_stylesheet,
|
||||
$set_javascript
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* wrapper call for setSmartyVars
|
||||
* this is only for admin interface and will set additional variables
|
||||
* @param string|null $compile_dir BASE . TEMPLATES_C
|
||||
* @param string|null $cache_dir BASE . CACHE
|
||||
* @param string|null $set_js JS
|
||||
* @param string|null $set_css CSS
|
||||
* @param string|null $set_font FONT
|
||||
* @param string|null $set_default_encoding DEFAULT_ENCODING
|
||||
* @param string|null $set_g_title G_TITLE
|
||||
* @param string|null $set_admin_stylesheet ADMIN_STYLESHEET
|
||||
* @param string|null $set_admin_javascript ADMIN_JAVASCRIPT
|
||||
* @param string|null $set_page_width PAGE_WIDTH
|
||||
* @param \CoreLibs\Admin\Backend|null $cms Optinal Admin Backend for
|
||||
* smarty variables merge
|
||||
* @return void
|
||||
*/
|
||||
public function setSmartyVarsAdmin(): void
|
||||
{
|
||||
$this->setSmartyVars(true);
|
||||
public function setSmartyVarsAdmin(
|
||||
?string $compile_dir = null,
|
||||
?string $cache_dir = null,
|
||||
?string $set_js = null,
|
||||
?string $set_css = null,
|
||||
?string $set_font = null,
|
||||
?string $set_default_encoding = null,
|
||||
?string $set_g_title = null,
|
||||
?string $set_admin_stylesheet = null,
|
||||
?string $set_admin_javascript = null,
|
||||
?string $set_page_width = null,
|
||||
?\CoreLibs\Admin\Backend $cms = null
|
||||
): void {
|
||||
$this->setSmartyVars(
|
||||
true,
|
||||
$cms,
|
||||
$compile_dir,
|
||||
$cache_dir,
|
||||
$set_js,
|
||||
$set_css,
|
||||
$set_font,
|
||||
$set_g_title,
|
||||
$set_default_encoding,
|
||||
$set_admin_stylesheet,
|
||||
$set_admin_javascript,
|
||||
$set_page_width,
|
||||
null,
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* set smarty pass on variables, sub template names and finally calls the smarty parser
|
||||
* set smarty pass on variables, sub template names and
|
||||
* finally calls the smarty parser
|
||||
*
|
||||
* @param boolean $admin_call default false, will set admin only variables
|
||||
* @param bool $admin_call default false
|
||||
* will set admin only variables
|
||||
* @param \CoreLibs\Admin\Backend|null $cms Optinal Admin Backend for
|
||||
* smarty variables merge
|
||||
* @param string|null $compile_dir BASE . TEMPLATES_C
|
||||
* @param string|null $cache_dir BASE . CACHE
|
||||
* @param string|null $set_js JS
|
||||
* @param string|null $set_css CSS
|
||||
* @param string|null $set_font FONT
|
||||
* @param string|null $set_default_encoding DEFAULT_ENCODING
|
||||
* @param string|null $set_g_title G_TITLE
|
||||
* @param string|null $set_admin_stylesheet ADMIN_STYLESHEET
|
||||
* @param string|null $set_admin_javascript ADMIN_JAVASCRIPT
|
||||
* @param string|null $set_page_width PAGE_WIDTH
|
||||
* @param string|null $set_stylesheet STYLESHEET
|
||||
* @param string|null $set_javascript JAVASCRIPT
|
||||
* @param string|null $set_user_name _SESSION['USER_NAME']
|
||||
* @return void
|
||||
*/
|
||||
private function setSmartyVars($admin_call = false): void
|
||||
{
|
||||
/** @var \CoreLibs\Admin\Backend This is an assumption */
|
||||
global $cms;
|
||||
if (is_object($cms)) {
|
||||
private function setSmartyVars(
|
||||
bool $admin_call,
|
||||
?\CoreLibs\Admin\Backend $cms = null,
|
||||
?string $compile_dir = null,
|
||||
?string $cache_dir = null,
|
||||
?string $set_js = null,
|
||||
?string $set_css = null,
|
||||
?string $set_font = null,
|
||||
?string $set_default_encoding = null,
|
||||
?string $set_g_title = null,
|
||||
?string $set_admin_stylesheet = null,
|
||||
?string $set_admin_javascript = null,
|
||||
?string $set_page_width = null,
|
||||
?string $set_stylesheet = null,
|
||||
?string $set_javascript = null,
|
||||
?string $set_user_name = null,
|
||||
): void {
|
||||
// trigger deprecation
|
||||
if (
|
||||
$compile_dir === null ||
|
||||
$cache_dir === null ||
|
||||
$set_css === null ||
|
||||
$set_font === null ||
|
||||
$set_js === null ||
|
||||
$set_default_encoding === null ||
|
||||
$set_g_title === null ||
|
||||
(
|
||||
$admin_call === true && (
|
||||
$set_admin_stylesheet === null ||
|
||||
$set_admin_javascript === null ||
|
||||
$set_page_width === null ||
|
||||
$set_user_name === null
|
||||
)
|
||||
) ||
|
||||
(
|
||||
$admin_call === false && (
|
||||
$set_stylesheet === null ||
|
||||
$set_javascript === null
|
||||
)
|
||||
)
|
||||
) {
|
||||
/** @deprecated setSmartyVars call without parameters */
|
||||
trigger_error(
|
||||
'Calling setSmartyVars without paramters is deprecated',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
}
|
||||
// set variables (will be deprecated)
|
||||
$compile_dir = $compile_dir ?? BASE . TEMPLATES_C;
|
||||
$cache_dir = $cache_dir ?? BASE . CACHE;
|
||||
$set_css = $set_css ?? CSS;
|
||||
$set_font = $set_font ?? FONT;
|
||||
$set_js = $set_js ?? JS;
|
||||
$set_default_encoding = $set_default_encoding ?? DEFAULT_ENCODING;
|
||||
$set_g_title = $set_g_title ?? G_TITLE;
|
||||
$set_admin_stylesheet = $set_admin_stylesheet ?? ADMIN_STYLESHEET;
|
||||
$set_admin_javascript = $set_admin_javascript ?? ADMIN_JAVASCRIPT;
|
||||
$set_page_width = $set_page_width ?? PAGE_WIDTH;
|
||||
$set_stylesheet = $set_stylesheet ?? STYLESHEET;
|
||||
$set_javascript = $set_javascript ?? JAVASCRIPT;
|
||||
$set_user_name = $set_user_name ?? $_SESSION['USER_NAME'] ?? '';
|
||||
// depreacte call globals cms on null 4mcs
|
||||
if (
|
||||
$cms === null &&
|
||||
isset($GLOBALS['cms'])
|
||||
) {
|
||||
/** @deprecated setSmartyVars globals cms is deprecated */
|
||||
trigger_error(
|
||||
'Calling setSmartyVars without cms parameter when needed is deprecated',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
}
|
||||
// this is ugly
|
||||
$cms = $cms ?? $GLOBALS['cms'] ?? null;
|
||||
if ($cms instanceof \CoreLibs\Admin\Backend) {
|
||||
$this->mergeCmsSmartyVars($cms);
|
||||
}
|
||||
|
||||
@@ -431,11 +671,11 @@ class SmartyExtend extends \Smarty
|
||||
|
||||
// default CMS settings
|
||||
// define all needed smarty stuff for the general HTML/page building
|
||||
$this->HEADER['CSS'] = CSS;
|
||||
$this->HEADER['FONT'] = FONT;
|
||||
$this->HEADER['JS'] = JS;
|
||||
$this->HEADER['CSS'] = $set_css;
|
||||
$this->HEADER['FONT'] = $set_font;
|
||||
$this->HEADER['JS'] = $set_js;
|
||||
$this->HEADER['ENCODING'] = $this->encoding;
|
||||
$this->HEADER['DEFAULT_ENCODING'] = DEFAULT_ENCODING;
|
||||
$this->HEADER['DEFAULT_ENCODING'] = $set_default_encoding;
|
||||
|
||||
// form name
|
||||
$this->DATA['FORM_NAME'] = !$this->FORM_NAME ?
|
||||
@@ -445,7 +685,7 @@ class SmartyExtend extends \Smarty
|
||||
// special for admin
|
||||
if ($admin_call === true) {
|
||||
// set ACL extra show
|
||||
if (is_object($cms)) {
|
||||
if ($cms instanceof \CoreLibs\Admin\Backend) {
|
||||
$this->DATA['show_ea_extra'] = $cms->acl['show_ea_extra'] ?? false;
|
||||
$this->DATA['ADMIN'] = $cms->acl['admin'] ?? 0;
|
||||
// top menu
|
||||
@@ -453,7 +693,7 @@ class SmartyExtend extends \Smarty
|
||||
$this->DATA['nav_menu_count'] = count($this->DATA['nav_menu']);
|
||||
// messages = ['msg' =>, 'class' => 'error/warning/...']
|
||||
$this->DATA['messages'] = $cms->messages;
|
||||
} else { /** @phpstan-ignore-line Because I assume object for phpstan */
|
||||
} else {
|
||||
$this->DATA['show_ea_extra'] = false;
|
||||
$this->DATA['ADMIN'] = 0;
|
||||
$this->DATA['nav_menu'] = [];
|
||||
@@ -461,11 +701,13 @@ class SmartyExtend extends \Smarty
|
||||
$this->DATA['messages'] = [];
|
||||
}
|
||||
// set style sheets
|
||||
$this->HEADER['STYLESHEET'] = $this->ADMIN_STYLESHEET ? $this->ADMIN_STYLESHEET : ADMIN_STYLESHEET;
|
||||
$this->HEADER['JAVASCRIPT'] = $this->ADMIN_JAVASCRIPT ? $this->ADMIN_JAVASCRIPT : ADMIN_JAVASCRIPT;
|
||||
$this->HEADER['STYLESHEET'] = !empty($this->ADMIN_STYLESHEET) ?
|
||||
$this->ADMIN_STYLESHEET : $set_admin_stylesheet;
|
||||
$this->HEADER['JAVASCRIPT'] = !empty($this->ADMIN_JAVASCRIPT) ?
|
||||
$this->ADMIN_JAVASCRIPT : $set_admin_javascript;
|
||||
// the page name
|
||||
$this->DATA['page_name'] = $this->page_name;
|
||||
$this->DATA['table_width'] = !empty($this->PAGE_WIDTH) ?: PAGE_WIDTH;
|
||||
$this->DATA['table_width'] = !empty($this->PAGE_WIDTH) ?: $set_page_width;
|
||||
$this->DATA['form_name'] = $this->DATA['FORM_NAME'];
|
||||
// for tinymce special
|
||||
$this->DATA['TINYMCE_LANG'] = $this->lang_short;
|
||||
@@ -474,14 +716,16 @@ class SmartyExtend extends \Smarty
|
||||
// debug data, if DEBUG flag is on, this data is print out
|
||||
$this->DEBUG_DATA['DEBUG'] = $this->DEBUG_TMPL;
|
||||
} else {
|
||||
$this->HEADER['STYLESHEET'] = $this->FRONTEND_STYLESHEET ? $this->FRONTEND_STYLESHEET : STYLESHEET;
|
||||
$this->HEADER['JAVASCRIPT'] = $this->FRONTEND_JAVASCRIPT ? $this->FRONTEND_JAVASCRIPT : JAVASCRIPT;
|
||||
$this->HEADER['STYLESHEET'] = !empty($this->FRONTEND_STYLESHEET) ?
|
||||
$this->FRONTEND_STYLESHEET : $set_stylesheet;
|
||||
$this->HEADER['JAVASCRIPT'] = !empty($this->FRONTEND_JAVASCRIPT) ?
|
||||
$this->FRONTEND_JAVASCRIPT : $set_javascript;
|
||||
}
|
||||
// html title
|
||||
// set local page title
|
||||
$this->HEADER['HTML_TITLE'] = !$this->L_TITLE ?
|
||||
ucfirst(str_replace('_', ' ', \CoreLibs\Get\System::getPageName(1)))
|
||||
. (defined('G_TITLE') ? ' - ' . $this->l10n->__(G_TITLE) : '') :
|
||||
. (!empty($set_g_title) ? '-' . $this->l10n->__($set_g_title) : '') :
|
||||
$this->l10n->__($this->L_TITLE);
|
||||
|
||||
// LANG
|
||||
@@ -491,7 +735,7 @@ class SmartyExtend extends \Smarty
|
||||
$this->DATA['JS_FLATPICKR'] = $this->JS_FLATPICKR;
|
||||
$this->DATA['JS_FILE_UPLOADER'] = $this->JS_FILE_UPLOADER;
|
||||
// user name
|
||||
$this->DATA['USER_NAME'] = !empty($_SESSION['USER_NAME']) ? $_SESSION['USER_NAME'] : '';
|
||||
$this->DATA['USER_NAME'] = $set_user_name;
|
||||
// the template part to include into the body
|
||||
$this->DATA['TEMPLATE_NAME'] = $this->TEMPLATE_NAME;
|
||||
$this->DATA['CONTENT_INCLUDE'] = $this->CONTENT_INCLUDE;
|
||||
@@ -499,16 +743,16 @@ class SmartyExtend extends \Smarty
|
||||
$this->DATA['JS_TRANSLATE'] = $this->JS_TRANSLATE ?? null;
|
||||
$this->DATA['PAGE_FILE_NAME'] = str_replace('.php', '', $this->page_name) . '.tpl';
|
||||
// render page
|
||||
$this->renderSmarty();
|
||||
$this->renderSmarty($compile_dir, $cache_dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* merge outside object HEADER/DATA/DEBUG_DATA vars into the smarty class
|
||||
*
|
||||
* @param object $cms object that has header/data/debug_data
|
||||
* @param \CoreLibs\Admin\Backend $cms object that has header/data/debug_data
|
||||
* @return void
|
||||
*/
|
||||
public function mergeCmsSmartyVars(object $cms): void
|
||||
public function mergeCmsSmartyVars(\CoreLibs\Admin\Backend $cms): void
|
||||
{
|
||||
// array merge HEADER, DATA, DEBUG DATA
|
||||
foreach (['HEADER', 'DATA', 'DEBUG_DATA'] as $ext_smarty) {
|
||||
@@ -524,21 +768,39 @@ class SmartyExtend extends \Smarty
|
||||
/**
|
||||
* render smarty data (can be called sepparate)
|
||||
*
|
||||
* @param string|null $compile_dir BASE . TEMPLATES_C
|
||||
* @param string|null $cache_dir BASE . CACHE
|
||||
* @return void
|
||||
*/
|
||||
public function renderSmarty(): void
|
||||
{
|
||||
public function renderSmarty(
|
||||
?string $compile_dir = null,
|
||||
?string $cache_dir = null
|
||||
): void {
|
||||
// trigger deprecation
|
||||
if (
|
||||
$compile_dir === null ||
|
||||
$cache_dir === null
|
||||
) {
|
||||
/** @deprecated renderSmarty call without parameters */
|
||||
trigger_error(
|
||||
'Calling renderSmarty without paramters is deprecated',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
}
|
||||
// set vars (to be deprecated)
|
||||
$compile_dir = $compile_dir ?? BASE . TEMPLATES_C;
|
||||
$cache_dir = $cache_dir ?? BASE . CACHE;
|
||||
// create main data array
|
||||
$this->CONTENT_DATA = array_merge($this->HEADER, $this->DATA, $this->DEBUG_DATA);
|
||||
// data is 1:1 mapping (all vars, values, etc)
|
||||
foreach ($this->CONTENT_DATA as $key => $value) {
|
||||
$this->assign($key, $value);
|
||||
}
|
||||
if (is_dir(BASE . TEMPLATES_C)) {
|
||||
$this->setCompileDir(BASE . TEMPLATES_C);
|
||||
if (is_dir($compile_dir)) {
|
||||
$this->setCompileDir($compile_dir);
|
||||
}
|
||||
if (is_dir(BASE . CACHE)) {
|
||||
$this->setCacheDir(BASE . CACHE);
|
||||
if (is_dir($cache_dir)) {
|
||||
$this->setCacheDir($cache_dir);
|
||||
}
|
||||
$this->display(
|
||||
$this->MASTER_TEMPLATE_NAME,
|
||||
|
||||
2
test/checking/phan.sh
Executable file
2
test/checking/phan.sh
Executable file
@@ -0,0 +1,2 @@
|
||||
base="/storage/var/www/html/developers/clemens/core_data/composer-packages/CoreLibs-Composer-All/";
|
||||
vendor/bin/phan --progress-bar -C --analyze-twice
|
||||
2
test/checking/phpstan.sh
Executable file
2
test/checking/phpstan.sh
Executable file
@@ -0,0 +1,2 @@
|
||||
base="/storage/var/www/html/developers/clemens/core_data/composer-packages/CoreLibs-Composer-All/";
|
||||
vendor/bin/phpstan
|
||||
46
test/checking/phpunit.sh
Executable file
46
test/checking/phpunit.sh
Executable file
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
base="/storage/var/www/html/developers/clemens/core_data/composer-packages/CoreLibs-Composer-All/";
|
||||
# -c phpunit.xml
|
||||
# --testdox
|
||||
# call with "t" to give verbose testdox output
|
||||
# SUPPORTED: https://www.php.net/supported-versions.php
|
||||
# call with php version number to force a certain php version
|
||||
|
||||
opt_testdox="";
|
||||
if [ "${1}" = "t" ] || [ "${2}" = "t" ]; then
|
||||
opt_testdox="--testdox";
|
||||
fi;
|
||||
php_bin="";
|
||||
if [ ! -z "${1}" ]; then
|
||||
case "${1}" in
|
||||
# "7.3") php_bin="/usr/bin/php7.3 "; ;;
|
||||
"7.4") php_bin="/usr/bin/php7.4 "; ;;
|
||||
"8.0") php_bin="/usr/bin/php8.0 "; ;;
|
||||
"8.1") php_bin="/usr/bin/php8.1 "; ;;
|
||||
"8.2") php_bin="/usr/bin/php8.2 "; ;;
|
||||
*) echo "Not support PHP: ${1}"; exit; ;;
|
||||
esac;
|
||||
fi;
|
||||
if [ ! -z "${2}" ] && [ -z "${php_bin}" ]; then
|
||||
case "${2}" in
|
||||
# "7.3") php_bin="/usr/bin/php7.3 "; ;;
|
||||
"7.4") php_bin="/usr/bin/php7.4 "; ;;
|
||||
"8.0") php_bin="/usr/bin/php8.0 "; ;;
|
||||
"8.1") php_bin="/usr/bin/php8.1 "; ;;
|
||||
"8.2") php_bin="/usr/bin/php8.2 "; ;;
|
||||
*) echo "Not support PHP: ${1}"; exit; ;;
|
||||
esac;
|
||||
fi;
|
||||
|
||||
phpunit_call="${php_bin}${base}vendor/bin/phpunit ${opt_testdox} -c ${base}phpunit.xml ${base}test/phpunit/";
|
||||
|
||||
${phpunit_call};
|
||||
|
||||
if [ ! -z "${php_bin}" ]; then
|
||||
echo "CALLED WITH PHP: ${php_bin}"$(${php_bin} --version);
|
||||
else
|
||||
echo "Default PHP used: "$(php --version);
|
||||
fi;
|
||||
|
||||
# __END__
|
||||
312
test/configs/config.master.php
Normal file
312
test/configs/config.master.php
Normal file
@@ -0,0 +1,312 @@
|
||||
<?php // phpcs:ignore PSR1.Files.SideEffects
|
||||
|
||||
/********************************************************************
|
||||
* AUTHOR: Clemens Schwaighofer
|
||||
* CREATED: 2003/06/10
|
||||
* SHORT DESCRIPTION:
|
||||
* configuration file
|
||||
* HISTORY:
|
||||
*********************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/************* PATHS *********************/
|
||||
// [DEPRECATED] directory seperator
|
||||
define('DS', DIRECTORY_SEPARATOR);
|
||||
// ** NEW/BETTER DIR DECLARATIONS **
|
||||
// path to original file (if symlink)
|
||||
define('DIR', __DIR__ . DIRECTORY_SEPARATOR);
|
||||
// base dir root folder level
|
||||
define('BASE', str_replace('/configs', '', __DIR__) . DIRECTORY_SEPARATOR);
|
||||
|
||||
// ** OLD DIR DECLARATIONS **
|
||||
// path to document root of file called
|
||||
define('ROOT', getcwd() . DIRECTORY_SEPARATOR);
|
||||
// libs path
|
||||
define('LIB', 'lib' . DIRECTORY_SEPARATOR);
|
||||
define('LIBS', 'lib' . DIRECTORY_SEPARATOR);
|
||||
// configs folder
|
||||
define('CONFIGS', 'configs' . DIRECTORY_SEPARATOR);
|
||||
// includes (strings, arrays for static, etc)
|
||||
define('INCLUDES', 'includes' . DIRECTORY_SEPARATOR);
|
||||
// data folder (mostly in includes, or root for internal data)
|
||||
define('DATA', 'data' . DIRECTORY_SEPARATOR);
|
||||
// layout base path
|
||||
define('LAYOUT', 'layout' . DIRECTORY_SEPARATOR);
|
||||
// pic-root (compatible to CMS)
|
||||
define('PICTURES', 'images' . DIRECTORY_SEPARATOR);
|
||||
// images
|
||||
define('IMAGES', 'images' . DIRECTORY_SEPARATOR);
|
||||
// icons (below the images/ folder)
|
||||
define('ICONS', 'icons' . DIRECTORY_SEPARATOR);
|
||||
// media (accessable from outside)
|
||||
define('MEDIA', 'media' . DIRECTORY_SEPARATOR);
|
||||
// uploads (anything to keep or data)
|
||||
define('UPLOADS', 'uploads' . DIRECTORY_SEPARATOR);
|
||||
// files (binaries) (below media or data)
|
||||
define('BINARIES', 'binaries' . DIRECTORY_SEPARATOR);
|
||||
// files (videos) (below media or data)
|
||||
define('VIDEOS', 'videos' . DIRECTORY_SEPARATOR);
|
||||
// files (documents) (below media or data)
|
||||
define('DOCUMENTS', 'documents' . DIRECTORY_SEPARATOR);
|
||||
// files (pdfs) (below media or data)
|
||||
define('PDFS', 'documents' . DIRECTORY_SEPARATOR);
|
||||
// files (general) (below media or data)
|
||||
define('FILES', 'files' . DIRECTORY_SEPARATOR);
|
||||
// CSV
|
||||
define('CSV', 'csv' . DIRECTORY_SEPARATOR);
|
||||
// css
|
||||
define('CSS', 'css' . DIRECTORY_SEPARATOR);
|
||||
// font (web)
|
||||
define('FONT', 'font' . DIRECTORY_SEPARATOR);
|
||||
// js
|
||||
define('JS', 'javascript' . DIRECTORY_SEPARATOR);
|
||||
// table arrays
|
||||
define('TABLE_ARRAYS', 'table_arrays' . DIRECTORY_SEPARATOR);
|
||||
// smarty libs path
|
||||
define('SMARTY', 'Smarty' . DIRECTORY_SEPARATOR);
|
||||
// po locale file
|
||||
define('LOCALE', 'locale' . DIRECTORY_SEPARATOR);
|
||||
// cache path
|
||||
define('CACHE', 'cache' . DIRECTORY_SEPARATOR);
|
||||
// temp path
|
||||
define('TMP', 'tmp' . DIRECTORY_SEPARATOR);
|
||||
// log files
|
||||
define('LOG', 'log' . DIRECTORY_SEPARATOR);
|
||||
// compiled template folder
|
||||
define('TEMPLATES_C', 'templates_c' . DIRECTORY_SEPARATOR);
|
||||
// template base
|
||||
define('TEMPLATES', 'templates' . DIRECTORY_SEPARATOR);
|
||||
|
||||
/************* HASH / ACL DEFAULT / ERROR SETTINGS / SMARTY *************/
|
||||
// default hash type
|
||||
define('DEFAULT_HASH', 'sha256');
|
||||
// default acl level
|
||||
define('DEFAULT_ACL_LEVEL', 80);
|
||||
// SSL host name
|
||||
// define('SSL_HOST', $_ENV['SSL_HOST'] ?? '');
|
||||
// error page strictness, Default is 3
|
||||
// 1: only show error page as the last mesure if really no mid & aid can be loaded and found at all
|
||||
// 2: if template not found, do not search, show error template
|
||||
// 3: if default template is not found, show error template, do not fall back to default tree
|
||||
// 4: very strict, even on normal fixable errors through error
|
||||
// define('ERROR_STRICT', 3);
|
||||
// allow page caching in general, set to 'false' if you do debugging or development!
|
||||
// define('ALLOW_SMARTY_CACHE', false);
|
||||
// cache life time, in second', default here is 2 days (172800s)
|
||||
// -1 is never expire cache
|
||||
// define('SMARTY_CACHE_LIFETIME', -1);
|
||||
|
||||
/************* LOGOUT ********************/
|
||||
// logout target
|
||||
define('LOGOUT_TARGET', '');
|
||||
// password change allowed
|
||||
define('PASSWORD_CHANGE', false);
|
||||
define('PASSWORD_FORGOT', false);
|
||||
// min/max password length
|
||||
define('PASSWORD_MIN_LENGTH', 9);
|
||||
define('PASSWORD_MAX_LENGTH', 255);
|
||||
// defines allowed special characters
|
||||
define('PASSWORD_SPECIAL_RANGE', '@$!%*?&');
|
||||
// password must have upper case, lower case, number, special
|
||||
// comment out for not mandatory
|
||||
define('PASSWORD_LOWER', '(?=.*[a-z])');
|
||||
define('PASSWORD_UPPER', '(?=.*[A-Z])');
|
||||
define('PASSWORD_NUMBER', '(?=.*\d)');
|
||||
define('PASSWORD_SPECIAL', "(?=.*[" . PASSWORD_SPECIAL_RANGE . "])");
|
||||
// define full regex
|
||||
define('PASSWORD_REGEX', "/^"
|
||||
. (defined('PASSWORD_LOWER') ? PASSWORD_LOWER : '')
|
||||
. (defined('PASSWORD_UPPER') ? PASSWORD_UPPER : '')
|
||||
. (defined('PASSWORD_NUMBER') ? PASSWORD_NUMBER : '')
|
||||
. (defined('PASSWORD_SPECIAL') ? PASSWORD_SPECIAL : '')
|
||||
. "[A-Za-z\d" . PASSWORD_SPECIAL_RANGE . "]{" . PASSWORD_MIN_LENGTH . "," . PASSWORD_MAX_LENGTH . "}$/");
|
||||
|
||||
/************* AJAX / ACCESS *************/
|
||||
// ajax request type
|
||||
define('AJAX_REQUEST_TYPE', 'POST');
|
||||
// what AJAX type to use
|
||||
define('USE_PROTOTYPE', false);
|
||||
define('USE_SCRIPTACULOUS', false);
|
||||
define('USE_JQUERY', true);
|
||||
|
||||
/************* LAYOUT WIDTHS *************/
|
||||
define('PAGE_WIDTH', '100%');
|
||||
define('CONTENT_WIDTH', '100%');
|
||||
// the default template name
|
||||
define('MASTER_TEMPLATE_NAME', 'main_body.tpl');
|
||||
|
||||
/************* OVERALL CONTROL NAMES *************/
|
||||
// BELOW has HAS to be changed
|
||||
// base name for all session and log names
|
||||
// only alphanumeric characters, strip all others
|
||||
define('BASE_NAME', preg_replace('/[^A-Za-z0-9]/', '', $_ENV['BASE_NAME'] ?? ''));
|
||||
|
||||
/************* SESSION NAMES *************/
|
||||
// server name HASH
|
||||
define('SERVER_NAME_HASH', hash('crc32b', $_SERVER['HTTP_HOST']));
|
||||
define('SERVER_PATH_HASH', hash('crc32b', BASE));
|
||||
// backend
|
||||
define('EDIT_SESSION_NAME', BASE_NAME . 'Admin' . SERVER_NAME_HASH . SERVER_PATH_HASH);
|
||||
// frontend
|
||||
define('SESSION_NAME', BASE_NAME . SERVER_NAME_HASH . SERVER_PATH_HASH);
|
||||
|
||||
/************* CACHE/COMPILE IDS *************/
|
||||
define('CACHE_ID', 'CACHE_' . BASE_NAME . '_' . SERVER_NAME_HASH);
|
||||
define('COMPILE_ID', 'COMPILE_' . BASE_NAME . '_' . SERVER_NAME_HASH);
|
||||
|
||||
/************* LANGUAGE / ENCODING *******/
|
||||
// default lang + encoding
|
||||
define('DEFAULT_LOCALE', 'en_US.UTF-8');
|
||||
// default web page encoding setting
|
||||
define('DEFAULT_ENCODING', 'UTF-8');
|
||||
|
||||
/************* LOGGING *******************/
|
||||
// below two can be defined here, but they should be
|
||||
// defined in either the header file or the file itself
|
||||
// as $LOG_FILE_ID which takes presence over LOG_FILE_ID
|
||||
// see Basic class constructor
|
||||
define('LOG_FILE_ID', BASE_NAME);
|
||||
|
||||
/************* QUEUE TABLE *************/
|
||||
// if we have a dev/live system
|
||||
// set_live is a per page/per item
|
||||
// live_queue is a global queue system
|
||||
// define('QUEUE', 'live_queue');
|
||||
|
||||
/************* DB PATHS (PostgreSQL) *****************/
|
||||
// schema names, can also be defined per <DB INFO>
|
||||
define('PUBLIC_SCHEMA', 'public');
|
||||
define('DEV_SCHEMA', 'public');
|
||||
define('TEST_SCHEMA', 'public');
|
||||
define('LIVE_SCHEMA', 'public');
|
||||
define('GLOBAL_DB_SCHEMA', '');
|
||||
define('LOGIN_DB_SCHEMA', '');
|
||||
|
||||
/************* CORE HOST SETTINGS *****************/
|
||||
if (file_exists(BASE . CONFIGS . 'config.host.php')) {
|
||||
require BASE . CONFIGS . 'config.host.php';
|
||||
}
|
||||
if (!isset($SITE_CONFIG)) {
|
||||
$SITE_CONFIG = [];
|
||||
}
|
||||
/************* DB ACCESS *****************/
|
||||
if (file_exists(BASE . CONFIGS . 'config.db.php')) {
|
||||
require BASE . CONFIGS . 'config.db.php';
|
||||
}
|
||||
if (!isset($DB_CONFIG)) {
|
||||
$DB_CONFIG = [];
|
||||
}
|
||||
/************* OTHER PATHS *****************/
|
||||
if (file_exists(BASE . CONFIGS . 'config.path.php')) {
|
||||
require BASE . CONFIGS . 'config.path.php';
|
||||
}
|
||||
|
||||
/************* MASTER INIT *****************/
|
||||
// live frontend pages
|
||||
// ** missing live domains **
|
||||
// get the name without the port
|
||||
list($HOST_NAME) = array_pad(explode(':', $_SERVER['HTTP_HOST'], 2), 2, null);
|
||||
// set HOST name
|
||||
define('HOST_NAME', $HOST_NAME);
|
||||
// BAIL ON MISSING MASTER SITE CONFIG
|
||||
if (!isset($SITE_CONFIG[HOST_NAME]['location'])) {
|
||||
echo 'Missing SITE_CONFIG entry for: "' . HOST_NAME . '". Contact Administrator';
|
||||
exit;
|
||||
}
|
||||
// BAIL ON MISSING DB CONFIG:
|
||||
// we have either no db selction for this host but have db config entries
|
||||
// or we have a db selection but no db config as array or empty
|
||||
// or we have a selection but no matching db config entry
|
||||
if (
|
||||
(!isset($SITE_CONFIG[HOST_NAME]['db_host']) && count($DB_CONFIG)) ||
|
||||
(isset($SITE_CONFIG[HOST_NAME]['db_host']) &&
|
||||
// missing DB CONFIG
|
||||
((is_array($DB_CONFIG) && !count($DB_CONFIG)) ||
|
||||
!is_array($DB_CONFIG) ||
|
||||
// has DB CONFIG but no match
|
||||
empty($DB_CONFIG[$SITE_CONFIG[HOST_NAME]['db_host']]))
|
||||
)
|
||||
) {
|
||||
echo 'No matching DB config found for: "' . HOST_NAME . '". Contact Administrator';
|
||||
exit;
|
||||
}
|
||||
// set SSL on
|
||||
$is_secure = false;
|
||||
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
|
||||
$is_secure = true;
|
||||
} elseif (
|
||||
!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' ||
|
||||
!empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on'
|
||||
) {
|
||||
$is_secure = true;
|
||||
}
|
||||
if ($is_secure) {
|
||||
define('HOST_SSL', true);
|
||||
define('HOST_PROTOCOL', 'https://');
|
||||
} else {
|
||||
define('HOST_SSL', false);
|
||||
define('HOST_PROTOCOL', 'http://');
|
||||
}
|
||||
// define the db config set name, the db config and the db schema
|
||||
define('DB_CONFIG_NAME', $SITE_CONFIG[HOST_NAME]['db_host'] ?? '');
|
||||
define('DB_CONFIG', $DB_CONFIG[DB_CONFIG_NAME] ?? []);
|
||||
// because we can't change constant, but we want to for db debug flag
|
||||
$GLOBALS['DB_CONFIG_SET'] = DB_CONFIG;
|
||||
// define('DB_CONFIG_TARGET', SITE_CONFIG[$HOST_NAME]['db_host_target']);
|
||||
// define('DB_CONFIG_OTHER', SITE_CONFIG[$HOST_NAME]['db_host_other']);
|
||||
// override for login and global schemas
|
||||
// where the edit* tables are
|
||||
// define('LOGIN_DB_SCHEMA', PUBLIC_SCHEMA);
|
||||
// where global tables are that are used by all schemas (eg queue tables for online, etc)
|
||||
// define('GLOBAL_DB_SCHEMA', PUBLIC_SCHEMA);
|
||||
// debug settings, site lang, etc
|
||||
define('TARGET', $SITE_CONFIG[HOST_NAME]['location'] ?? 'test');
|
||||
define('DEBUG', $SITE_CONFIG[HOST_NAME]['debug_flag'] ?? false);
|
||||
define('SITE_LOCALE', $SITE_CONFIG[HOST_NAME]['site_locale'] ?? DEFAULT_LOCALE);
|
||||
define('SITE_ENCODING', $SITE_CONFIG[HOST_NAME]['site_encoding'] ?? DEFAULT_ENCODING);
|
||||
define('LOGIN_ENABLED', $SITE_CONFIG[HOST_NAME]['login_enabled'] ?? false);
|
||||
define('AUTH', $SITE_CONFIG[HOST_NAME]['auth'] ?? false);
|
||||
// paths
|
||||
// define('CSV_PATH', $PATHS[TARGET]['csv_path'] ?? '');
|
||||
// define('EXPORT_SCRIPT', $PATHS[TARGET]['perl_bin'] ?? '');
|
||||
// define('REDIRECT_URL', $PATHS[TARGET]['redirect_url'] ?? '');
|
||||
|
||||
// show all errors if debug_all & show_error_handling are enabled
|
||||
define('SHOW_ALL_ERRORS', true);
|
||||
|
||||
/************* GENERAL PAGE TITLE ********/
|
||||
define('G_TITLE', $_ENV['G_TITLE'] ?? '');
|
||||
|
||||
/************ STYLE SHEETS / JS **********/
|
||||
define('ADMIN_STYLESHEET', 'edit.css');
|
||||
define('ADMIN_JAVASCRIPT', 'edit.js');
|
||||
define('STYLESHEET', $_ENV['STYLESHEET'] ?? 'frontend.css');
|
||||
define('JAVASCRIPT', $_ENV['JAVASCRIPT'] ?? 'frontend.js');
|
||||
|
||||
// anything optional
|
||||
/************* INTERNAL ******************/
|
||||
// any other global definitons in the config.other.php
|
||||
if (file_exists(BASE . CONFIGS . 'config.other.php')) {
|
||||
require BASE . CONFIGS . 'config.other.php';
|
||||
}
|
||||
|
||||
/************* DEBUG *******************/
|
||||
// turn off debug if debug flag is OFF
|
||||
if (defined('DEBUG') && DEBUG == false) {
|
||||
$ECHO_ALL = false;
|
||||
$DEBUG_ALL = false;
|
||||
$PRINT_ALL = false;
|
||||
$DB_DEBUG = false;
|
||||
$ENABLE_ERROR_HANDLING = false;
|
||||
$DEBUG_ALL_OVERRIDE = false;
|
||||
} else {
|
||||
$ECHO_ALL = false;
|
||||
$DEBUG_ALL = true;
|
||||
$PRINT_ALL = true;
|
||||
$DB_DEBUG = true;
|
||||
$ENABLE_ERROR_HANDLING = false;
|
||||
$DEBUG_ALL_OVERRIDE = false;
|
||||
}
|
||||
|
||||
// __END__
|
||||
35
test/configs/config.other.php
Normal file
35
test/configs/config.other.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php // phpcs:ignore PSR1.Files.SideEffects
|
||||
|
||||
/********************************************************************
|
||||
* AUTHOR: Clemens Schwaighofer
|
||||
* CREATED: 2019/10/28
|
||||
* SHORT DESCRIPTION:
|
||||
* other global constant variables
|
||||
* HISTORY:
|
||||
*********************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
// define('SOME_ID', <SOME VALUE>);
|
||||
|
||||
/************* CONVERT *******************/
|
||||
// this only needed if the external thumbnail create is used
|
||||
$paths = [
|
||||
'/bin',
|
||||
'/usr/bin',
|
||||
'/usr/local/bin',
|
||||
];
|
||||
// find convert
|
||||
foreach ($paths as $path) {
|
||||
if (
|
||||
file_exists($path . DIRECTORY_SEPARATOR . 'convert') &&
|
||||
is_file($path . DIRECTORY_SEPARATOR . 'convert')
|
||||
) {
|
||||
// image magick convert location
|
||||
define('CONVERT', $path . DIRECTORY_SEPARATOR . 'convert');
|
||||
break;
|
||||
}
|
||||
}
|
||||
unset($paths);
|
||||
|
||||
// __END__
|
||||
79
test/configs/config.php
Normal file
79
test/configs/config.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php // phpcs:ignore warning
|
||||
|
||||
/********************************************************************
|
||||
* AUTHOR: Clemens Schwaighofer
|
||||
* CREATED: 2018/10/11
|
||||
* SHORT DESCRIPTION:
|
||||
* pre config included -> includes master config
|
||||
* HISTORY:
|
||||
*********************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
define('CONFIG_PATH', 'configs' . DIRECTORY_SEPARATOR);
|
||||
// config path prefix search, start with 0, got down each level __DIR__ has,
|
||||
// if nothing found -> bail
|
||||
$CONFIG_PATH_PREFIX = '';
|
||||
// base path for loads
|
||||
$__DIR__PATH = __DIR__ . DIRECTORY_SEPARATOR;
|
||||
// don't load autoloader twice
|
||||
$end_autoload = false;
|
||||
for (
|
||||
$dir_pos = 0, $dir_max = count(explode(DIRECTORY_SEPARATOR, __DIR__));
|
||||
$dir_pos <= $dir_max;
|
||||
$dir_pos++
|
||||
) {
|
||||
$CONFIG_PATH_PREFIX .= '..' . DIRECTORY_SEPARATOR;
|
||||
if ($end_autoload === false) {
|
||||
/************* AUTO LOADER *******************/
|
||||
// composer auto loader, in composer.json file add classmap for lib/:
|
||||
// "autoload": {
|
||||
// "classmap": [
|
||||
// "lib/"
|
||||
// ]
|
||||
// },
|
||||
// NOTE: MUST RUN composer dump-autoload if file/class names are
|
||||
// changed or new ones are added
|
||||
if (
|
||||
is_file(
|
||||
$__DIR__PATH . $CONFIG_PATH_PREFIX
|
||||
. 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php'
|
||||
)
|
||||
) {
|
||||
require $__DIR__PATH . $CONFIG_PATH_PREFIX
|
||||
. 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
|
||||
$end_autoload = true;
|
||||
}
|
||||
}
|
||||
/************* MASTER CONFIG *******************/
|
||||
if (
|
||||
is_file($__DIR__PATH . $CONFIG_PATH_PREFIX . CONFIG_PATH . 'config.master.php')
|
||||
) {
|
||||
// load enviorment file if it exists
|
||||
\gullevek\dotEnv\DotEnv::readEnvFile(
|
||||
$__DIR__PATH . $CONFIG_PATH_PREFIX . CONFIG_PATH
|
||||
);
|
||||
// find trigger name "admin/" or "frontend/" in the getcwd() folder
|
||||
$folder = '';
|
||||
foreach (['admin', 'frontend'] as $_folder) {
|
||||
if (strstr(getcwd() ?: '', DIRECTORY_SEPARATOR . $_folder)) {
|
||||
$folder = $_folder;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// if content path is empty, fallback is default
|
||||
if (empty($folder)) {
|
||||
$folder = 'default';
|
||||
}
|
||||
define('CONTENT_PATH', $folder . DIRECTORY_SEPARATOR);
|
||||
// load master config file that loads all other config files
|
||||
require $__DIR__PATH . $CONFIG_PATH_PREFIX . CONFIG_PATH . 'config.master.php';
|
||||
break;
|
||||
}
|
||||
}
|
||||
// fail if no base DIR is not set
|
||||
if (!defined('DIR')) {
|
||||
exit('Base config could not be loaded');
|
||||
}
|
||||
|
||||
// __END__
|
||||
40
test/phpunit/AAASetupData/CoreLibsAAASetupDataTest.php
Normal file
40
test/phpunit/AAASetupData/CoreLibsAAASetupDataTest.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test base setup
|
||||
* @testdox AAASetupData\AAASetupDataTest just setup BASE
|
||||
*/
|
||||
final class CoreLibsAAASetupDataTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Covers nothing
|
||||
*
|
||||
* @testdox Just setup BASE
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetupData(): void
|
||||
{
|
||||
if (!defined('BASE')) {
|
||||
define(
|
||||
'BASE',
|
||||
str_replace('/configs', '', __DIR__)
|
||||
. DIRECTORY_SEPARATOR
|
||||
);
|
||||
}
|
||||
$this->assertEquals(
|
||||
str_replace('/configs', '', __DIR__)
|
||||
. DIRECTORY_SEPARATOR,
|
||||
BASE,
|
||||
'BASE Path set check'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
1
test/phpunit/AAASetupData/includes
Symbolic link
1
test/phpunit/AAASetupData/includes
Symbolic link
@@ -0,0 +1 @@
|
||||
../Language/includes/
|
||||
1
test/phpunit/AAASetupData/log
Symbolic link
1
test/phpunit/AAASetupData/log
Symbolic link
@@ -0,0 +1 @@
|
||||
../Debug/log/
|
||||
2137
test/phpunit/ACL/CoreLibsACLLoginTest.php
Normal file
2137
test/phpunit/ACL/CoreLibsACLLoginTest.php
Normal file
File diff suppressed because it is too large
Load Diff
52
test/phpunit/ACL/CoreLibsACLLogin_database_prepare.sh
Executable file
52
test/phpunit/ACL/CoreLibsACLLogin_database_prepare.sh
Executable file
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# note: there is currently no port selection, standard 5432 port is assumed
|
||||
# note: we use the default in path postgresql commands and connect to whatever default DB is set
|
||||
|
||||
# PARAMETER 1: database data file to load
|
||||
# PARAMETER 2: db user WHO MUST BE ABLE TO CREATE A DATABASE
|
||||
# PARAMETER 3: db name
|
||||
# PARAMETER 4: db host
|
||||
# PARAMETER 5: print out for testing
|
||||
|
||||
load_sql="${1}";
|
||||
# abort with 1 if we cannot find the file
|
||||
if [ ! -f "${load_sql}" ]; then
|
||||
echo 1;
|
||||
exit 1;
|
||||
fi;
|
||||
db_user="${2}";
|
||||
db_name="${3}";
|
||||
db_host="${4}";
|
||||
# empty db name or db user -> exit with 2
|
||||
if [ -z "${db_user}" ] || [ -z "${db_name}" ] || [ -z "${db_host}" ]; then
|
||||
echo 2;
|
||||
exit 2;
|
||||
fi;
|
||||
# drop database, on error exit with 3
|
||||
dropdb -U ${db_user} -h ${db_host} ${db_name} 2>&1;
|
||||
if [ $? -ne 0 ]; then
|
||||
echo 3;
|
||||
exit 3;
|
||||
fi;
|
||||
# create database, on error exit with 4
|
||||
createdb -U ${db_user} -O ${db_user} -h ${db_host} -E utf8 ${db_name} 2>&1;
|
||||
if [ $? -ne 0 ]; then
|
||||
echo 4;
|
||||
exit 4;
|
||||
fi;
|
||||
# if error 5 thrown, test with enabled below
|
||||
if [ ! -z "${5}" ]; then
|
||||
psql -U ${db_user} -h ${db_host} -f ${load_sql} ${db_name};
|
||||
else
|
||||
# load data (redirect ALL error to null), on error exit with 5
|
||||
psql -U ${db_user} -h ${db_host} -f ${load_sql} ${db_name} 2>&1 1>/dev/null 2>/dev/null;
|
||||
fi;
|
||||
if [ $? -ne 0 ]; then
|
||||
echo 5;
|
||||
exit 5;
|
||||
fi;
|
||||
echo 0;
|
||||
exit 0;
|
||||
|
||||
# __END__
|
||||
1031
test/phpunit/ACL/database/CoreLibsACLLogin_database_create_data.sql
Normal file
1031
test/phpunit/ACL/database/CoreLibsACLLogin_database_create_data.sql
Normal file
File diff suppressed because it is too large
Load Diff
1
test/phpunit/ACL/includes
Symbolic link
1
test/phpunit/ACL/includes
Symbolic link
@@ -0,0 +1 @@
|
||||
../AAASetupData/includes
|
||||
3
test/phpunit/ACL/log/.gitignore
vendored
Normal file
3
test/phpunit/ACL/log/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
*log
|
||||
*LOG
|
||||
!.gitignore
|
||||
47
test/phpunit/Admin/CoreLibsAdminBackendTest.php
Normal file
47
test/phpunit/Admin/CoreLibsAdminBackendTest.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Admin\Backend
|
||||
* @coversDefaultClass \CoreLibs\Admin\Backend
|
||||
* @testdox \CoreLibs\Admin\Backend method tests
|
||||
*/
|
||||
final class CoreLibsAdminBackendTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
if (!extension_loaded('pgsql')) {
|
||||
$this->markTestSkipped(
|
||||
'The PgSQL extension is not available.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @testdox Admin\Backend Class tests
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAdminBackend()
|
||||
{
|
||||
/* $this->assertTrue(true, 'ACL Login Tests not implemented');
|
||||
$this->markTestIncomplete(
|
||||
'ACL\Login Tests have not yet been implemented'
|
||||
); */
|
||||
$this->markTestSkipped('No implementation for Admin\Backend at the moment');
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
47
test/phpunit/Admin/CoreLibsAdminEditPageTest.php
Normal file
47
test/phpunit/Admin/CoreLibsAdminEditPageTest.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Admin\EditPage
|
||||
* @coversDefaultClass \CoreLibs\Admin\EditPage
|
||||
* @testdox \CoreLibs\Admin\EditPage method tests
|
||||
*/
|
||||
final class CoreLibsAdminEditPageTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
if (!extension_loaded('pgsql')) {
|
||||
$this->markTestSkipped(
|
||||
'The PgSQL extension is not available.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @testdox Admin\EditPage Class tests
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAdminEditPage()
|
||||
{
|
||||
/* $this->assertTrue(true, 'ACL Login Tests not implemented');
|
||||
$this->markTestIncomplete(
|
||||
'ACL\Login Tests have not yet been implemented'
|
||||
); */
|
||||
$this->markTestSkipped('No implementation for Admin\EditPage at the moment');
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
329
test/phpunit/Check/CoreLibsCheckColorsTest.php
Normal file
329
test/phpunit/Check/CoreLibsCheckColorsTest.php
Normal file
@@ -0,0 +1,329 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Check\Colors
|
||||
* @coversDefaultClass \CoreLibs\Check\Colors
|
||||
* @testdox \CoreLibs\Check\Colors method tests
|
||||
*/
|
||||
final class CoreLibsCheckColorsTest extends TestCase
|
||||
{
|
||||
public function validateColorProvider(): array
|
||||
{
|
||||
/*
|
||||
0: input color string
|
||||
1: flag (or flags to set)
|
||||
2: expected result (bool)
|
||||
*/
|
||||
return [
|
||||
// * hex
|
||||
'valid hex rgb, flag ALL (default)' => [
|
||||
'#ab12cd',
|
||||
null,
|
||||
true,
|
||||
],
|
||||
'valid hex rgb, flag ALL' => [
|
||||
'#ab12cd',
|
||||
\CoreLibs\Check\Colors::ALL,
|
||||
true,
|
||||
],
|
||||
'valid hex rgb, flag HEX_RGB' => [
|
||||
'#ab12cd',
|
||||
\CoreLibs\Check\Colors::HEX_RGB,
|
||||
true,
|
||||
],
|
||||
'valid hex rgb, wrong flag' => [
|
||||
'#ab12cd',
|
||||
\CoreLibs\Check\Colors::RGB,
|
||||
false,
|
||||
],
|
||||
// error
|
||||
'invalid hex rgb A' => [
|
||||
'#ab12zz',
|
||||
null,
|
||||
false,
|
||||
],
|
||||
'invalid hex rgb B' => [
|
||||
'#ZyQfo',
|
||||
null,
|
||||
false,
|
||||
],
|
||||
// other valid hex checks
|
||||
'valid hex rgb, alt A' => [
|
||||
'#AB12cd',
|
||||
null,
|
||||
true,
|
||||
],
|
||||
// * hax alpha
|
||||
'valid hex rgb alpha, flag ALL (default)' => [
|
||||
'#ab12cd12',
|
||||
null,
|
||||
true,
|
||||
],
|
||||
'valid hex rgb alpha, flag ALL' => [
|
||||
'#ab12cd12',
|
||||
\CoreLibs\Check\Colors::ALL,
|
||||
true,
|
||||
],
|
||||
'valid hex rgb alpha, flag HEX_RGBA' => [
|
||||
'#ab12cd12',
|
||||
\CoreLibs\Check\Colors::HEX_RGBA,
|
||||
true,
|
||||
],
|
||||
'valid hex rgb alpha, wrong flag' => [
|
||||
'#ab12cd12',
|
||||
\CoreLibs\Check\Colors::RGB,
|
||||
false,
|
||||
],
|
||||
// error
|
||||
'invalid hex rgb alpha A' => [
|
||||
'#ab12dd1',
|
||||
null,
|
||||
false,
|
||||
],
|
||||
'invalid hex rgb alpha B' => [
|
||||
'#ab12ddzz',
|
||||
null,
|
||||
false,
|
||||
],
|
||||
'valid hex rgb alpha, alt A' => [
|
||||
'#ab12cdEE',
|
||||
null,
|
||||
true,
|
||||
],
|
||||
// * rgb
|
||||
'valid rgb, flag ALL (default)' => [
|
||||
'rgb(255, 10, 20)',
|
||||
null,
|
||||
true,
|
||||
],
|
||||
'valid rgb, flag ALL' => [
|
||||
'rgb(255, 10, 20)',
|
||||
\CoreLibs\Check\Colors::ALL,
|
||||
true,
|
||||
],
|
||||
'valid rgb, flag RGB' => [
|
||||
'rgb(255, 10, 20)',
|
||||
\CoreLibs\Check\Colors::RGB,
|
||||
true,
|
||||
],
|
||||
'valid rgb, wrong flag' => [
|
||||
'rgb(255, 10, 20)',
|
||||
\CoreLibs\Check\Colors::HEX_RGB,
|
||||
false,
|
||||
],
|
||||
// error
|
||||
'invalid rgb A' => [
|
||||
'rgb(356, 10, 20)',
|
||||
null,
|
||||
false,
|
||||
],
|
||||
// other valid rgb conbinations
|
||||
'valid rgb, alt A (percent)' => [
|
||||
'rgb(100%, 10%, 20%)',
|
||||
null,
|
||||
true,
|
||||
],
|
||||
// TODO check all % and non percent combinations
|
||||
'valid rgb, alt B (percent, mix)' => [
|
||||
'rgb(100%, 10, 40)',
|
||||
null,
|
||||
true,
|
||||
],
|
||||
// * rgb alpha
|
||||
'valid rgba, flag ALL (default)' => [
|
||||
'rgba(255, 10, 20, 0.5)',
|
||||
null,
|
||||
true,
|
||||
],
|
||||
'valid rgba, flag ALL' => [
|
||||
'rgba(255, 10, 20, 0.5)',
|
||||
\CoreLibs\Check\Colors::ALL,
|
||||
true,
|
||||
],
|
||||
'valid rgba, flag RGB' => [
|
||||
'rgba(255, 10, 20, 0.5)',
|
||||
\CoreLibs\Check\Colors::RGBA,
|
||||
true,
|
||||
],
|
||||
'valid rgba, wrong flag' => [
|
||||
'rgba(255, 10, 20, 0.5)',
|
||||
\CoreLibs\Check\Colors::HEX_RGB,
|
||||
false,
|
||||
],
|
||||
// error
|
||||
'invalid rgba A' => [
|
||||
'rgba(356, 10, 20, 0.5)',
|
||||
null,
|
||||
false,
|
||||
],
|
||||
// other valid rgba combinations
|
||||
'valid rgba, alt A (percent)' => [
|
||||
'rgba(100%, 10%, 20%, 0.5)',
|
||||
null,
|
||||
true,
|
||||
],
|
||||
// TODO check all % and non percent combinations
|
||||
'valid rgba, alt B (percent, mix)' => [
|
||||
'rgba(100%, 10, 40, 0.5)',
|
||||
null,
|
||||
true,
|
||||
],
|
||||
// TODO check all % and non percent combinations with percent transparent
|
||||
'valid rgba, alt C (percent transparent)' => [
|
||||
'rgba(100%, 10%, 20%, 50%)',
|
||||
null,
|
||||
true,
|
||||
],
|
||||
/*
|
||||
// hsl
|
||||
'hsl(100, 50%, 60%)',
|
||||
'hsl(100, 50.5%, 60.5%)',
|
||||
'hsla(100, 50%, 60%)',
|
||||
'hsla(100, 50.5%, 60.5%)',
|
||||
'hsla(100, 50%, 60%, 0.5)',
|
||||
'hsla(100, 50.5%, 60.5%, 0.5)',
|
||||
'hsla(100, 50%, 60%, 50%)',
|
||||
'hsla(100, 50.5%, 60.5%, 50%)',
|
||||
*/
|
||||
// * hsl
|
||||
'valid hsl, flag ALL (default)' => [
|
||||
'hsl(100, 50%, 60%)',
|
||||
null,
|
||||
true,
|
||||
],
|
||||
'valid hsl, flag ALL' => [
|
||||
'hsl(100, 50%, 60%)',
|
||||
\CoreLibs\Check\Colors::ALL,
|
||||
true,
|
||||
],
|
||||
'valid hsl, flag RGB' => [
|
||||
'hsl(100, 50%, 60%)',
|
||||
\CoreLibs\Check\Colors::HSL,
|
||||
true,
|
||||
],
|
||||
'valid hsl, wrong flag' => [
|
||||
'hsl(100, 50%, 60%)',
|
||||
\CoreLibs\Check\Colors::HEX_RGB,
|
||||
false,
|
||||
],
|
||||
'invalid hsl A' => [
|
||||
'hsl(500, 50%, 60%)',
|
||||
null,
|
||||
false,
|
||||
],
|
||||
'valid hsl, alt A' => [
|
||||
'hsl(100, 50.5%, 60.5%)',
|
||||
null,
|
||||
true,
|
||||
],
|
||||
// * hsl alpha
|
||||
'valid hsla, flag ALL (default)' => [
|
||||
'hsla(100, 50%, 60%, 0.5)',
|
||||
null,
|
||||
true,
|
||||
],
|
||||
'valid hsla, flag ALL' => [
|
||||
'hsla(100, 50%, 60%, 0.5)',
|
||||
\CoreLibs\Check\Colors::ALL,
|
||||
true,
|
||||
],
|
||||
'valid hsla, flag RGB' => [
|
||||
'hsla(100, 50%, 60%, 0.5)',
|
||||
\CoreLibs\Check\Colors::HSLA,
|
||||
true,
|
||||
],
|
||||
'valid hsla, wrong flag' => [
|
||||
'hsla(100, 50%, 60%, 0.5)',
|
||||
\CoreLibs\Check\Colors::HEX_RGB,
|
||||
false,
|
||||
],
|
||||
'invalid hsla A' => [
|
||||
'hsla(500, 50%, 60%, 0.5)',
|
||||
null,
|
||||
false,
|
||||
],
|
||||
'valid hsla, alt A (percent alpha' => [
|
||||
'hsla(100, 50%, 60%, 50%)',
|
||||
null,
|
||||
true,
|
||||
],
|
||||
'valid hsla, alt A (percent alpha' => [
|
||||
'hsla(100, 50.5%, 60.5%, 50%)',
|
||||
null,
|
||||
true,
|
||||
],
|
||||
// * combined flag checks
|
||||
'valid rgb, flag RGB|RGBA' => [
|
||||
'rgb(100%, 10%, 20%)',
|
||||
\CoreLibs\Check\Colors::RGB | \CoreLibs\Check\Colors::RGBA,
|
||||
true,
|
||||
],
|
||||
// TODO other combined flag checks all combinations
|
||||
// * invalid string
|
||||
'invalid string A' => [
|
||||
'invalid string',
|
||||
null,
|
||||
false,
|
||||
],
|
||||
'invalid string B' => [
|
||||
'(hsla(100, 100, 100))',
|
||||
null,
|
||||
false,
|
||||
],
|
||||
'invalid string C' => [
|
||||
'hsla(100, 100, 100',
|
||||
null,
|
||||
false,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::validateColor
|
||||
* @dataProvider validateColorProvider
|
||||
* @testdox validateColor $input with flags $flags be $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param int|null $flags
|
||||
* @param bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testValidateColor(string $input, ?int $flags, bool $expected)
|
||||
{
|
||||
if ($flags === null) {
|
||||
$result = \CoreLibs\Check\Colors::validateColor($input);
|
||||
} else {
|
||||
$result = \CoreLibs\Check\Colors::validateColor($input, $flags);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$result
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::validateColor
|
||||
* @testWith [99]
|
||||
* @testdox Check Exception throw for $flag
|
||||
*
|
||||
* @param int $flag
|
||||
* @return void
|
||||
*/
|
||||
public function testValidateColorException(int $flag): void
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
\CoreLibs\Check\Colors::validateColor('#ffffff', $flag);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
381
test/phpunit/Check/CoreLibsCheckEmailTest.php
Normal file
381
test/phpunit/Check/CoreLibsCheckEmailTest.php
Normal file
@@ -0,0 +1,381 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Undocumented class
|
||||
* @coversDefaultClass \CoreLibs\Check\Email
|
||||
* @testdox \CoreLibs\Check\Email method tests
|
||||
*/
|
||||
final class CoreLibsCheckEmailTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Array position to regex
|
||||
*
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function emailRegexProvider(): array
|
||||
{
|
||||
return [
|
||||
'get email regex invalid -1, will be 0' => [
|
||||
-1,
|
||||
"^[A-Za-z0-9!#$%&'*+\-\/=?^_`{|}~][A-Za-z0-9!#$%:\(\)&'*+\-\/=?^_`{|}~\.]{0,63}@"
|
||||
. "[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]{1,})*\.([a-zA-Z]{2,}){1}$"
|
||||
],
|
||||
'get email regex invalid 10, will be 0' => [
|
||||
10,
|
||||
"^[A-Za-z0-9!#$%&'*+\-\/=?^_`{|}~][A-Za-z0-9!#$%:\(\)&'*+\-\/=?^_`{|}~\.]{0,63}@"
|
||||
. "[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]{1,})*\.([a-zA-Z]{2,}){1}$"
|
||||
],
|
||||
'get email regex valid 1, will be 1' => [
|
||||
1,
|
||||
"@(.*)@(.*)"
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test regex level return
|
||||
*
|
||||
* @covers ::getEmailRegex
|
||||
* @dataProvider emailRegexProvider
|
||||
* @testdox getEmailRegex $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param int $input
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testGetEmailRegexReturn(int $input, string $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Check\Email::getEmailRegex($input)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* provides data for emailCheckProvider and emailCheckFullProvider
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function emailCheckList(): array
|
||||
{
|
||||
return [
|
||||
'valid email' => ['test@test.com', true, []],
|
||||
'invalid empty email' => ['', false, [0, 2, 3, 4, 5]],
|
||||
'invalid email' => ['-@-', false, [0, 3, 4, 5]],
|
||||
'invalid email leading dot' => ['.test@test.com', false, [0, 2]],
|
||||
'invalid email invalid domain' => ['test@t_est.com', false, [0, 3, 4]],
|
||||
'invalid email double @' => ['test@@test.com', false, [0, 1]],
|
||||
'invalid email double dot' => ['test@test..com', false, [0, 3, 6]],
|
||||
'invalid email end with dot' => ['test@test.', false, [0, 3, 5, 7]],
|
||||
'invalid email bad top level' => ['test@test.j', false, [0, 3, 5]],
|
||||
'invalid email double @ and double dot' => ['test@@test..com', false, [0, 1, 3, 6]],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Valids or not valid email address
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function emailCheckProvider(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->emailCheckList() as $key => $data) {
|
||||
$list[$key] = [$data[0], $data[1]];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::checkEmail
|
||||
* @dataProvider emailCheckProvider
|
||||
* @testdox checkEmail $input will be $expected [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCheckEmail(string $input, bool $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Check\Email::checkEmail($input)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* this is like emailCheckProvider but it has the full detail errors
|
||||
* All errors should be tetsed in testGetEmailRegexErrorMessage
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function emailCheckFullProvider(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->emailCheckList() as $key => $data) {
|
||||
$list[$key] = [$data[0], $data[2]];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::checkEmailFull
|
||||
* @dataProvider emailCheckFullProvider
|
||||
* @testdox checkEmailFull $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param array $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testCheckEmailFull(string $input, array $expected): void
|
||||
{
|
||||
$this->assertEqualsCanonicalizing(
|
||||
$expected,
|
||||
\CoreLibs\Check\Email::checkEmailFull($input, true)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* error data returned for each error position
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function emailRegexErrorProvider(): array
|
||||
{
|
||||
return [
|
||||
'error 0 will return general' => [
|
||||
0,
|
||||
[
|
||||
'error' => 0,
|
||||
'message' => 'Invalid email address',
|
||||
'regex' => "^[A-Za-z0-9!#$%&'*+\-\/=?^_`{|}~][A-Za-z0-9!#$%:\(\)&'*+\-\/=?^_`{|}~\.]{0,63}@"
|
||||
. "[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]{1,})*\.([a-zA-Z]{2,}){1}$"
|
||||
]
|
||||
],
|
||||
'error 1 will return double @ error' => [
|
||||
1,
|
||||
[
|
||||
'error' => 1,
|
||||
'message' => 'Double @ mark in email address',
|
||||
'regex' => "@(.*)@(.*)"
|
||||
]
|
||||
],
|
||||
'error 2 will be invalid before @' => [
|
||||
2,
|
||||
[
|
||||
'error' => 2,
|
||||
'message' => 'Invalid email part before @ sign',
|
||||
'regex' => "^[A-Za-z0-9!#$%&'*+\-\/=?^_`{|}~][A-Za-z0-9!#$%:\(\)&'*+\-\/=?^_`{|}~\.]{0,63}@"
|
||||
]
|
||||
],
|
||||
'error 3 will be invalid domain and top level' => [
|
||||
3,
|
||||
[
|
||||
'error' => 3,
|
||||
'message' => 'Invalid domain part after @ sign',
|
||||
'regex' => "@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]{1,})*\.([a-zA-Z]{2,}){1}$"
|
||||
]
|
||||
],
|
||||
'error 4 will be invalid domain' => [
|
||||
4,
|
||||
[
|
||||
'error' => 4,
|
||||
'message' => 'Invalid domain name part',
|
||||
'regex' => "@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]{1,})*\."
|
||||
]
|
||||
],
|
||||
'error 5 will be invalid domain top level only' => [
|
||||
5,
|
||||
[
|
||||
'error' => 5,
|
||||
'message' => 'Wrong domain top level part',
|
||||
'regex' => "\.([a-zA-Z]{2,6}){1}$"
|
||||
]
|
||||
],
|
||||
'error 6 will be domain double dot' => [
|
||||
6,
|
||||
[
|
||||
'error' => 6,
|
||||
'message' => 'Double consecutive dots in domain name (..)',
|
||||
'regex' => "@(.*)\.{2,}"
|
||||
]
|
||||
],
|
||||
'error 7 will domain ends with dot' => [
|
||||
7,
|
||||
[
|
||||
'error' => 7,
|
||||
'message' => 'Domain ends with a dot or is missing top level part',
|
||||
'regex' => "@.*\.$"
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::getEmailRegexErrorMessage
|
||||
* @dataProvider emailRegexErrorProvider
|
||||
* @testdox getEmailRegexErrorMessage $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param integer $input
|
||||
* @param array $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testGetEmailRegexErrorMessage(int $input, array $expected): void
|
||||
{
|
||||
$this->assertEqualsCanonicalizing(
|
||||
$expected,
|
||||
\CoreLibs\Check\Email::getEmailRegexErrorMessage($input)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* This holds all email type checks normal and short
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function emailTypeProvider(): array
|
||||
{
|
||||
return [
|
||||
['test@test.com', 'pc_html', 'pc'],
|
||||
['test@docomo.ne.jp', 'keitai_docomo', 'docomo'],
|
||||
['test@softbank.ne.jp', 'keitai_softbank', 'softbank'],
|
||||
['test@i.softbank.ne.jp', 'smartphone_softbank_iphone', 'iphone'],
|
||||
// TODO: add more test emails here
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns only normal email type checks
|
||||
*
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function emailTypeProviderLong(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->emailTypeProvider() as $set) {
|
||||
$list['email ' . $set[0] . ' is valid and matches normal ' . $set[1]] = [$set[0], $set[1]];
|
||||
}
|
||||
$list['email is empty and not valid normal'] = ['', 'invalid'];
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* only short email type list
|
||||
*
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function emailTypeProviderShort(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->emailTypeProvider() as $set) {
|
||||
$list['email ' . $set[0] . ' is valid and matches short ' . $set[2]] = [$set[0], $set[2]];
|
||||
}
|
||||
$list['email is empty and not valid short'] = ['', 'invalid'];
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::getEmailType
|
||||
* @dataProvider emailTypeProviderLong
|
||||
* @testdox getEmailType $input will be normal $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testGetEmailTypeNormal(string $input, string $expected)
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Check\Email::getEmailType($input, false)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::getEmailType
|
||||
* @dataProvider emailTypeProviderShort
|
||||
* @testdox getEmailType $input will be short $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testGetEmailTypeShort(string $input, string $expected)
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Check\Email::getEmailType($input, true)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function emailProviderTypeLongToShort(): array
|
||||
{
|
||||
$mobile_email_type_short = [
|
||||
'keitai_docomo' => 'docomo',
|
||||
'keitai_kddi_ezweb' => 'kddi',
|
||||
'keitai_kddi' => 'kddi',
|
||||
'keitai_kddi_tu-ka' => 'kddi',
|
||||
'keitai_kddi_sky' => 'kddi',
|
||||
'keitai_softbank' => 'softbank',
|
||||
'smartphone_softbank_iphone' => 'iphone',
|
||||
'keitai_softbank_disney' => 'softbank',
|
||||
'keitai_softbank_vodafone' => 'softbank',
|
||||
'keitai_softbank_j-phone' => 'softbank',
|
||||
'keitai_willcom' => 'willcom',
|
||||
'keitai_willcom_pdx' => 'willcom',
|
||||
'keitai_willcom_bandai' => 'willcom',
|
||||
'keitai_willcom_pipopa' => 'willcom',
|
||||
'keitai_willcom_ymobile' => 'willcom',
|
||||
'keitai_willcom_emnet' => 'willcom',
|
||||
'pc_html' => 'pc',
|
||||
];
|
||||
$list = [];
|
||||
// use the static one
|
||||
foreach ($mobile_email_type_short as $long => $short) {
|
||||
$list[$long . ' matches to ' . $short] = [$long, $short];
|
||||
}
|
||||
// add invalid check
|
||||
$list['Not found will be bool false'] = ['invalid', false];
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::getShortEmailType
|
||||
* @dataProvider emailProviderTypeLongToShort
|
||||
* @testdox getShortEmailType $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string|bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testGetShortEmailType(string $input, $expected)
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Check\Email::getShortEmailType($input)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
120
test/phpunit/Check/CoreLibsCheckEncodingTest.php
Normal file
120
test/phpunit/Check/CoreLibsCheckEncodingTest.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Check\Encoding
|
||||
* @coversDefaultClass \CoreLibs\Check\Encoding
|
||||
* @testdox \CoreLibs\Check\Encoding method tests
|
||||
*/
|
||||
final class CoreLibsCheckEncodingTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function checkConvertEncodingProvider(): array
|
||||
{
|
||||
return [
|
||||
// 0: string to test
|
||||
// 1: source encoding
|
||||
// 2: target encoding
|
||||
// 3: substitue character
|
||||
// 4: false for ok, array with error list
|
||||
'valid test UTF-8 to SJIS (default)' => [
|
||||
'日本語',
|
||||
'UTF-8',
|
||||
'SJIS',
|
||||
null,
|
||||
false
|
||||
],
|
||||
'invalid test UTF-8 to SJIS (dots as code point)' => [
|
||||
'❶',
|
||||
'UTF-8',
|
||||
'SJIS',
|
||||
0x2234,
|
||||
['❶']
|
||||
],
|
||||
'invalid test UTF-8 to SJIS (dots as string)' => [
|
||||
'❶',
|
||||
'UTF-8',
|
||||
'SJIS',
|
||||
'∴',
|
||||
['❶']
|
||||
],
|
||||
'invalid test UTF-8 to SJIS (none)' => [
|
||||
'❶',
|
||||
'UTF-8',
|
||||
'SJIS',
|
||||
'none',
|
||||
['❶']
|
||||
],
|
||||
'invalid test UTF-8 to SJIS (long)' => [
|
||||
'❶',
|
||||
'UTF-8',
|
||||
'SJIS',
|
||||
'long',
|
||||
['❶']
|
||||
],
|
||||
'invalid test UTF-8 to SJIS (entity)' => [
|
||||
'❶',
|
||||
'UTF-8',
|
||||
'SJIS',
|
||||
'entity',
|
||||
['❶']
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::checkConvertEncoding
|
||||
* @dataProvider checkConvertEncodingProvider
|
||||
* @testdox check encoding convert from $from_encoding to $to_encoding [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $from_encoding
|
||||
* @param string $to_encoding
|
||||
* @param string|int|null $error_char
|
||||
* @param array|bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testCheckConvertEncoding(
|
||||
string $input,
|
||||
string $from_encoding,
|
||||
string $to_encoding,
|
||||
$error_char,
|
||||
$expected
|
||||
): void {
|
||||
$current_subsitute_character = mb_substitute_character();
|
||||
if ($error_char !== null) {
|
||||
\CoreLibs\Check\Encoding::setErrorChar($error_char);
|
||||
if (!in_array($error_char, ['none', 'long', 'entity'])) {
|
||||
$this->assertEquals(
|
||||
\IntlChar::chr($error_char),
|
||||
\CoreLibs\Check\Encoding::getErrorChar()
|
||||
);
|
||||
} else {
|
||||
$this->assertEquals(
|
||||
$error_char,
|
||||
\CoreLibs\Check\Encoding::getErrorChar()
|
||||
);
|
||||
}
|
||||
}
|
||||
$return = \CoreLibs\Check\Encoding::checkConvertEncoding($input, $from_encoding, $to_encoding);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$return
|
||||
);
|
||||
// reset after test
|
||||
mb_substitute_character($current_subsitute_character);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
120
test/phpunit/Check/CoreLibsCheckFileTest.php
Normal file
120
test/phpunit/Check/CoreLibsCheckFileTest.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Check\File
|
||||
* @coversDefaultClass \CoreLibs\Check\File
|
||||
* @testdox \CoreLibs\Check\File method tests
|
||||
*/
|
||||
final class CoreLibsCheckFileTest extends TestCase
|
||||
{
|
||||
/** @var array<mixed> */
|
||||
// private $files_list = [];
|
||||
/** @var string */
|
||||
private $base_folder = DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR;
|
||||
|
||||
/**
|
||||
* main file list + data provider
|
||||
*
|
||||
* filename, file extension matching, lines in file, -1 for nothing
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function filesList(): array
|
||||
{
|
||||
return [
|
||||
['filename.txt', 'txt', 5],
|
||||
['filename.csv', 'csv', 15],
|
||||
['filename.tsv', 'tsv', 0],
|
||||
['file_does_not_exits', '', -1],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function filesExtensionProvider(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->filesList() as $row) {
|
||||
$list[$row[0] . ' must be extension ' . $row[1]] = [$row[0], $row[1]];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function filesLinesProvider(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->filesList() as $row) {
|
||||
$list[$row[0] . ' must have ' . $row[2] . ' lines'] = [$row[0], $row[2]];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if file extension matches
|
||||
*
|
||||
* @covers ::getFilenameEnding
|
||||
* @dataProvider filesExtensionProvider
|
||||
* @testdox getFilenameEnding $input must be extension $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testGetFilenameEnding(string $input, string $expected): void
|
||||
{
|
||||
// getFilenameEnding
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Check\File::getFilenameEnding($input)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the file line read
|
||||
*
|
||||
* @covers ::getLinesFromFile
|
||||
* @dataProvider filesLinesProvider
|
||||
* @testdox getLinesFromFile $input must have $expected lines [$_dataName]
|
||||
*
|
||||
* @param string $input file name
|
||||
* @param int $expected lines in file
|
||||
* @return void
|
||||
*/
|
||||
public function testGetLinesFromFile(string $input, int $expected): void
|
||||
{
|
||||
// create file
|
||||
if ($expected > -1) {
|
||||
$file = $this->base_folder . $input;
|
||||
$fp = fopen($file, 'w');
|
||||
for ($i = 0; $i < $expected; $i++) {
|
||||
fwrite($fp, 'This is row ' . ($i + 1) . PHP_EOL);
|
||||
}
|
||||
fclose($fp);
|
||||
}
|
||||
// test
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Check\File::getLinesFromFile($this->base_folder . $input)
|
||||
);
|
||||
// unlink file
|
||||
if (is_file($this->base_folder . $input)) {
|
||||
unlink($this->base_folder . $input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
73
test/phpunit/Check/CoreLibsCheckPasswordTest.php
Normal file
73
test/phpunit/Check/CoreLibsCheckPasswordTest.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Check\Password
|
||||
* @coversDefaultClass \CoreLibs\Check\Password
|
||||
* @testdox \CoreLibs\Check\Password method tests
|
||||
*/
|
||||
final class CoreLibsCheckPasswordTest extends TestCase
|
||||
{
|
||||
public function passwordProvider(): array
|
||||
{
|
||||
return [
|
||||
'matching password' => ['test', 'test', true],
|
||||
'not matching password' => ['test', 'not_test', false],
|
||||
];
|
||||
}
|
||||
|
||||
public function passwordRehashProvider(): array
|
||||
{
|
||||
return [
|
||||
'no rehash needed' => ['$2y$10$EgWJ2WE73DWi.hIyFRCdpejLXTvHbmTK3LEOclO1tAvXAXUNuUS4W', false],
|
||||
'rehash needed' => ['9c42a1346e333a770904b2a2b37fa7d3', true],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::passwordVerify
|
||||
* @covers ::passwordSet
|
||||
* @dataProvider passwordProvider
|
||||
* @testdox passwordSet $input compare to $input_hash: passwordVerify $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $input_hash
|
||||
* @param boolean $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testPasswordSetVerify(string $input, string $input_hash, bool $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Check\Password::passwordVerify($input, \CoreLibs\Check\Password::passwordSet($input_hash))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::passwordRehashCheck
|
||||
* @dataProvider passwordRehashProvider
|
||||
* @testdox passwordRehashCheck $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param boolean $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testPasswordRehashCheck(string $input, bool $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Check\Password::passwordRehashCheck($input)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
73
test/phpunit/Check/CoreLibsCheckPhpVersionTest.php
Normal file
73
test/phpunit/Check/CoreLibsCheckPhpVersionTest.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Check\PHPVersion
|
||||
* @coversDefaultClass \CoreLibs\Check\PHPVersion
|
||||
* @testdox \CoreLibs\Check\PHPVersion method tests
|
||||
*/
|
||||
final class CoreLibsCheckPhpVersionTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* NOTE: The checks must be adapted to the PHP version or they will fail
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function phpVersionProvider(): array
|
||||
{
|
||||
return [
|
||||
// min
|
||||
'min 7' => ['7', '', true],
|
||||
'min 7.4' => ['7.4', '', true],
|
||||
'min 7.4.1' => ['7.4.1', '', true],
|
||||
// NOTE: update if php version bigger than 10
|
||||
'min 10' => ['10', '', false],
|
||||
'min 10.0' => ['10.0', '', false],
|
||||
'min 10.0.0' => ['10.0.0', '', false],
|
||||
// min/max version, NOTE: update if php version bigger than 10
|
||||
'min 7/max 10' => ['7', '10', true],
|
||||
'min 7/max 10.0' => ['7', '10.0', true],
|
||||
'min 7/max 10.0.0' => ['7', '10.0.0', true],
|
||||
// min/max version
|
||||
'min 5/max 7' => ['5', '7', false],
|
||||
'min 5/max 7.4' => ['5', '7.4', false],
|
||||
'min 5/max 7.4.1' => ['5', '7.4.1', false],
|
||||
// max only
|
||||
'max 7' => ['', '7', false],
|
||||
'max 7.4' => ['', '7.4', false],
|
||||
'max 7.4.1' => ['', '7.4.1', false],
|
||||
// max over
|
||||
'max 10' => ['', '10', true],
|
||||
'max 10.0' => ['', '10.0', true],
|
||||
'max 10.0.0' => ['', '10.0.0', true],
|
||||
// TODO: add null tests
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::checkPHPVersion
|
||||
* @dataProvider phpVersionProvider
|
||||
* @testdox checkPHPVersion $input_min and $input_max will be $expected [$_dataName]
|
||||
*
|
||||
* @param string $input_min
|
||||
* @param string $input_max
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testCheckPHPVersion(string $input_min, string $input_max, bool $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Check\PhpVersion::checkPHPVersion($input_min, $input_max)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
887
test/phpunit/Combined/CoreLibsCombinedArrayHandlerTest.php
Normal file
887
test/phpunit/Combined/CoreLibsCombinedArrayHandlerTest.php
Normal file
@@ -0,0 +1,887 @@
|
||||
<?php
|
||||
|
||||
// because we have long testdox lines
|
||||
// phpcs:disable Generic.Files.LineLength
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use Exception;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Combined\ArrayHandler
|
||||
* @coversDefaultClass \CoreLibs\Combined\ArrayHandler
|
||||
* @testdox \CoreLibs\Combined\ArrayHandler method tests
|
||||
*/
|
||||
final class CoreLibsCombinedArrayHandlerTest extends TestCase
|
||||
{
|
||||
// we use that for all
|
||||
public static $array = [
|
||||
'a' => [
|
||||
'b' => 'bar',
|
||||
'c' => 'foo',
|
||||
'same' => 'same',
|
||||
3 => 'foobar',
|
||||
'foobar' => 4,
|
||||
'true' => true,
|
||||
],
|
||||
'd',
|
||||
4,
|
||||
'b',
|
||||
'c' => 'test',
|
||||
'same' => 'same',
|
||||
'deep' => [
|
||||
'sub' => [
|
||||
'nested' => 'bar',
|
||||
'same' => 'same',
|
||||
'more' => 'test'
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function arraySearchRecursiveProvider(): array
|
||||
{
|
||||
return [
|
||||
'find value' => [
|
||||
0 => 'bar',
|
||||
1 => self::$array,
|
||||
2 => null,
|
||||
3 => ['a', 'b'],
|
||||
],
|
||||
'find value with key' => [
|
||||
0 => 'bar',
|
||||
1 => self::$array,
|
||||
2 => 'nested',
|
||||
3 => ['deep', 'sub', 'nested']
|
||||
],
|
||||
'not existing value' => [
|
||||
0 => 'not exists',
|
||||
1 => self::$array,
|
||||
2 => null,
|
||||
3 => [],
|
||||
],
|
||||
'find value int' => [
|
||||
0 => 4,
|
||||
1 => self::$array,
|
||||
2 => null,
|
||||
3 => ['a', 'foobar']
|
||||
],
|
||||
'find value int as string' => [
|
||||
0 => '4',
|
||||
1 => self::$array,
|
||||
2 => null,
|
||||
3 => []
|
||||
],
|
||||
'find value int as string with key' => [
|
||||
0 => '4',
|
||||
1 => self::$array,
|
||||
2 => 'foobar',
|
||||
3 => []
|
||||
],
|
||||
'first level value' => [
|
||||
0 => 'd',
|
||||
1 => self::$array,
|
||||
2 => null,
|
||||
4 => [0]
|
||||
],
|
||||
'find value, return int key' => [
|
||||
0 => 'foobar',
|
||||
1 => self::$array,
|
||||
2 => null,
|
||||
3 => ['a', 3]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function arraySearchRecursiveAllProvider(): array
|
||||
{
|
||||
/*
|
||||
0: $needle,
|
||||
1: array $input,
|
||||
2: ?string $key_search_for,
|
||||
3: bool $flag,
|
||||
4: array $expected
|
||||
*/
|
||||
return [
|
||||
'find value' => [
|
||||
0 => 'bar',
|
||||
1 => self::$array,
|
||||
2 => null,
|
||||
3 => true,
|
||||
4 => [
|
||||
'level' => -1,
|
||||
'work' => [],
|
||||
'found' => [
|
||||
0 => ['a', 'b'],
|
||||
1 => ['deep', 'sub', 'nested']
|
||||
]
|
||||
]
|
||||
],
|
||||
'find value, new type' => [
|
||||
0 => 'bar',
|
||||
1 => self::$array,
|
||||
2 => null,
|
||||
3 => false,
|
||||
4 => [
|
||||
0 => ['a', 'b'],
|
||||
1 => ['deep', 'sub', 'nested']
|
||||
]
|
||||
],
|
||||
'find value with key' => [
|
||||
0 => 'bar',
|
||||
1 => self::$array,
|
||||
2 => 'nested',
|
||||
3 => true,
|
||||
4 => [
|
||||
'level' => -1,
|
||||
'work' => [],
|
||||
'found' => [
|
||||
0 => ['deep', 'sub', 'nested']
|
||||
]
|
||||
]
|
||||
],
|
||||
'not existing value' => [
|
||||
0 => 'not exists',
|
||||
1 => self::$array,
|
||||
2 => null,
|
||||
3 => true,
|
||||
4 => [
|
||||
'level' => -1,
|
||||
'work' => [],
|
||||
],
|
||||
],
|
||||
'not existing value, new type' => [
|
||||
0 => 'not exists',
|
||||
1 => self::$array,
|
||||
2 => null,
|
||||
3 => false,
|
||||
4 => [],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function arraySearchSimpleProvider(): array
|
||||
{
|
||||
/*
|
||||
0: array $input,
|
||||
1: $key,
|
||||
2: $value,
|
||||
3: bool $flag,
|
||||
4: bool $expected
|
||||
*/
|
||||
return [
|
||||
'key/value exist' => [
|
||||
0 => self::$array,
|
||||
1 => 'c',
|
||||
2 => 'foo',
|
||||
3 => false,
|
||||
4 => true,
|
||||
],
|
||||
'key/value exists twice' => [
|
||||
0 => self::$array,
|
||||
1 => 'same',
|
||||
2 => 'same',
|
||||
3 => false,
|
||||
4 => true,
|
||||
],
|
||||
'key/value not found' => [
|
||||
0 => self::$array,
|
||||
1 => 'not exists',
|
||||
2 => 'not exists',
|
||||
3 => false,
|
||||
4 => false,
|
||||
],
|
||||
'key exists, value not' => [
|
||||
0 => self::$array,
|
||||
1 => 'b',
|
||||
2 => 'not exists',
|
||||
3 => false,
|
||||
4 => false,
|
||||
],
|
||||
'key not, value exists' => [
|
||||
0 => self::$array,
|
||||
1 => 'not exists',
|
||||
2 => 'bar',
|
||||
3 => false,
|
||||
4 => false,
|
||||
],
|
||||
'numeric key, value exists' => [
|
||||
0 => self::$array,
|
||||
1 => 0,
|
||||
2 => 'd',
|
||||
3 => false,
|
||||
4 => true,
|
||||
],
|
||||
'numeric key as string, value exists' => [
|
||||
0 => self::$array,
|
||||
1 => '0',
|
||||
2 => 'd',
|
||||
3 => false,
|
||||
4 => true,
|
||||
],
|
||||
'numeric key as string, value exists, strinct' => [
|
||||
0 => self::$array,
|
||||
1 => '0',
|
||||
2 => 'd',
|
||||
3 => true,
|
||||
4 => false,
|
||||
],
|
||||
'key exists, value numeric' => [
|
||||
0 => self::$array,
|
||||
1 => 'foobar',
|
||||
2 => 4,
|
||||
3 => false,
|
||||
4 => true,
|
||||
],
|
||||
'key exists, value numeric as string' => [
|
||||
0 => self::$array,
|
||||
1 => 'foobar',
|
||||
2 => '4',
|
||||
3 => false,
|
||||
4 => true,
|
||||
],
|
||||
'key exists, value numeric as string, strict' => [
|
||||
0 => self::$array,
|
||||
1 => 'foobar',
|
||||
2 => '4',
|
||||
3 => true,
|
||||
4 => false,
|
||||
],
|
||||
'key exists, value bool' => [
|
||||
0 => self::$array,
|
||||
1 => 'true',
|
||||
2 => true,
|
||||
3 => false,
|
||||
4 => true,
|
||||
],
|
||||
'key exists, value bool as string' => [
|
||||
0 => self::$array,
|
||||
1 => 'true',
|
||||
2 => 'true',
|
||||
3 => false,
|
||||
4 => true,
|
||||
],
|
||||
'key exists, value bool as string, strict' => [
|
||||
0 => self::$array,
|
||||
1 => 'true',
|
||||
2 => 'true',
|
||||
3 => true,
|
||||
4 => false,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* provides array listing for the merge test
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function arrayMergeRecursiveProvider(): array
|
||||
{
|
||||
return [
|
||||
// 0: expected
|
||||
// 1..n: to merge arrays
|
||||
// n+1: trigger for handle keys as string
|
||||
'two arrays' => [
|
||||
['a' => 1, 'b' => 2, 'c' => 3],
|
||||
['a' => 1, 'b' => 2],
|
||||
['b' => 2, 'c' => 3],
|
||||
],
|
||||
'two arrays, string flag' => [
|
||||
['a' => 1, 'b' => 2, 'c' => 3],
|
||||
['a' => 1, 'b' => 2],
|
||||
['b' => 2, 'c' => 3],
|
||||
true,
|
||||
],
|
||||
// non hash arrays
|
||||
'non hash array merge, no string flag' => [
|
||||
[3, 4, 5],
|
||||
[1, 2, 3],
|
||||
[3, 4, 5],
|
||||
],
|
||||
'non hash array merge, string flag' => [
|
||||
[1, 2, 3, 3, 4, 5],
|
||||
[1, 2, 3],
|
||||
[3, 4, 5],
|
||||
true
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* for warning checks
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function arrayMergeRecursiveProviderWarning(): array
|
||||
{
|
||||
return [
|
||||
// error <2 arguments
|
||||
'too view arguments' => [
|
||||
'arrayMergeRecursive needs two or more array arguments',
|
||||
[1]
|
||||
],
|
||||
// error <2 arrays
|
||||
'only one array' => [
|
||||
'arrayMergeRecursive needs two or more array arguments',
|
||||
[1],
|
||||
true,
|
||||
],
|
||||
// error element is not array
|
||||
'non array between array' => [
|
||||
'arrayMergeRecursive encountered a non array argument',
|
||||
[1],
|
||||
'string',
|
||||
[2]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function arrayCompareProvider(): array
|
||||
{
|
||||
return [
|
||||
'one matching' => [
|
||||
['a', 'b', 'c'],
|
||||
['c', 'd', 'e'],
|
||||
['a', 'b', 'd', 'e']
|
||||
],
|
||||
'all the same' => [
|
||||
['a', 'b', 'c'],
|
||||
['a', 'b', 'c'],
|
||||
[]
|
||||
],
|
||||
'all different' => [
|
||||
['a', 'b'],
|
||||
['c', 'd'],
|
||||
['a', 'b', 'c', 'd']
|
||||
],
|
||||
'empty arrays' => [
|
||||
[],
|
||||
[],
|
||||
[]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function inArrayAnyProvider(): array
|
||||
{
|
||||
return [
|
||||
'all exist in haystack' => [
|
||||
[1],
|
||||
[1, 2, 3, 4],
|
||||
[1]
|
||||
],
|
||||
'not all exist in haystack' => [
|
||||
[1, 5],
|
||||
[1, 2, 3, 4],
|
||||
[1]
|
||||
],
|
||||
'none exist in haystack' => [
|
||||
[5],
|
||||
[1, 2, 3, 4],
|
||||
false
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function genAssocArrayProvider(): array
|
||||
{
|
||||
return [
|
||||
'non set' => [
|
||||
[
|
||||
0 => ['a' => 'a1', 'b' => 2],
|
||||
1 => ['a' => 'a2', 'b' => 3],
|
||||
2 => ['a' => '', 'b' => null],
|
||||
],
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
[],
|
||||
],
|
||||
'key set' => [
|
||||
[
|
||||
0 => ['a' => 'a1', 'b' => 2],
|
||||
1 => ['a' => 'a2', 'b' => 3],
|
||||
2 => ['a' => '', 'b' => null],
|
||||
],
|
||||
'a',
|
||||
false,
|
||||
false,
|
||||
['a1' => 0, 'a2' => 1],
|
||||
],
|
||||
'value set' => [
|
||||
[
|
||||
0 => ['a' => 'a1', 'b' => 2],
|
||||
1 => ['a' => 'a2', 'b' => 3],
|
||||
2 => ['a' => '', 'b' => null],
|
||||
],
|
||||
false,
|
||||
'a',
|
||||
false,
|
||||
[0 => 'a1', 1 => 'a2', 2 => ''],
|
||||
],
|
||||
'key and value set, add empty, null' => [
|
||||
[
|
||||
0 => ['a' => 'a1', 'b' => 2],
|
||||
1 => ['a' => 'a2', 'b' => 3],
|
||||
2 => ['a' => '', 'b' => null],
|
||||
],
|
||||
'a',
|
||||
'b',
|
||||
false,
|
||||
['a1' => 2, 'a2' => 3],
|
||||
],
|
||||
'key and value set, add empty' => [
|
||||
[
|
||||
0 => ['a' => 'a1', 'b' => 2],
|
||||
1 => ['a' => 'a2', 'b' => 3],
|
||||
2 => ['a' => '', 'b' => ''],
|
||||
3 => ['a' => 'a4', 'b' => ''],
|
||||
],
|
||||
'a',
|
||||
'b',
|
||||
false,
|
||||
['a1' => 2, 'a2' => 3, 'a4' => ''],
|
||||
],
|
||||
'key/value set, skip empty' => [
|
||||
[
|
||||
0 => ['a' => 'a1', 'b' => 2],
|
||||
1 => ['a' => 'a2', 'b' => 3],
|
||||
2 => ['a' => '', 'b' => null],
|
||||
],
|
||||
'a',
|
||||
'b',
|
||||
true,
|
||||
['a1' => 2, 'a2' => 3],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function flattenArrayProvider(): array
|
||||
{
|
||||
return [
|
||||
'array key/value, single' => [
|
||||
0 => ['a' => 'foo', 1 => 'bar', 'c' => 2],
|
||||
1 => ['foo', 'bar', 2],
|
||||
2 => ['a', 1, 'c'],
|
||||
3 => ['a', 1, 'c'],
|
||||
],
|
||||
'array values, single' => [
|
||||
0 => ['foo', 'bar', 2],
|
||||
1 => ['foo', 'bar', 2],
|
||||
2 => [0, 1, 2],
|
||||
3 => [0, 1, 2],
|
||||
],
|
||||
'array key/value, multi' => [
|
||||
0 => [
|
||||
'a' => ['a1' => 'a1foo', 'a2' => 'a1bar'],
|
||||
1 => 'bar',
|
||||
'c' => [2, 3, 4],
|
||||
'd' => [
|
||||
'e' => [
|
||||
'de1' => 'subfoo', 'de2' => 'subbar', 'a2' => 'a1bar'
|
||||
]
|
||||
]
|
||||
],
|
||||
1 => ['a1foo', 'a1bar', 'bar', 2, 3, 4, 'subfoo', 'subbar', 'a1bar'],
|
||||
2 => ['a', 'a1', 'a2', 1, 'c', 0, 1, 2, 'd', 'e', 'de1', 'de2', 'a2'],
|
||||
3 => ['a1', 'a2', 1, 0, 1, 2, 'de1', 'de2', 'a2'],
|
||||
],
|
||||
'array with double values' => [
|
||||
0 => ['a', 'a', 'b'],
|
||||
1 => ['a', 'a', 'b'],
|
||||
2 => [0, 1, 2],
|
||||
3 => [0, 1, 2],
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* use the flattenArrayProvider and replace 1 with 2 array pos
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function flattenArrayKeyProvider(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->flattenArrayProvider() as $key => $row) {
|
||||
$list[$key] = [
|
||||
$row[0],
|
||||
$row[2],
|
||||
];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* use the flattenArrayProvider and replace 1 with 3 array pos
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function flattenArrayKeyLeavesOnlyProvider(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->flattenArrayProvider() as $key => $row) {
|
||||
$list[$key] = [
|
||||
$row[0],
|
||||
$row[3],
|
||||
];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function arrayFlatForKeyProvider(): array
|
||||
{
|
||||
return [
|
||||
'all present, single level' => [
|
||||
0 => [
|
||||
'a' => ['b1' => 'foo', 'a2' => 'a-foo'],
|
||||
'b' => ['b1' => 'bar', 'a2' => 'b-foo'],
|
||||
'c' => ['b1' => 'foobar', 'a2' => 'c-foo'],
|
||||
],
|
||||
1 => 'a2',
|
||||
2 => [
|
||||
'a' => 'a-foo',
|
||||
'b' => 'b-foo',
|
||||
'c' => 'c-foo',
|
||||
],
|
||||
],
|
||||
'no sub arrays' => [
|
||||
0 => ['a', 'b', 'c'],
|
||||
1 => 'a',
|
||||
2 => ['a', 'b', 'c'],
|
||||
],
|
||||
'sub arrays with missing' => [
|
||||
0 => [
|
||||
'a' => ['b1' => 'foo', 'a2' => 'a-foo'],
|
||||
'b' => ['b1' => 'bar'],
|
||||
'c' => ['b1' => 'foobar', 'a2' => 'c-foo'],
|
||||
],
|
||||
1 => 'a2',
|
||||
2 => [
|
||||
'a' => 'a-foo',
|
||||
'b' => ['b1' => 'bar'],
|
||||
'c' => 'c-foo',
|
||||
],
|
||||
],
|
||||
'deep nested sub arrays' => [
|
||||
0 => [
|
||||
'a' => [
|
||||
'b1' => 'foo',
|
||||
'a2' => [
|
||||
'text' => ['a-foo', 'a-bar'],
|
||||
],
|
||||
],
|
||||
'b' => [
|
||||
'b1' => 'bar',
|
||||
'a2' => [
|
||||
'text' => 'b-foo',
|
||||
],
|
||||
],
|
||||
],
|
||||
1 => 'a2',
|
||||
2 => [
|
||||
'a' => [
|
||||
'text' => ['a-foo', 'a-bar'],
|
||||
],
|
||||
'b' => [
|
||||
'text' => 'b-foo',
|
||||
],
|
||||
],
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::arraySearchRecursive
|
||||
* @dataProvider arraySearchRecursiveProvider
|
||||
* @testdox arraySearchRecursive $needle (key $key_search_for) in $input and will be $expected [$_dataName]
|
||||
*
|
||||
* @param string|null $needle
|
||||
* @param array $input
|
||||
* @param string|null $key_search_for
|
||||
* @return void
|
||||
*/
|
||||
public function testArraySearchRecursive($needle, array $input, ?string $key_search_for, array $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Combined\ArrayHandler::arraySearchRecursive($needle, $input, $key_search_for)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::arraySearchRecursiveAll
|
||||
* @dataProvider arraySearchRecursiveAllProvider
|
||||
* @testdox arraySearchRecursiveAll $needle (key $key_search_for) in $input and will be $expected (old: $flag) [$_dataName]
|
||||
*
|
||||
* @param string|null $needle
|
||||
* @param array $input
|
||||
* @param string|null $key_search_for
|
||||
* @param bool $flag
|
||||
* @return void
|
||||
*/
|
||||
public function testArraySearchRecursiveAll($needle, array $input, ?string $key_search_for, bool $flag, array $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Combined\ArrayHandler::arraySearchRecursiveAll($needle, $input, $key_search_for, $flag)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::arraySearchSimple
|
||||
* @dataProvider arraySearchSimpleProvider
|
||||
* @testdox arraySearchSimple $input searched with key: $key / value: $value (strict: $flag) will be $expected [$_dataName]
|
||||
*
|
||||
* @param array $input
|
||||
* @param string|int $key
|
||||
* @param string|int|bool $value
|
||||
* @param bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testArraySearchSimple(array $input, $key, $value, bool $flag, bool $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Combined\ArrayHandler::arraySearchSimple($input, $key, $value, $flag)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::arrayMergeRecursive
|
||||
* @dataProvider arrayMergeRecursiveProvider
|
||||
* @testdox arrayMergeRecursive ... [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
*/
|
||||
public function testArrayMergeRecursive(): void
|
||||
{
|
||||
$arrays = func_get_args();
|
||||
// first is expected array, always
|
||||
$expected = array_shift($arrays);
|
||||
$output = \CoreLibs\Combined\ArrayHandler::arrayMergeRecursive(
|
||||
...$arrays
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::arrayMergeRecursive
|
||||
* @dataProvider arrayMergeRecursiveProviderWarning
|
||||
* @testdox arrayMergeRecursive with E_USER_WARNING [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testArrayMergeRecursiveWarningA(): void
|
||||
{
|
||||
set_error_handler(
|
||||
static function (int $errno, string $errstr): never {
|
||||
throw new Exception($errstr, $errno);
|
||||
},
|
||||
E_USER_WARNING
|
||||
);
|
||||
|
||||
$arrays = func_get_args();
|
||||
// first is expected warning
|
||||
$warning = array_shift($arrays);
|
||||
|
||||
// phpunit 10.0 compatible
|
||||
$this->expectExceptionMessage($warning);
|
||||
|
||||
\CoreLibs\Combined\ArrayHandler::arrayMergeRecursive(...$arrays);
|
||||
|
||||
restore_error_handler();
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::arrayDiff
|
||||
* @dataProvider arrayCompareProvider
|
||||
* @testdox arrayDiff $input_a diff $input_b will be $expected [$_dataName]
|
||||
*
|
||||
* @param array $input_a
|
||||
* @param array $input_b
|
||||
* @param array $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testArrayDiff(array $input_a, array $input_b, array $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Combined\ArrayHandler::arrayDiff($input_a, $input_b)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::inArrayAny
|
||||
* @dataProvider inArrayAnyProvider
|
||||
* @testdox inArrayAny needle $input_a in haystack $input_b will be $expected [$_dataName]
|
||||
*
|
||||
* @param array $input_a
|
||||
* @param array $input_b
|
||||
* @param array|bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testInArrayAny(array $input_a, array $input_b, $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Combined\ArrayHandler::inArrayAny($input_a, $input_b)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::genAssocArray
|
||||
* @dataProvider genAssocArrayProvider
|
||||
* @testdox genAssocArray array $input with $key or $value and flag set only $flag will be $expected [$_dataName]
|
||||
*
|
||||
* @param array $input
|
||||
* @param string|int|bool $key
|
||||
* @param string|int|bool $value
|
||||
* @param bool $flag
|
||||
* @param array $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testGenAssocArray(array $input, $key, $value, bool $flag, array $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Combined\ArrayHandler::genAssocArray($input, $key, $value, $flag)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::flattenArray
|
||||
* @dataProvider flattenArrayProvider
|
||||
* @testdox testFlattenArray array $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param array $input
|
||||
* @param array $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testFlattenyArray(array $input, array $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Combined\ArrayHandler::flattenArray($input)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::flattenArrayKey
|
||||
* @dataProvider flattenArrayKeyProvider
|
||||
* @testdox flattenArrayKey array $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param array $input
|
||||
* @param array $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testFlattenArrayKey(array $input, array $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Combined\ArrayHandler::flattenArrayKey($input)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::flattenArrayKeyLeavesOnly
|
||||
* @dataProvider flattenArrayKeyLeavesOnlyProvider
|
||||
* @testdox flattenArrayKeyLeavesOnly array $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param array $input
|
||||
* @param array $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testFlattenArrayKeyLeavesOnly(array $input, array $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Combined\ArrayHandler::flattenArrayKeyLeavesOnly($input)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::arrayFlatForKey
|
||||
* @dataProvider arrayFlatForKeyProvider
|
||||
* @testdox arrayFlatForKey array $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param array $input
|
||||
* @param array $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testArrayFlatForKey(array $input, $search, array $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Combined\ArrayHandler::arrayFlatForKey($input, $search)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
785
test/phpunit/Combined/CoreLibsCombinedDateTimeTest.php
Normal file
785
test/phpunit/Combined/CoreLibsCombinedDateTimeTest.php
Normal file
@@ -0,0 +1,785 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Combined\DateTime
|
||||
* @coversDefaultClass \CoreLibs\Combined\DateTime
|
||||
* @testdox \CoreLibs\Combined\DateTime method tests
|
||||
*/
|
||||
final class CoreLibsCombinedDateTimeTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* timestamps
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function timestampProvider(): array
|
||||
{
|
||||
return [
|
||||
'valid timestamp no microtime' => [
|
||||
1641515890,
|
||||
false,
|
||||
false,
|
||||
'2022-01-07 09:38:10',
|
||||
],
|
||||
'valid timestamp with microtime' => [
|
||||
1641515890,
|
||||
true,
|
||||
false,
|
||||
'2022-01-07 09:38:10',
|
||||
],
|
||||
'valid timestamp with microtime float' => [
|
||||
1641515890,
|
||||
true,
|
||||
true,
|
||||
'2022-01-07 09:38:10',
|
||||
],
|
||||
'valid micro timestamp with microtime' => [
|
||||
1641515890.123456,
|
||||
true,
|
||||
false,
|
||||
'2022-01-07 09:38:10 1235ms',
|
||||
],
|
||||
'valid micro timestamp with microtime float' => [
|
||||
1641515890.123456,
|
||||
true,
|
||||
true,
|
||||
'2022-01-07 09:38:10.1235',
|
||||
],
|
||||
'valid micro timestamp no microtime' => [
|
||||
1641515890.123456,
|
||||
false,
|
||||
false,
|
||||
'2022-01-07 09:38:10',
|
||||
],
|
||||
'invalid timestamp' => [
|
||||
-123123,
|
||||
false,
|
||||
false,
|
||||
'1969-12-30 22:47:57',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* interval for both directions
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function intervalProvider(): array
|
||||
{
|
||||
return [
|
||||
'interval no microtime' => [
|
||||
1641515890,
|
||||
false,
|
||||
'18999d 0h 38m 10s',
|
||||
],
|
||||
'interval with microtime' => [
|
||||
1641515890,
|
||||
true,
|
||||
'18999d 0h 38m 10s',
|
||||
],
|
||||
'micro interval no microtime' => [
|
||||
1641515890.123456,
|
||||
false,
|
||||
'18999d 0h 38m 10s',
|
||||
],
|
||||
'micro interval with microtime' => [
|
||||
1641515890.123456,
|
||||
true,
|
||||
'18999d 0h 38m 10s 1235ms',
|
||||
],
|
||||
'negative interval no microtime' => [
|
||||
-1641515890,
|
||||
false,
|
||||
'-18999d 0h 38m 10s',
|
||||
],
|
||||
// short for mini tests
|
||||
'microtime only' => [
|
||||
0.123456,
|
||||
true,
|
||||
'0s 1235ms',
|
||||
],
|
||||
'seconds only' => [
|
||||
30.123456,
|
||||
true,
|
||||
'30s 1235ms',
|
||||
],
|
||||
'minutes only' => [
|
||||
90.123456,
|
||||
true,
|
||||
'1m 30s 1235ms',
|
||||
],
|
||||
'hours only' => [
|
||||
3690.123456,
|
||||
true,
|
||||
'1h 1m 30s 1235ms',
|
||||
],
|
||||
'days only' => [
|
||||
90090.123456,
|
||||
true,
|
||||
'1d 1h 1m 30s 1235ms',
|
||||
],
|
||||
'already set' => [
|
||||
'1d 1h 1m 30s 1235ms',
|
||||
true,
|
||||
'1d 1h 1m 30s 1235ms',
|
||||
],
|
||||
'invalid data' => [
|
||||
'xyz',
|
||||
true,
|
||||
'0s',
|
||||
],
|
||||
'out of bounds timestamp' => [
|
||||
999999999999999,
|
||||
false,
|
||||
'1s'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function reverseIntervalProvider(): array
|
||||
{
|
||||
return [
|
||||
'interval no microtime' => [
|
||||
'18999d 0h 38m 10s',
|
||||
1641515890,
|
||||
],
|
||||
'micro interval with microtime' => [
|
||||
'18999d 0h 38m 10s 1235ms',
|
||||
1641515890.1235,
|
||||
],
|
||||
'micro interval with microtime' => [
|
||||
'18999d 0h 38m 10s 1234567890ms',
|
||||
1641515890.1234567,
|
||||
],
|
||||
'negative interval no microtime' => [
|
||||
'-18999d 0h 38m 10s',
|
||||
-1641515890,
|
||||
],
|
||||
// short for mini tests
|
||||
'microtime only' => [
|
||||
'0s 1235ms',
|
||||
0.1235,
|
||||
],
|
||||
'seconds only' => [
|
||||
'30s 1235ms',
|
||||
30.1235,
|
||||
],
|
||||
'minutes only' => [
|
||||
'1m 30s 1235ms',
|
||||
90.1235,
|
||||
],
|
||||
'hours only' => [
|
||||
'1h 1m 30s 1235ms',
|
||||
3690.1235,
|
||||
],
|
||||
'days only' => [
|
||||
'1d 1h 1m 30s 1235ms',
|
||||
90090.1235,
|
||||
],
|
||||
'already set' => [
|
||||
1641515890,
|
||||
1641515890,
|
||||
],
|
||||
'invalid data' => [
|
||||
'xyz',
|
||||
'xyz',
|
||||
],
|
||||
'out of bound data' => [
|
||||
'99999999999999999999d',
|
||||
8.64E+24
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function dateProvider(): array
|
||||
{
|
||||
return [
|
||||
'valid date with -' => [
|
||||
'2021-12-12',
|
||||
true,
|
||||
],
|
||||
'valid date with /' => [
|
||||
'2021/12/12',
|
||||
true,
|
||||
],
|
||||
'valid date time with -' => [
|
||||
'2021-12-12 12:12:12',
|
||||
true,
|
||||
],
|
||||
'invalid date' => [
|
||||
'2021-31-31',
|
||||
false,
|
||||
],
|
||||
'invalid date string' => [
|
||||
'xyz',
|
||||
false,
|
||||
],
|
||||
'out of bound date' => [
|
||||
'9999-12-31',
|
||||
true
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function dateTimeProvider(): array
|
||||
{
|
||||
return [
|
||||
'valid date time with -' => [
|
||||
'2021-12-12 12:12:12',
|
||||
true,
|
||||
],
|
||||
'valid date time with /' => [
|
||||
'2021/12/12 12:12:12',
|
||||
true,
|
||||
],
|
||||
'vald date time with hour/min' => [
|
||||
'2021/12/12 12:12',
|
||||
true,
|
||||
],
|
||||
'valid date missing time' => [
|
||||
'2021-12-12',
|
||||
false,
|
||||
],
|
||||
'valid date invalid time string' => [
|
||||
'2021-12-12 ab:cd',
|
||||
false,
|
||||
],
|
||||
'invalid hour +' => [
|
||||
'2021-12-12 35:12',
|
||||
false,
|
||||
],
|
||||
'invalid hour -' => [
|
||||
'2021-12-12 -12:12',
|
||||
false,
|
||||
],
|
||||
'invalid minute +' => [
|
||||
'2021-12-12 23:65:12',
|
||||
false,
|
||||
],
|
||||
'invalid minute -' => [
|
||||
'2021-12-12 23:-12:12',
|
||||
false,
|
||||
],
|
||||
'invalid seconds +' => [
|
||||
'2021-12-12 23:12:99',
|
||||
false,
|
||||
],
|
||||
'invalid seconds -' => [
|
||||
'2021-12-12 23:12:-12',
|
||||
false,
|
||||
],
|
||||
'invalid seconds string' => [
|
||||
'2021-12-12 23:12:ss',
|
||||
false,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function dateCompareProvider(): array
|
||||
{
|
||||
return [
|
||||
'first date smaller' => [
|
||||
'2020-12-12',
|
||||
'2021-12-12',
|
||||
-1,
|
||||
],
|
||||
'dates equal' => [
|
||||
'2020-12-12',
|
||||
'2020-12-12',
|
||||
0,
|
||||
],
|
||||
'second date smaller' => [
|
||||
'2021-12-12',
|
||||
'2020-12-12',
|
||||
1
|
||||
],
|
||||
'dates equal with different time' => [
|
||||
'2020-12-12 12:12:12',
|
||||
'2020-12-12 13:13:13',
|
||||
0,
|
||||
],
|
||||
'invalid dates --' => [
|
||||
'--',
|
||||
'--',
|
||||
false
|
||||
],
|
||||
'empty dates' => [
|
||||
'',
|
||||
'',
|
||||
false
|
||||
],
|
||||
'invalid dates' => [
|
||||
'not a date',
|
||||
'not a date either',
|
||||
false,
|
||||
],
|
||||
'out of bound dates' => [
|
||||
'1900-1-1',
|
||||
'9999-12-31',
|
||||
-1
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function dateTimeCompareProvider(): array
|
||||
{
|
||||
return [
|
||||
'first date smaller no time' => [
|
||||
'2020-12-12',
|
||||
'2021-12-12',
|
||||
-1,
|
||||
],
|
||||
'dates equal no timestamp' => [
|
||||
'2020-12-12',
|
||||
'2020-12-12',
|
||||
0,
|
||||
],
|
||||
'second date smaller no timestamp' => [
|
||||
'2021-12-12',
|
||||
'2020-12-12',
|
||||
1
|
||||
],
|
||||
'date equal first time smaller' => [
|
||||
'2020-12-12 12:12:12',
|
||||
'2020-12-12 13:13:13',
|
||||
-1,
|
||||
],
|
||||
'date equal time equal' => [
|
||||
'2020-12-12 12:12:12',
|
||||
'2020-12-12 12:12:12',
|
||||
0,
|
||||
],
|
||||
'date equal second time smaller' => [
|
||||
'2020-12-12 13:13:13',
|
||||
'2020-12-12 12:12:12',
|
||||
1,
|
||||
],
|
||||
'valid date invalid time' => [
|
||||
'2020-12-12 13:99:13',
|
||||
'2020-12-12 12:12:99',
|
||||
false,
|
||||
],
|
||||
'invalid datetimes --' => [
|
||||
'--',
|
||||
'--',
|
||||
false,
|
||||
],
|
||||
'empty datetimess' => [
|
||||
'',
|
||||
'',
|
||||
false,
|
||||
],
|
||||
'invalid datetimes' => [
|
||||
'not a date',
|
||||
'not a date either',
|
||||
false,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function daysIntervalProvider(): array
|
||||
{
|
||||
return [
|
||||
'valid interval /, not named array' => [
|
||||
'2020/1/1',
|
||||
'2020/1/30',
|
||||
false,
|
||||
[29, 22, 8],
|
||||
],
|
||||
'valid interval /, named array' => [
|
||||
'2020/1/1',
|
||||
'2020/1/30',
|
||||
true,
|
||||
['overall' => 29, 'weekday' => 22, 'weekend' => 8],
|
||||
],
|
||||
'valid interval -' => [
|
||||
'2020-1-1',
|
||||
'2020-1-30',
|
||||
false,
|
||||
[29, 22, 8],
|
||||
],
|
||||
'valid interval switched' => [
|
||||
'2020/1/30',
|
||||
'2020/1/1',
|
||||
false,
|
||||
[28, 0, 0],
|
||||
],
|
||||
'valid interval with time' => [
|
||||
'2020/1/1 12:12:12',
|
||||
'2020/1/30 13:13:13',
|
||||
false,
|
||||
[28, 21, 8],
|
||||
],
|
||||
'invalid dates' => [
|
||||
'abc',
|
||||
'xyz',
|
||||
false,
|
||||
[0, 0, 0]
|
||||
],
|
||||
// this test will take a long imte
|
||||
'out of bound dates' => [
|
||||
'1900-1-1',
|
||||
'9999-12-31',
|
||||
false,
|
||||
[2958463,2113189,845274],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* date string convert test
|
||||
*
|
||||
* @covers ::dateStringFormat
|
||||
* @dataProvider timestampProvider
|
||||
* @testdox dateStringFormat $input (microtime $flag) will be $expected [$_dataName]
|
||||
*
|
||||
* @param int|float $input
|
||||
* @param bool $flag
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testDateStringFormat(
|
||||
$input,
|
||||
bool $flag_show_micro,
|
||||
bool $flag_micro_as_float,
|
||||
string $expected
|
||||
): void {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Combined\DateTime::dateStringFormat(
|
||||
$input,
|
||||
$flag_show_micro,
|
||||
$flag_micro_as_float
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* interval convert test
|
||||
*
|
||||
* @covers ::timeStringFormat
|
||||
* @dataProvider intervalProvider
|
||||
* @testdox timeStringFormat $input (microtime $flag) will be $expected [$_dataName]
|
||||
*
|
||||
* @param int|float $input
|
||||
* @param bool $flag
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testTimeStringFormat($input, bool $flag, string $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Combined\DateTime::timeStringFormat($input, $flag)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::stringToTime
|
||||
* @dataProvider reverseIntervalProvider
|
||||
* @testdox stringToTime $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param string|int|float $input
|
||||
* @param string|int|float $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testStringToTime($input, $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Combined\DateTime::stringToTime($input)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::checkDate
|
||||
* @dataProvider dateProvider
|
||||
* @testdox checkDate $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testCheckDate(string $input, bool $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Combined\DateTime::checkDate($input)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::checkDateTime
|
||||
* @dataProvider dateTimeProvider
|
||||
* @testdox checkDateTime $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testCheckDateTime(string $input, bool $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Combined\DateTime::checkDateTime($input)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::compareDate
|
||||
* @dataProvider dateCompareProvider
|
||||
* @testdox compareDate $input_a compared to $input_b will be $expected [$_dataName]
|
||||
*
|
||||
* @param string $input_a
|
||||
* @param string $input_b
|
||||
* @param int|bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testCompareDate(string $input_a, string $input_b, $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Combined\DateTime::compareDate($input_a, $input_b)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::compareDateTime
|
||||
* @dataProvider dateTimeCompareProvider
|
||||
* @testdox compareDateTime $input_a compared to $input_b will be $expected [$_dataName]
|
||||
*
|
||||
* @param string $input_a
|
||||
* @param string $input_b
|
||||
* @param int|bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testCompareDateTime(string $input_a, string $input_b, $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Combined\DateTime::compareDateTime($input_a, $input_b)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::calcDaysInterval
|
||||
* @dataProvider daysIntervalProvider
|
||||
* @testdox calcDaysInterval $input_a compared to $input_b will be $expected [$_dataName]
|
||||
* @medium
|
||||
*
|
||||
* @param string $input_a
|
||||
* @param string $input_b
|
||||
* @param bool $flag
|
||||
* @param array $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testCalcDaysInterval(
|
||||
string $input_a,
|
||||
string $input_b,
|
||||
bool $flag,
|
||||
$expected
|
||||
): void {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Combined\DateTime::calcDaysInterval($input_a, $input_b, $flag)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function weekdayNumberProvider(): array
|
||||
{
|
||||
return [
|
||||
'0 invalid' => [0, null, 'Inv',],
|
||||
'0 invalid long' => [0, true, 'Invalid',],
|
||||
'1 short' => [1, null, 'Mon',],
|
||||
'1 long' => [1, true, 'Monday',],
|
||||
'2 short' => [2, null, 'Tue',],
|
||||
'2 long' => [2, true, 'Tuesday',],
|
||||
'3 short' => [3, null, 'Wed',],
|
||||
'3 long' => [3, true, 'Wednesday',],
|
||||
'4 short' => [4, null, 'Thu',],
|
||||
'4 long' => [4, true, 'Thursday',],
|
||||
'5 short' => [5, null, 'Fri',],
|
||||
'5 long' => [5, true, 'Friday',],
|
||||
'6 short' => [6, null, 'Sat',],
|
||||
'6 long' => [6, true, 'Saturday',],
|
||||
'7 short' => [7, null, 'Sun',],
|
||||
'7 long' => [7, true, 'Sunday',],
|
||||
'8 invalid' => [8, null, 'Inv',],
|
||||
'8 invalid long' => [8, true, 'Invalid',],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* int weekday number to string weekday
|
||||
*
|
||||
* @covers ::setWeekdayNameFromIsoDow
|
||||
* @dataProvider weekdayNumberProvider
|
||||
* @testdox weekdayListProvider $input (short $flag) will be $expected [$_dataName]
|
||||
*
|
||||
* @param int $input
|
||||
* @param bool|null $flag
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testSetWeekdayNameFromIsoDow(
|
||||
int $input,
|
||||
?bool $flag,
|
||||
string $expected
|
||||
): void {
|
||||
if ($flag === null) {
|
||||
$output = \CoreLibs\Combined\DateTime::setWeekdayNameFromIsoDow($input);
|
||||
} else {
|
||||
$output = \CoreLibs\Combined\DateTime::setWeekdayNameFromIsoDow($input, $flag);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function weekdayDateProvider(): array
|
||||
{
|
||||
return [
|
||||
'invalid date' => ['2022-02-31', -1],
|
||||
'1: monday' => ['2022-07-25', 1],
|
||||
'2: tuesday' => ['2022-07-26', 2],
|
||||
'3: wednesday' => ['2022-07-27', 3],
|
||||
'4: thursday' => ['2022-07-28', 4],
|
||||
'5: friday' => ['2022-07-29', 5],
|
||||
'6: saturday' => ['2022-07-30', 6],
|
||||
'7: sunday' => ['2022-07-31', 7],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* date to weekday number
|
||||
*
|
||||
* @covers ::setWeekdayNumberFromDate
|
||||
* @dataProvider weekdayDateProvider
|
||||
* @testdox setWeekdayNumberFromDate $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param int $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testSetWeekdayNumberFromDate(
|
||||
string $input,
|
||||
int $expected
|
||||
): void {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Combined\DateTime::setWeekdayNumberFromDate($input)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function weekdayDateNameProvider(): array
|
||||
{
|
||||
return [
|
||||
'invalid date short' => ['2022-02-31', null, 'Inv'],
|
||||
'invalid date long' => ['2022-02-31', true, 'Invalid'],
|
||||
'Mon short' => ['2022-07-25', null, 'Mon'],
|
||||
'Monday long' => ['2022-07-25', true, 'Monday'],
|
||||
'Tue short' => ['2022-07-26', null, 'Tue'],
|
||||
'Tuesday long' => ['2022-07-26', true, 'Tuesday'],
|
||||
'Wed short' => ['2022-07-27', null, 'Wed'],
|
||||
'Wednesday long' => ['2022-07-27', true, 'Wednesday'],
|
||||
'Thu short' => ['2022-07-28', null, 'Thu'],
|
||||
'Thursday long' => ['2022-07-28', true, 'Thursday'],
|
||||
'Fri short' => ['2022-07-29', null, 'Fri'],
|
||||
'Friday long' => ['2022-07-29', true, 'Friday'],
|
||||
'Sat short' => ['2022-07-30', null, 'Sat'],
|
||||
'Saturday long' => ['2022-07-30', true, 'Saturday'],
|
||||
'Sun short' => ['2022-07-31', null, 'Sun'],
|
||||
'Sunday long' => ['2022-07-31', true, 'Sunday'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* date to weekday name
|
||||
*
|
||||
* @covers ::setWeekdayNameFromDate
|
||||
* @dataProvider weekdayDateNameProvider
|
||||
* @testdox setWeekdayNameFromDate $input (short $flag) will be $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param bool|null $flag
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testSetWeekdayNameFromDate(
|
||||
string $input,
|
||||
?bool $flag,
|
||||
string $expected
|
||||
): void {
|
||||
if ($flag === null) {
|
||||
$output = \CoreLibs\Combined\DateTime::setWeekdayNameFromDate($input);
|
||||
} else {
|
||||
$output = \CoreLibs\Combined\DateTime::setWeekdayNameFromDate($input, $flag);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$output
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
280
test/phpunit/Convert/CoreLibsConvertByteTest.php
Normal file
280
test/phpunit/Convert/CoreLibsConvertByteTest.php
Normal file
@@ -0,0 +1,280 @@
|
||||
<?php
|
||||
|
||||
// because we have long testdox lines
|
||||
// phpcs:disable Generic.Files.LineLength
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Convert\Byte
|
||||
* @coversDefaultClass \CoreLibs\Convert\Byte
|
||||
* @testdox \CoreLibs\Convert\Byte method tests
|
||||
*/
|
||||
final class CoreLibsConvertByteTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function byteProvider(): array
|
||||
{
|
||||
/*
|
||||
* 0: input string
|
||||
* 1: default flags
|
||||
* 2: BYTE_FORMAT_SI
|
||||
* 3: BYTE_FORMAT_NOSPACE
|
||||
* 4: BYTE_FORMAT_ADJUST
|
||||
* 5: BYTE_FORMAT_SI | BYTE_FORMAT_NOSPACE
|
||||
*/
|
||||
return [
|
||||
'string number' => [
|
||||
0 => '1024',
|
||||
1 => '1 KB',
|
||||
2 => '1.02 KiB',
|
||||
3 => '1KB',
|
||||
4 => '1.00 KB',
|
||||
5 => '1.02KiB',
|
||||
],
|
||||
'invalud string number' => [
|
||||
0 => '1024 MB',
|
||||
1 => '1024 MB',
|
||||
2 => '1024 MB',
|
||||
3 => '1024 MB',
|
||||
4 => '1024 MB',
|
||||
5 => '1024 MB',
|
||||
],
|
||||
'negative number' => [
|
||||
0 => -123123123,
|
||||
1 => '-117.42 MB',
|
||||
2 => '-123.12 MiB',
|
||||
3 => '-117.42MB',
|
||||
4 => '-117.42 MB',
|
||||
5 => '-123.12MiB',
|
||||
],
|
||||
'kilobyte minus one' => [
|
||||
0 => 999999, // KB-1
|
||||
1 => '976.56 KB',
|
||||
2 => '1 MiB',
|
||||
3 => '976.56KB',
|
||||
4 => '976.56 KB',
|
||||
5 => '1MiB',
|
||||
],
|
||||
'megabyte minus one' => [
|
||||
0 => 999999999, // MB-1
|
||||
1 => '953.67 MB',
|
||||
2 => '1 GiB',
|
||||
3 => '953.67MB',
|
||||
4 => '953.67 MB',
|
||||
5 => '1GiB',
|
||||
],
|
||||
'megabyte' => [
|
||||
0 => 254779258,
|
||||
1 => '242.98 MB',
|
||||
2 => '254.78 MiB',
|
||||
3 => '242.98MB',
|
||||
4 => '242.98 MB',
|
||||
5 => '254.78MiB',
|
||||
],
|
||||
'terabyte minus one' => [
|
||||
0 => 999999999999999, // TB-1
|
||||
1 => '909.49 TB',
|
||||
2 => '1 PiB',
|
||||
3 => '909.49TB',
|
||||
4 => '909.49 TB',
|
||||
5 => '1PiB',
|
||||
],
|
||||
'terabyte' => [
|
||||
0 => 588795544887632, // TB-n
|
||||
1 => '535.51 TB',
|
||||
2 => '588.8 TiB',
|
||||
3 => '535.51TB',
|
||||
4 => '535.51 TB',
|
||||
5 => '588.8TiB',
|
||||
],
|
||||
'petabyte minus one' => [
|
||||
0 => 999999999999999999, // PB-1
|
||||
1 => '888.18 PB',
|
||||
2 => '1 EiB',
|
||||
3 => '888.18PB',
|
||||
4 => '888.18 PB',
|
||||
5 => '1EiB',
|
||||
],
|
||||
'max int value' => [
|
||||
0 => 9223372036854775807, // MAX INT
|
||||
1 => '8 EB',
|
||||
2 => '9.22 EiB',
|
||||
3 => '8EB',
|
||||
4 => '8.00 EB',
|
||||
5 => '9.22EiB',
|
||||
],
|
||||
'exabyte minus 1' => [
|
||||
0 => 999999999999999999999, // EB-1
|
||||
1 => '867.36 EB',
|
||||
2 => '1000 EiB',
|
||||
3 => '867.36EB',
|
||||
4 => '867.36 EB',
|
||||
5 => '1000EiB',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function byteStringProvider(): array
|
||||
{
|
||||
return [
|
||||
'negative number' => [
|
||||
0 => '-117.42 MB',
|
||||
1 => -123123794,
|
||||
2 => -117420000,
|
||||
],
|
||||
'megabyte' => [
|
||||
0 => '242.98 MB',
|
||||
1 => 254782996,
|
||||
2 => 242980000
|
||||
],
|
||||
'megabyte si' => [
|
||||
0 => '254.78 MiB',
|
||||
1 => 267156193,
|
||||
2 => 254780000
|
||||
],
|
||||
'petabyte' => [
|
||||
0 => '1 EiB',
|
||||
1 => 1152921504606846976,
|
||||
2 => 1000000000000000000,
|
||||
],
|
||||
'max int' => [
|
||||
0 => '8 EB',
|
||||
1 => -9223372036854775807 - 1,
|
||||
2 => 8000000000000000000,
|
||||
],
|
||||
'exabyte, overflow' => [
|
||||
0 => '867.36EB',
|
||||
1 => 3873816255479021568,
|
||||
2 => 363028535651074048,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::humanReadableByteFormat
|
||||
* @dataProvider byteProvider
|
||||
* @testdox humanReadableByteFormat $input will be $expected, $expected_si SI, $expected_no_space no space, $expected_adjust adjust, $expected_si_no_space SI/no space [$_dataName]
|
||||
*
|
||||
* @param string|int|float $input
|
||||
* @param string $expected
|
||||
* @param string $expected_si
|
||||
* @param string $expected_no_space
|
||||
* @param string $expected_adjust
|
||||
* @param string $expected_si_no_space
|
||||
* @return void
|
||||
*/
|
||||
public function testHumanReadableByteFormat(
|
||||
$input,
|
||||
string $expected,
|
||||
string $expected_si,
|
||||
string $expected_no_space,
|
||||
string $expected_adjust,
|
||||
string $expected_si_no_space
|
||||
): void {
|
||||
// 1024
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Byte::humanReadableByteFormat($input)
|
||||
);
|
||||
// 1000
|
||||
$this->assertEquals(
|
||||
$expected_si,
|
||||
\CoreLibs\Convert\Byte::humanReadableByteFormat($input, \CoreLibs\Convert\Byte::BYTE_FORMAT_SI)
|
||||
);
|
||||
// no space
|
||||
$this->assertEquals(
|
||||
$expected_no_space,
|
||||
\CoreLibs\Convert\Byte::humanReadableByteFormat($input, \CoreLibs\Convert\Byte::BYTE_FORMAT_NOSPACE)
|
||||
);
|
||||
// always 2 decimals
|
||||
$this->assertEquals(
|
||||
$expected_adjust,
|
||||
\CoreLibs\Convert\Byte::humanReadableByteFormat($input, \CoreLibs\Convert\Byte::BYTE_FORMAT_ADJUST)
|
||||
);
|
||||
// combined si + no space
|
||||
$this->assertEquals(
|
||||
$expected_si_no_space,
|
||||
\CoreLibs\Convert\Byte::humanReadableByteFormat(
|
||||
$input,
|
||||
\CoreLibs\Convert\Byte::BYTE_FORMAT_SI | \CoreLibs\Convert\Byte::BYTE_FORMAT_NOSPACE
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::stringByteFormat
|
||||
* @dataProvider byteStringProvider
|
||||
* @testdox stringByteFormat $input will be $expected and $expected_si SI [$_dataName]
|
||||
*
|
||||
* @param string|int|float $input
|
||||
* @param string|int|float $expected
|
||||
* @param string|int|float $expected_si
|
||||
* @return void
|
||||
*/
|
||||
public function testStringByteFormat($input, $expected, $expected_si): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Byte::stringByteFormat($input)
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected_si,
|
||||
\CoreLibs\Convert\Byte::stringByteFormat($input, \CoreLibs\Convert\Byte::BYTE_FORMAT_SI)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exceptions tests
|
||||
*
|
||||
* @covers ::humanReadableByteFormat
|
||||
* @testWith [99]
|
||||
* @testdox Test exception for humanReadableByteFormat with flag $flag
|
||||
*
|
||||
* @param int $flag
|
||||
* @return void
|
||||
*/
|
||||
public function testHumanReadableByteFormatException(int $flag): void
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
\CoreLibs\Convert\Byte::humanReadableByteFormat(12, $flag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exceptions tests
|
||||
* can only be 4, try 1,2 and over
|
||||
*
|
||||
* @covers ::stringByteFormat
|
||||
* @testWith [1]
|
||||
* [2]
|
||||
* [99]
|
||||
* @testdox Test exception for stringByteFormat with flag $flag
|
||||
*
|
||||
* @param int $flag
|
||||
* @return void
|
||||
*/
|
||||
public function testStringByteFormatException(int $flag): void
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
\CoreLibs\Convert\Byte::stringByteFormat(12, $flag);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
420
test/phpunit/Convert/CoreLibsConvertColorsTest.php
Normal file
420
test/phpunit/Convert/CoreLibsConvertColorsTest.php
Normal file
@@ -0,0 +1,420 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Convert\Colors
|
||||
* @coversDefaultClass \CoreLibs\Convert\Colors
|
||||
* @testdox \CoreLibs\Convert\Colors method tests
|
||||
*/
|
||||
final class CoreLibsConvertColorsTest extends TestCase
|
||||
{
|
||||
// convert list
|
||||
public static $colors = [];
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rgb2hexColorProvider(): array
|
||||
{
|
||||
return [
|
||||
'color' => [
|
||||
0 => 10,
|
||||
1 => 100,
|
||||
2 => 200,
|
||||
3 => '#0a64c8',
|
||||
4 => '0a64c8'
|
||||
],
|
||||
'gray' => [
|
||||
0 => 12,
|
||||
1 => 12,
|
||||
2 => 12,
|
||||
3 => '#0c0c0c',
|
||||
4 => '0c0c0c',
|
||||
],
|
||||
'black' => [
|
||||
0 => 0,
|
||||
1 => 0,
|
||||
2 => 0,
|
||||
3 => '#000000',
|
||||
4 => '000000',
|
||||
],
|
||||
'white' => [
|
||||
0 => 255,
|
||||
1 => 255,
|
||||
2 => 255,
|
||||
3 => '#ffffff',
|
||||
4 => 'ffffff',
|
||||
],
|
||||
'invalid color red & green' => [
|
||||
0 => -12,
|
||||
1 => 300,
|
||||
2 => 12,
|
||||
3 => false,
|
||||
4 => false
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function hex2rgbColorProvider(): array
|
||||
{
|
||||
return [
|
||||
'color' => [
|
||||
0 => '#0a64c8',
|
||||
1 => ['r' => 10, 'g' => 100, 'b' => 200],
|
||||
2 => '10,100,200',
|
||||
3 => ';',
|
||||
4 => '10;100;200',
|
||||
],
|
||||
'gray, long' => [
|
||||
0 => '0c0c0c',
|
||||
1 => ['r' => 12, 'g' => 12, 'b' => 12],
|
||||
2 => '12,12,12',
|
||||
3 => ';',
|
||||
4 => '12;12;12',
|
||||
],
|
||||
'gray, short' => [
|
||||
0 => 'ccc',
|
||||
1 => ['r' => 204, 'g' => 204, 'b' => 204],
|
||||
2 => '204,204,204',
|
||||
3 => ';',
|
||||
4 => '204;204;204',
|
||||
],
|
||||
'hex string with #' => [
|
||||
0 => '#0c0c0c',
|
||||
1 => ['r' => 12, 'g' => 12, 'b' => 12],
|
||||
2 => '12,12,12',
|
||||
3 => ';',
|
||||
4 => '12;12;12',
|
||||
],
|
||||
'a too long hex string' => [
|
||||
0 => '#0c0c0c0c',
|
||||
1 => false,
|
||||
2 => false,
|
||||
3 => ';',
|
||||
4 => false,
|
||||
],
|
||||
'a too short hex string' => [
|
||||
0 => '0c0c',
|
||||
1 => false,
|
||||
2 => false,
|
||||
3 => ';',
|
||||
4 => false,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rgb2hslAndhsbList(): array
|
||||
{
|
||||
// if hsb_from or hsl_from is set, this will be used in hsb/hsl convert
|
||||
// hsb_rgb is used for adjusted rgb valus due to round error to in
|
||||
return [
|
||||
'valid gray' => [
|
||||
'rgb' => [12, 12, 12],
|
||||
'hsb' => [0, 0, 5],
|
||||
'hsb_rgb' => [13, 13, 13], // should be rgb, but rounding in this
|
||||
'hsl' => [0.0, 0.0, 4.7],
|
||||
'valid' => true,
|
||||
],
|
||||
'valid color' => [
|
||||
'rgb' => [10, 100, 200],
|
||||
'hsb' => [212, 95, 78.0],
|
||||
'hsb_rgb' => [10, 98, 199], // should be rgb, but rounding error
|
||||
'hsl' => [211.6, 90.5, 41.2],
|
||||
'valid' => true,
|
||||
],
|
||||
// hsg/hsl with 360 which is seen as 0
|
||||
'valid color hue 360' => [
|
||||
'rgb' => [200, 10, 10],
|
||||
'hsb' => [0, 95, 78.0],
|
||||
'hsb_from' => [360, 95, 78.0],
|
||||
'hsb_rgb' => [199, 10, 10], // should be rgb, but rounding error
|
||||
'hsl' => [0.0, 90.5, 41.2],
|
||||
'hsl_from' => [360.0, 90.5, 41.2],
|
||||
'valid' => true,
|
||||
],
|
||||
// invalid values
|
||||
'invalid color' => [
|
||||
'rgb' => [-12, 300, 12],
|
||||
'hsb' => [-12, 300, 12],
|
||||
'hsl' => [-12, 300, 12],
|
||||
'valid' => false,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rgb2hsbColorProvider(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->rgb2hslAndhsbList() as $name => $values) {
|
||||
$list[$name . ', rgb to hsb'] = [
|
||||
0 => $values['rgb'][0],
|
||||
1 => $values['rgb'][1],
|
||||
2 => $values['rgb'][2],
|
||||
3 => $values['valid'] ? $values['hsb'] : false
|
||||
];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function hsb2rgbColorProvider(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->rgb2hslAndhsbList() as $name => $values) {
|
||||
$list[$name . ', hsb to rgb'] = [
|
||||
0 => $values['hsb_from'][0] ?? $values['hsb'][0],
|
||||
1 => $values['hsb_from'][1] ?? $values['hsb'][1],
|
||||
2 => $values['hsb_from'][2] ?? $values['hsb'][2],
|
||||
3 => $values['valid'] ? $values['hsb_rgb'] : false
|
||||
];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rgb2hslColorProvider(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->rgb2hslAndhsbList() as $name => $values) {
|
||||
$list[$name . ', rgb to hsl'] = [
|
||||
0 => $values['rgb'][0],
|
||||
1 => $values['rgb'][1],
|
||||
2 => $values['rgb'][2],
|
||||
3 => $values['valid'] ? $values['hsl'] : false
|
||||
];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function hsl2rgbColorProvider(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->rgb2hslAndhsbList() as $name => $values) {
|
||||
$list[$name . ', hsl to rgb'] = [
|
||||
0 => $values['hsl_from'][0] ?? $values['hsl'][0],
|
||||
1 => $values['hsl_from'][1] ?? $values['hsl'][1],
|
||||
2 => $values['hsl_from'][2] ?? $values['hsl'][2],
|
||||
3 => $values['valid'] ? $values['rgb'] : false
|
||||
];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* TODO: add cross convert check
|
||||
*
|
||||
* @covers ::rgb2hex
|
||||
* @dataProvider rgb2hexColorProvider
|
||||
* @testdox rgb2hex $input_r,$input_g,$input_b will be $expected [$_dataName]
|
||||
*
|
||||
* @param int $input_r
|
||||
* @param int $input_g
|
||||
* @param int $input_b
|
||||
* @param string|bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testRgb2hex(int $input_r, int $input_g, int $input_b, $expected_hash, $expected)
|
||||
{
|
||||
// with #
|
||||
$this->assertEquals(
|
||||
$expected_hash,
|
||||
\CoreLibs\Convert\Colors::rgb2hex($input_r, $input_g, $input_b)
|
||||
);
|
||||
// without #
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Colors::rgb2hex($input_r, $input_g, $input_b, false)
|
||||
);
|
||||
// cross convert must match
|
||||
// $rgb = \CoreLibs\Convert\Colors::hex2rgb($expected_hash);
|
||||
// if ($rgb === false) {
|
||||
// $rgb = [
|
||||
// 'r' => $input_r,
|
||||
// 'g' => $input_g,
|
||||
// 'b' => $input_b,
|
||||
// ];
|
||||
// }
|
||||
// $this->assertEquals(
|
||||
// $expected_hash,
|
||||
// \CoreLibs\Convert\Colors::rgb2hex($rgb['r'], $rgb['g'], $rgb['b'])
|
||||
// );
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::hex2rgb
|
||||
* @dataProvider hex2rgbColorProvider
|
||||
* @testdox hex2rgb $input will be $expected, $expected_str str[,], $expected_str_sep str[$separator] [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param array|bool $expected
|
||||
* @param string|bool $expected_str
|
||||
* @param string $separator
|
||||
* @param string|bool $expected_str_sep
|
||||
* @return void
|
||||
*/
|
||||
public function testHex2rgb(
|
||||
string $input,
|
||||
$expected,
|
||||
$expected_str,
|
||||
string $separator,
|
||||
$expected_str_sep
|
||||
): void {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Colors::hex2rgb($input)
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected_str,
|
||||
\CoreLibs\Convert\Colors::hex2rgb($input, true)
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected_str_sep,
|
||||
\CoreLibs\Convert\Colors::hex2rgb($input, true, $separator)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::rgb2hsb
|
||||
* @dataProvider rgb2hsbColorProvider
|
||||
* @testdox rgb2hsb $input_r,$input_g,$input_b will be $expected [$_dataName]
|
||||
*
|
||||
* @param integer $input_r
|
||||
* @param integer $input_g
|
||||
* @param integer $input_b
|
||||
* @param array|bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testRgb2hsb(int $input_r, int $input_g, int $input_b, $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Colors::rgb2hsb($input_r, $input_g, $input_b)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::hsb2rgb
|
||||
* @dataProvider hsb2rgbColorProvider
|
||||
* @testdox hsb2rgb $input_h,$input_s,$input_b will be $expected [$_dataName]
|
||||
*
|
||||
* @param float $input_h
|
||||
* @param float $input_s
|
||||
* @param float $input_b
|
||||
* @param array|bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testHsb2rgb(float $input_h, float $input_s, float $input_b, $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Colors::hsb2rgb($input_h, $input_s, $input_b)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::rgb2hsl
|
||||
* @dataProvider rgb2hslColorProvider
|
||||
* @testdox rgb2hsl $input_r,$input_g,$input_b will be $expected [$_dataName]
|
||||
*
|
||||
* @param integer $input_r
|
||||
* @param integer $input_g
|
||||
* @param integer $input_b
|
||||
* @param array|bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testRgb2hsl(int $input_r, int $input_g, int $input_b, $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Colors::rgb2hsl($input_r, $input_g, $input_b)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::hsl2rgb
|
||||
* @dataProvider hsl2rgbColorProvider
|
||||
* @testdox hsl2rgb $input_h,$input_s,$input_l will be $expected [$_dataName]
|
||||
*
|
||||
* @param integer|float $input_h
|
||||
* @param integer $input_s
|
||||
* @param integer $input_l
|
||||
* @param array|bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testHsl2rgb($input_h, float $input_s, float $input_l, $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Colors::hsl2rgb($input_h, $input_s, $input_l)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* edge case check hsl/hsb and hue 360 (= 0)
|
||||
*
|
||||
* @covers ::hsl2rgb
|
||||
* @covers ::hsb2rgb
|
||||
* @testdox hsl2rgb/hsb2rgb hue 360 valid check
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testHslHsb360hue(): void
|
||||
{
|
||||
$this->assertNotFalse(
|
||||
\CoreLibs\Convert\Colors::hsl2rgb(360.0, 90.5, 41.2),
|
||||
'HSL to RGB with 360 hue'
|
||||
);
|
||||
$this->assertNotFalse(
|
||||
\CoreLibs\Convert\Colors::hsb2rgb(360, 95, 78.0),
|
||||
'HSB to RGB with 360 hue'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
102
test/phpunit/Convert/CoreLibsConvertEncodingTest.php
Normal file
102
test/phpunit/Convert/CoreLibsConvertEncodingTest.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Convert\Encoding
|
||||
* @coversDefaultClass \CoreLibs\Convert\Encoding
|
||||
* @testdox \CoreLibs\Convert\Encoding method tests
|
||||
*/
|
||||
final class CoreLibsConvertEncodingTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function convertEncodingProvider(): array
|
||||
{
|
||||
return [
|
||||
// 0: original string
|
||||
// 1: target encoding
|
||||
// 2: optional source encoding
|
||||
// 3: auto check (not used)
|
||||
// 4: expected string
|
||||
// 5: expected string encoding
|
||||
'simple from UTF-8 to SJIS' => [
|
||||
'input string',
|
||||
'SJIS',
|
||||
null,
|
||||
null,
|
||||
'input string',
|
||||
'SJIS'
|
||||
],
|
||||
'kanji from UTF-8 to SJIS' => [
|
||||
'日本語',
|
||||
'SJIS',
|
||||
null,
|
||||
null,
|
||||
'日本語',
|
||||
'SJIS'
|
||||
],
|
||||
'kanji from UTF-8 to SJIS with source' => [
|
||||
'日本語',
|
||||
'SJIS',
|
||||
'UTF-8',
|
||||
null,
|
||||
'日本語',
|
||||
'SJIS'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::convertEncoding
|
||||
* @dataProvider convertEncodingProvider
|
||||
* @testdox convert encoding $target_encoding, source: $source_encoding, auto: $auto_check [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $target_encoding
|
||||
* @param string $source_encoding
|
||||
* @param bool $auto_check
|
||||
* @param string $expected
|
||||
* @param string $expected_encoding
|
||||
* @return void
|
||||
*/
|
||||
public function testConvertEncoding(
|
||||
string $input,
|
||||
string $target_encoding,
|
||||
?string $source_encoding,
|
||||
?bool $auto_check,
|
||||
string $expected,
|
||||
string $expected_encoding
|
||||
): void {
|
||||
if ($source_encoding === null and $auto_check === null) {
|
||||
$string = \CoreLibs\Convert\Encoding::convertEncoding($input, $target_encoding);
|
||||
} elseif ($auto_check === null) {
|
||||
$string = \CoreLibs\Convert\Encoding::convertEncoding($input, $target_encoding, $source_encoding);
|
||||
} else {
|
||||
$string = \CoreLibs\Convert\Encoding::convertEncoding(
|
||||
$input,
|
||||
$target_encoding,
|
||||
$source_encoding,
|
||||
$auto_check
|
||||
);
|
||||
}
|
||||
// because we can't store encoding in here anyway
|
||||
$target = mb_convert_encoding($expected, $expected_encoding, 'UTF-8');
|
||||
// print "IN: $input, $target_encoding\n";
|
||||
$this->assertEquals(
|
||||
$target,
|
||||
$string
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
188
test/phpunit/Convert/CoreLibsConvertHtmlTest.php
Normal file
188
test/phpunit/Convert/CoreLibsConvertHtmlTest.php
Normal file
@@ -0,0 +1,188 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Convert\Html
|
||||
* @coversDefaultClass \CoreLibs\Convert\Html
|
||||
* @testdox \CoreLibs\Convert\Html method tests
|
||||
*/
|
||||
final class CoreLibsConvertHtmlTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function htmlentProvider(): array
|
||||
{
|
||||
return [
|
||||
'no conversion' => [
|
||||
0 => 'I am some string',
|
||||
1 => 'I am some string',
|
||||
],
|
||||
'conversion' => [
|
||||
0 => 'I have special <> inside',
|
||||
1 => 'I have special <> inside',
|
||||
],
|
||||
'skip number' => [
|
||||
0 => 1234,
|
||||
1 => 1234,
|
||||
],
|
||||
'utf8' => [
|
||||
0 => '日本語 <>',
|
||||
1 => '日本語 <>'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function removeLBProvider(): array
|
||||
{
|
||||
return [
|
||||
'nothing replaced, default' => [
|
||||
0 => 'I am some string',
|
||||
1 => null,
|
||||
2 => 'I am some string',
|
||||
],
|
||||
'string with \n replace -' => [
|
||||
0 => "I am\nsome string",
|
||||
1 => '-',
|
||||
2 => 'I am-some string',
|
||||
],
|
||||
'string with \r replace _' => [
|
||||
0 => "I am\rsome string",
|
||||
1 => '_',
|
||||
2 => 'I am_some string',
|
||||
],
|
||||
'string with \n\r, default' => [
|
||||
0 => "I am\n\rsome string",
|
||||
1 => null,
|
||||
2 => 'I am some string',
|
||||
],
|
||||
'string with \n\r replae ##BR##' => [
|
||||
0 => "I am\n\rsome string",
|
||||
1 => '##BR##',
|
||||
2 => 'I am##BR##some string',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function checkedProvider(): array
|
||||
{
|
||||
return [
|
||||
'haystack is a string and matching selected' => [
|
||||
0 => 'string',
|
||||
1 => 'string',
|
||||
2 => \CoreLibs\Convert\Html::SELECTED,
|
||||
3 => 'selected'
|
||||
],
|
||||
'haystack is a string and matching checked' => [
|
||||
0 => 'string',
|
||||
1 => 'string',
|
||||
2 => \CoreLibs\Convert\Html::CHECKED,
|
||||
3 => 'checked'
|
||||
],
|
||||
'haystack is a string and not matching' => [
|
||||
0 => 'string',
|
||||
1 => 'not matching',
|
||||
2 => \CoreLibs\Convert\Html::CHECKED,
|
||||
3 => null
|
||||
],
|
||||
'haystack is array and matching' => [
|
||||
0 => ['a', 'b', 'c'],
|
||||
1 => 'a',
|
||||
2 => \CoreLibs\Convert\Html::SELECTED,
|
||||
3 => 'selected'
|
||||
],
|
||||
'haystack is array and not matching' => [
|
||||
0 => ['a', 'b', 'c'],
|
||||
1 => 'not matching',
|
||||
2 => \CoreLibs\Convert\Html::SELECTED,
|
||||
3 => null
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::htmlent
|
||||
* @dataProvider htmlentProvider
|
||||
* @testdox htmlent $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param mixed $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testHtmlent($input, $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Html::htmlent($input)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::removeLB
|
||||
* @dataProvider removeLBProvider
|
||||
* @testdox removeLB $input with replace $replace will be $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string|null $replace
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testRemoveLB(string $input, ?string $replace, string $expected): void
|
||||
{
|
||||
if ($replace !== null) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Html::removeLB($input, $replace)
|
||||
);
|
||||
} else {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Html::removeLB($input)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::checked
|
||||
* @dataProvider checkedProvider
|
||||
* @testdox checked find $needle in $haystack and return $type will be $expected [$_dataName]
|
||||
*
|
||||
* @param array<mixed>|string $haystack
|
||||
* @param string $needle
|
||||
* @param integer $type
|
||||
* @param string|null $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testChecked($haystack, string $needle, int $type, ?string $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Html::checked($haystack, $needle, $type)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
166
test/phpunit/Convert/CoreLibsConvertJsonTest.php
Normal file
166
test/phpunit/Convert/CoreLibsConvertJsonTest.php
Normal file
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Check\Json
|
||||
* @coversDefaultClass \CoreLibs\Convert\Json
|
||||
* @testdox \CoreLibs\Convert\Json method tests
|
||||
*/
|
||||
final class CoreLibsConvertJsonTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* test list for json convert tests
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function jsonProvider(): array
|
||||
{
|
||||
return [
|
||||
'valid json' => [
|
||||
'{"m":2,"f":"sub_2"}',
|
||||
false,
|
||||
[
|
||||
'm' => 2,
|
||||
'f' => 'sub_2'
|
||||
]
|
||||
],
|
||||
'empty json' => [
|
||||
'',
|
||||
false,
|
||||
[]
|
||||
],
|
||||
'invalid json override' => [
|
||||
'not valid',
|
||||
true,
|
||||
[
|
||||
'not valid'
|
||||
]
|
||||
],
|
||||
'invalid json' => [
|
||||
'not valid',
|
||||
false,
|
||||
[]
|
||||
],
|
||||
'null json' => [
|
||||
null,
|
||||
false,
|
||||
[]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* json error list
|
||||
*
|
||||
* @return array JSON error list
|
||||
*/
|
||||
public function jsonErrorProvider(): array
|
||||
{
|
||||
return [
|
||||
'no error' => [
|
||||
'{}',
|
||||
JSON_ERROR_NONE, ''
|
||||
],
|
||||
'depth error' => [
|
||||
'[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[['
|
||||
. '[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[['
|
||||
. '[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[['
|
||||
. '[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[['
|
||||
. '[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[['
|
||||
. '[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[['
|
||||
. '[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[['
|
||||
. '[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[['
|
||||
. '[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]'
|
||||
. ']]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]'
|
||||
. ']]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]'
|
||||
. ']]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]'
|
||||
. ']]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]'
|
||||
. ']]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]'
|
||||
. ']]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]'
|
||||
. ']]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]'
|
||||
. ']]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]'
|
||||
. ']]]]',
|
||||
JSON_ERROR_DEPTH, 'Maximum stack depth exceeded'
|
||||
],
|
||||
// 'state mismatch error' => [
|
||||
// '{foo:}',
|
||||
// JSON_ERROR_STATE_MISMATCH, 'Underflow or the modes mismatch'
|
||||
// ],
|
||||
// 'ctrl char error' => [
|
||||
// ' {"data":"data","data":"data","data":"data","data":"data"}',
|
||||
// JSON_ERROR_CTRL_CHAR, 'Unexpected control character found'
|
||||
// ],
|
||||
'syntax error' => [
|
||||
'not valid',
|
||||
JSON_ERROR_SYNTAX, 'Syntax error, malformed JSON'
|
||||
],
|
||||
// 'utf8 error' => [
|
||||
// '{"invalid":"\xB1\x31"}',
|
||||
// JSON_ERROR_UTF8, 'Malformed UTF-8 characters, possibly incorrectly encoded'
|
||||
// ],
|
||||
// 'invalid property' => [
|
||||
// '{"\u0000":"abc"}',
|
||||
// JSON_ERROR_INVALID_PROPERTY_NAME, 'A key starting with \u0000 character was in the string'
|
||||
// ],
|
||||
// 'utf-16 error' => [
|
||||
// '',
|
||||
// JSON_ERROR_UTF16, 'Single unpaired UTF-16 surrogate in unicode escape'
|
||||
// ],
|
||||
// 'unknown error' => [
|
||||
// '',
|
||||
// -999999, 'Unknown error'
|
||||
// ]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* test json convert states
|
||||
*
|
||||
* @covers ::jsonConvertToArray
|
||||
* @dataProvider jsonProvider
|
||||
* @testdox jsonConvertToArray $input (Override: $flag) will be $expected [$_dataName]
|
||||
*
|
||||
* @param string|null $input
|
||||
* @param bool $flag
|
||||
* @param array $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testJsonConvertToArray(?string $input, bool $flag, array $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Json::jsonConvertToArray($input, $flag)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test json error states
|
||||
*
|
||||
* @covers ::jsonGetLastError
|
||||
* @dataProvider jsonErrorProvider
|
||||
* @testdox jsonGetLastError $input will be $expected_i/$expected_s [$_dataName]
|
||||
*
|
||||
* @param string|null $input
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testJsonGetLastError(?string $input, int $expected_i, string $expected_s): void
|
||||
{
|
||||
\CoreLibs\Convert\Json::jsonConvertToArray($input);
|
||||
$this->assertEquals(
|
||||
$expected_i,
|
||||
\CoreLibs\Convert\Json::jsonGetLastError()
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected_s,
|
||||
\CoreLibs\Convert\Json::jsonGetLastError(true)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
118
test/phpunit/Convert/CoreLibsConvertMathTest.php
Normal file
118
test/phpunit/Convert/CoreLibsConvertMathTest.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Undocumented class
|
||||
* @coversDefaultClass \CoreLibs\Convert\Math
|
||||
* @testdox \CoreLibs\Convert\Math method tests
|
||||
*/
|
||||
final class CoreLibsConvertMathTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function fceilProvider(): array
|
||||
{
|
||||
return [
|
||||
'5.5 must be 6' => [5.5, 6],
|
||||
'5.1234567890 with 5 must be 6' => [5.1234567890, 6],
|
||||
'6 must be 6' => [6, 6]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::fceil
|
||||
* @dataProvider fceilProvider
|
||||
* @testdox fceil: Input $input must be $expected
|
||||
*
|
||||
* @param float $input
|
||||
* @param int $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testMathFceilValue(float $input, int $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Math::fceil($input)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function floorProvider(): array
|
||||
{
|
||||
return [
|
||||
'5123456 with -3 must be 5123000' => [5123456, -3, 5123000],
|
||||
'5123456 with -10 must be 5000000' => [5123456, -10, 5000000]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::floorp
|
||||
* @dataProvider floorProvider
|
||||
* @testdox floor: Input $input with cutoff $cutoff must be $expected
|
||||
*
|
||||
* @param int $input
|
||||
* @param int $cutoff
|
||||
* @param int $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testMathFloorValue(int $input, int $cutoff, int $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Math::floorp($input, $cutoff)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function initNumericProvider(): array
|
||||
{
|
||||
return [
|
||||
'5 must be 5' => [5, 5, 'int'],
|
||||
'5.123 must be 5.123' => [5.123, 5.123, 'float'],
|
||||
"'5' must be 5" => ['5', 5, 'string'],
|
||||
"'5.123' must be 5.123" => ['5.123', 5.123, 'string'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::initNumeric
|
||||
* @dataProvider initNumericProvider
|
||||
* @testdox initNumeric: Input $info $input must match $expected [$_dataName]
|
||||
*
|
||||
* @param int|float|string $input
|
||||
* @param float $expected
|
||||
* @param string $info
|
||||
* @return void
|
||||
*/
|
||||
public function testMathInitNumericValue($input, float $expected, string $info): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Math::initNumeric($input)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
60
test/phpunit/Convert/CoreLibsConvertMimeAppNameTest.php
Normal file
60
test/phpunit/Convert/CoreLibsConvertMimeAppNameTest.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Convert\MimeAppName
|
||||
* @coversDefaultClass \CoreLibs\Convert\MimeAppName
|
||||
* @testdox \CoreLibs\Convert\MimeAppName method tests
|
||||
*/
|
||||
final class CoreLibsConvertMimeAppNameTest extends TestCase
|
||||
{
|
||||
|
||||
public function mimeProvider(): array
|
||||
{
|
||||
return [
|
||||
'find matching app' => [
|
||||
0 => 'foo/bar',
|
||||
1 => 'FooBar Application',
|
||||
2 => 'FooBar Application',
|
||||
],
|
||||
'try to set empty mime type' => [
|
||||
0 => '',
|
||||
1 => 'Some app',
|
||||
2 => 'Other file'
|
||||
],
|
||||
'try to set empty app name' => [
|
||||
0 => 'some/app',
|
||||
1 => '',
|
||||
2 => 'Other file'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::mimeGetAppName
|
||||
* @covers ::mimeSetAppName
|
||||
* @dataProvider mimeProvider
|
||||
* @testdox mimeSetAppName set $mime with $app and will be $expected [$_dataName]
|
||||
*
|
||||
* @param string $mime
|
||||
* @param string $app
|
||||
* @return void
|
||||
*/
|
||||
public function testMimeSetAppName(string $mime, string $app, string $expected): void
|
||||
{
|
||||
\CoreLibs\Convert\MimeAppName::mimeSetAppName($mime, $app);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\MimeAppName::mimeGetAppName($mime)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
101
test/phpunit/Convert/CoreLibsConvertMimeEncodeTest.php
Normal file
101
test/phpunit/Convert/CoreLibsConvertMimeEncodeTest.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Convert\MimeEncode
|
||||
* @coversDefaultClass \CoreLibs\Convert\MimeEncode
|
||||
* @testdox \CoreLibs\Convert\MimeEncode method tests
|
||||
*/
|
||||
final class CoreLibsConvertMimeEncodeTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function mbMimeEncodeProvider(): array
|
||||
{
|
||||
return [
|
||||
// 0: input string
|
||||
// 1: encoding
|
||||
// 2: expected
|
||||
'standard UTF-8' => [
|
||||
'Test string',
|
||||
'UTF-8',
|
||||
'Test string'
|
||||
],
|
||||
'long text UTF-8' => [
|
||||
'The quick brown fox jumps over the lazy sheep that sleeps in the ravine '
|
||||
. 'and has no idea what is going on here',
|
||||
'UTF-8',
|
||||
'The quick brown fox jumps over the lazy sheep that sleeps in the ravine '
|
||||
. 'and has no idea what is going on here'
|
||||
],
|
||||
'standard with special chars UTF-8' => [
|
||||
'This is ümläßtと漢字もカタカナ!!^$%&',
|
||||
'UTF-8',
|
||||
'This is =?UTF-8?B?w7xtbMOkw59044Go5ryi5a2X44KC44Kr44K/44Kr44OK77yBIV4k?='
|
||||
. "\r\n"
|
||||
. ' =?UTF-8?B?JQ==?=&'
|
||||
],
|
||||
'35 chars and space at the end UTF-8' => [
|
||||
'12345678901234567890123456789012345 '
|
||||
. 'is there a space?',
|
||||
'UTF-8',
|
||||
'12345678901234567890123456789012345 '
|
||||
. 'is there a =?UTF-8?B?c3BhY2U/?='
|
||||
],
|
||||
'36 chars and space at the end UTF-8' => [
|
||||
'123456789012345678901234567890123456 '
|
||||
. 'is there a space?',
|
||||
'UTF-8',
|
||||
'123456789012345678901234567890123456 '
|
||||
. 'is there a =?UTF-8?B?c3BhY2U/?='
|
||||
],
|
||||
'36 kanji and space UTF-8' => [
|
||||
'カタカナカタカナかなカタカナカタカナかなカタカナカタカナかなカタカナカタ '
|
||||
. 'is there a space?',
|
||||
'UTF-8',
|
||||
"=?UTF-8?B?44Kr44K/44Kr44OK44Kr44K/44Kr44OK44GL44Gq44Kr44K/44Kr44OK44Kr?=\r\n"
|
||||
. " =?UTF-8?B?44K/44Kr44OK?=\r\n"
|
||||
. " =?UTF-8?B?44GL44Gq44Kr44K/44Kr44OK44Kr44K/44Kr44OK44GL44Gq44Kr44K/44Kr?=\r\n"
|
||||
. " =?UTF-8?B?44OK44Kr44K/?= is there a =?UTF-8?B?c3BhY2U/?="
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* mb mime header encoding test
|
||||
*
|
||||
* @covers ::__mbMimeEncode
|
||||
* @dataProvider mbMimeEncodeProvider
|
||||
* @testdox mb encoding target $encoding [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testUuMbMimeEncode(string $input, string $encoding, string $expected): void
|
||||
{
|
||||
// encode string first
|
||||
$encoded = \CoreLibs\Convert\MimeEncode::__mbMimeEncode($input, $encoding);
|
||||
// print "MIME: -" . $encoded . "-\n";
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$encoded
|
||||
);
|
||||
$decoded = mb_decode_mimeheader($encoded);
|
||||
// print "INPUT : " . $input . "\n";
|
||||
// print "DECODED: " . $decoded . "\n";
|
||||
// back compare decoded
|
||||
$this->assertEquals(
|
||||
$input,
|
||||
$decoded
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
652
test/phpunit/Convert/CoreLibsConvertSetVarTypeNullTest.php
Normal file
652
test/phpunit/Convert/CoreLibsConvertSetVarTypeNullTest.php
Normal file
@@ -0,0 +1,652 @@
|
||||
<?php // phpcs:disable Generic.Files.LineLength
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use CoreLibs\Convert\SetVarTypeNull;
|
||||
|
||||
/**
|
||||
* Test class for Convert\Strings
|
||||
* @coversDefaultClass \CoreLibs\Convert\SetVarTypeNull
|
||||
* @testdox \CoreLibs\Convert\SetVarTypeNull method tests
|
||||
*/
|
||||
final class CoreLibsConvertSetVarTypeNullTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function varSetTypeStringProvider(): array
|
||||
{
|
||||
// 0: input
|
||||
// 1: default (null default)
|
||||
// 2: expected
|
||||
return [
|
||||
'empty string' => [
|
||||
'',
|
||||
null,
|
||||
''
|
||||
],
|
||||
'filled string' => [
|
||||
'string',
|
||||
null,
|
||||
'string'
|
||||
],
|
||||
'valid string, override set' => [
|
||||
'string',
|
||||
'override',
|
||||
'string'
|
||||
],
|
||||
'int, no override' => [
|
||||
1,
|
||||
null,
|
||||
null
|
||||
],
|
||||
'int, override set' => [
|
||||
1,
|
||||
'not int',
|
||||
'not int'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* @covers ::setStr
|
||||
* @dataProvider varSetTypeStringProvider
|
||||
* @testdox setStr $input with override $default will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param string|null $default
|
||||
* @param string|null $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testSetString(mixed $input, ?string $default, ?string $expected): void
|
||||
{
|
||||
$set_var = SetVarTypeNull::setStr($input, $default);
|
||||
if ($expected !== null) {
|
||||
$this->assertIsString($set_var);
|
||||
} else {
|
||||
$this->assertNull($set_var);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$set_var
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function varMakeTypeStringProvider(): array
|
||||
{
|
||||
// 0: input
|
||||
// 1: default (null default)
|
||||
// 2: expected
|
||||
return [
|
||||
'empty string' => [
|
||||
'',
|
||||
null,
|
||||
''
|
||||
],
|
||||
'filled string' => [
|
||||
'string',
|
||||
null,
|
||||
'string'
|
||||
],
|
||||
'valid string, override set' => [
|
||||
'string',
|
||||
'override',
|
||||
'string'
|
||||
],
|
||||
'int, no override' => [
|
||||
1,
|
||||
null,
|
||||
'1'
|
||||
],
|
||||
'int, override set' => [
|
||||
1,
|
||||
'not int',
|
||||
'1'
|
||||
],
|
||||
'float, no override' => [
|
||||
1.5,
|
||||
null,
|
||||
'1.5'
|
||||
],
|
||||
// all the strange things here
|
||||
'function, override set' => [
|
||||
$foo = function () {
|
||||
return '';
|
||||
},
|
||||
'function',
|
||||
'function'
|
||||
],
|
||||
'function, no override' => [
|
||||
$foo = function () {
|
||||
return '';
|
||||
},
|
||||
null,
|
||||
null
|
||||
],
|
||||
'hex value, override set' => [
|
||||
0x55,
|
||||
'hex',
|
||||
'85'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* @covers ::makeStr
|
||||
* @dataProvider varMakeTypeStringProvider
|
||||
* @testdox makeStr $input with override $default will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param string|null $default
|
||||
* @param string|null $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testMakeString(mixed $input, ?string $default, ?string $expected): void
|
||||
{
|
||||
$set_var = SetVarTypeNull::makeStr($input, $default);
|
||||
if ($expected !== null) {
|
||||
$this->assertIsString($set_var);
|
||||
} else {
|
||||
$this->assertNull($set_var);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$set_var
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function varSetTypeIntProvider(): array
|
||||
{
|
||||
// 0: input
|
||||
// 1: default (null default)
|
||||
// 2: expected
|
||||
return [
|
||||
'int' => [
|
||||
1,
|
||||
null,
|
||||
1
|
||||
],
|
||||
'int, override set' => [
|
||||
1,
|
||||
-1,
|
||||
1
|
||||
],
|
||||
'string, no override' => [
|
||||
'string',
|
||||
null,
|
||||
null
|
||||
],
|
||||
'string, override' => [
|
||||
'string',
|
||||
-1,
|
||||
-1
|
||||
],
|
||||
'float' => [
|
||||
1.5,
|
||||
null,
|
||||
null
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* @covers ::setInt
|
||||
* @dataProvider varSetTypeIntProvider
|
||||
* @testdox setInt $input with override $default will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param int|null $default
|
||||
* @param int|null $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testSetInt(mixed $input, ?int $default, ?int $expected): void
|
||||
{
|
||||
$set_var = SetVarTypeNull::setInt($input, $default);
|
||||
if ($expected !== null) {
|
||||
$this->assertIsInt($set_var);
|
||||
} else {
|
||||
$this->assertNull($set_var);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$set_var
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function varMakeTypeIntProvider(): array
|
||||
{
|
||||
// 0: input
|
||||
// 1: default (null default)
|
||||
// 2: expected
|
||||
return [
|
||||
'int' => [
|
||||
1,
|
||||
null,
|
||||
1
|
||||
],
|
||||
'int, override set' => [
|
||||
1,
|
||||
-1,
|
||||
1
|
||||
],
|
||||
'string, no override' => [
|
||||
'string',
|
||||
null,
|
||||
0
|
||||
],
|
||||
'string, override' => [
|
||||
'string',
|
||||
-1,
|
||||
0
|
||||
],
|
||||
'float' => [
|
||||
1.5,
|
||||
null,
|
||||
1
|
||||
],
|
||||
// all the strange things here
|
||||
'function, override set' => [
|
||||
$foo = function () {
|
||||
return '';
|
||||
},
|
||||
-1,
|
||||
-1
|
||||
],
|
||||
'function, no override ' => [
|
||||
$foo = function () {
|
||||
return '';
|
||||
},
|
||||
null,
|
||||
null
|
||||
],
|
||||
'hex value, override set' => [
|
||||
0x55,
|
||||
-1,
|
||||
85
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* @covers ::makeInt
|
||||
* @dataProvider varMakeTypeIntProvider
|
||||
* @testdox makeInt $input with override $default will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param int|null $default
|
||||
* @param int|null $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testMakeInt(mixed $input, ?int $default, ?int $expected): void
|
||||
{
|
||||
$set_var = SetVarTypeNull::makeInt($input, $default);
|
||||
if ($expected !== null) {
|
||||
$this->assertIsInt($set_var);
|
||||
} else {
|
||||
$this->assertNull($set_var);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$set_var
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function varSetTypeFloatProvider(): array
|
||||
{
|
||||
// 0: input
|
||||
// 1: default (null default)
|
||||
// 2: expected
|
||||
return [
|
||||
'float' => [
|
||||
1.5,
|
||||
null,
|
||||
1.5
|
||||
],
|
||||
'float, override set' => [
|
||||
1.5,
|
||||
-1.5,
|
||||
1.5
|
||||
],
|
||||
'string, no override' => [
|
||||
'string',
|
||||
null,
|
||||
null
|
||||
],
|
||||
'string, override' => [
|
||||
'string',
|
||||
1.5,
|
||||
1.5
|
||||
],
|
||||
'int' => [
|
||||
1,
|
||||
null,
|
||||
null
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* @covers ::setFloat
|
||||
* @dataProvider varSetTypeFloatProvider
|
||||
* @testdox setFloat $input with override $default will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param float|null $default
|
||||
* @param float|null $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testSetFloat(mixed $input, ?float $default, ?float $expected): void
|
||||
{
|
||||
$set_var = SetVarTypeNull::setFloat($input, $default);
|
||||
if ($expected !== null) {
|
||||
$this->assertIsFloat($set_var);
|
||||
} else {
|
||||
$this->assertNull($set_var);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$set_var
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function varMakeTypeFloatProvider(): array
|
||||
{
|
||||
// 0: input
|
||||
// 1: default (null default)
|
||||
// 2: expected
|
||||
return [
|
||||
'float' => [
|
||||
1.5,
|
||||
null,
|
||||
1.5
|
||||
],
|
||||
'float, override set' => [
|
||||
1.5,
|
||||
-1.5,
|
||||
1.5
|
||||
],
|
||||
'string, no override' => [
|
||||
'string',
|
||||
null,
|
||||
0.0
|
||||
],
|
||||
'string, override' => [
|
||||
'string',
|
||||
1.5,
|
||||
0.0
|
||||
],
|
||||
'int' => [
|
||||
1,
|
||||
null,
|
||||
1.0
|
||||
],
|
||||
// all the strange things here
|
||||
'function, override set' => [
|
||||
$foo = function () {
|
||||
return '';
|
||||
},
|
||||
-1.0,
|
||||
-1.0
|
||||
],
|
||||
// all the strange things here
|
||||
'function, no override' => [
|
||||
$foo = function () {
|
||||
return '';
|
||||
},
|
||||
null,
|
||||
null
|
||||
],
|
||||
'hex value, override set' => [
|
||||
0x55,
|
||||
-1,
|
||||
85.0
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* @covers ::makeFloat
|
||||
* @dataProvider varMakeTypeFloatProvider
|
||||
* @testdox makeFloat $input with override $default will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param float|null $default
|
||||
* @param float|null $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testMakeFloat(mixed $input, ?float $default, ?float $expected): void
|
||||
{
|
||||
$set_var = SetVarTypeNull::makeFloat($input, $default);
|
||||
if ($expected !== null) {
|
||||
$this->assertIsFloat($set_var);
|
||||
} else {
|
||||
$this->assertNull($set_var);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$set_var
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function varSetTypeArrayProvider(): array
|
||||
{
|
||||
// 0: input
|
||||
// 1: default (null default)
|
||||
// 2: expected
|
||||
return [
|
||||
'array, empty' => [
|
||||
[],
|
||||
null,
|
||||
[]
|
||||
],
|
||||
'array, filled' => [
|
||||
['array'],
|
||||
null,
|
||||
['array']
|
||||
],
|
||||
'string, no override' => [
|
||||
'string',
|
||||
null,
|
||||
null
|
||||
],
|
||||
'string, override' => [
|
||||
'string',
|
||||
['string'],
|
||||
['string']
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* @covers ::setArray
|
||||
* @dataProvider varSetTypeArrayProvider
|
||||
* @testdox setArray $input with override $default will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param array|null $default
|
||||
* @param array|null $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testSetArray(mixed $input, ?array $default, ?array $expected): void
|
||||
{
|
||||
$set_var = SetVarTypeNull::setArray($input, $default);
|
||||
if ($expected !== null) {
|
||||
$this->assertIsArray($set_var);
|
||||
} else {
|
||||
$this->assertNull($set_var);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$set_var
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function varSetTypeBoolProvider(): array
|
||||
{
|
||||
// 0: input
|
||||
// 1: default (null default)
|
||||
// 2: expected
|
||||
return [
|
||||
'bool true' => [
|
||||
true,
|
||||
null,
|
||||
true
|
||||
],
|
||||
'bool false' => [
|
||||
false,
|
||||
null,
|
||||
false
|
||||
],
|
||||
'string, no override' => [
|
||||
'string',
|
||||
null,
|
||||
null
|
||||
],
|
||||
'string, override' => [
|
||||
'string',
|
||||
true,
|
||||
true
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* @covers ::setBool
|
||||
* @dataProvider varSetTypeBoolProvider
|
||||
* @testdox setBool $input with override $default will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param bool|null $default
|
||||
* @param bool|null $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testSetBool(mixed $input, ?bool $default, ?bool $expected): void
|
||||
{
|
||||
$set_var = SetVarTypeNull::setBool($input, $default);
|
||||
if ($expected !== null) {
|
||||
$this->assertIsBool($set_var);
|
||||
} else {
|
||||
$this->assertNull($set_var);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$set_var
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function varMakeTypeBoolProvider(): array
|
||||
{
|
||||
// 0: input
|
||||
// 2: expected
|
||||
return [
|
||||
'true' => [
|
||||
true,
|
||||
true
|
||||
],
|
||||
'false' => [
|
||||
false,
|
||||
false
|
||||
],
|
||||
'string on' => [
|
||||
'on',
|
||||
true
|
||||
],
|
||||
'string off' => [
|
||||
'off',
|
||||
false
|
||||
],
|
||||
'invalid string' => [
|
||||
'sulzenbacher',
|
||||
null,
|
||||
],
|
||||
'invalid string, override' => [
|
||||
'sulzenbacher',
|
||||
null,
|
||||
],
|
||||
'array to default' => [
|
||||
[],
|
||||
false
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* @covers ::setBool
|
||||
* @dataProvider varMakeTypeBoolProvider
|
||||
* @testdox setBool $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param bool|null $default
|
||||
* @param bool|null $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testMakeBool(mixed $input, ?bool $expected): void
|
||||
{
|
||||
$set_var = SetVarTypeNull::makeBool($input);
|
||||
if ($expected !== null) {
|
||||
$this->assertIsBool($set_var);
|
||||
} else {
|
||||
$this->assertNull($set_var);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$set_var
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
632
test/phpunit/Convert/CoreLibsConvertSetVarTypeTest.php
Normal file
632
test/phpunit/Convert/CoreLibsConvertSetVarTypeTest.php
Normal file
@@ -0,0 +1,632 @@
|
||||
<?php // phpcs:disable Generic.Files.LineLength
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use CoreLibs\Convert\SetVarType;
|
||||
|
||||
/**
|
||||
* Test class for Convert\Strings
|
||||
* @coversDefaultClass \CoreLibs\Convert\SetVarType
|
||||
* @testdox \CoreLibs\Convert\SetVarType method tests
|
||||
*/
|
||||
final class CoreLibsConvertSetVarTypeTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function varSetTypeStringProvider(): array
|
||||
{
|
||||
// 0: input
|
||||
// 1: default (null default)
|
||||
// 2: expected
|
||||
return [
|
||||
'empty string' => [
|
||||
'',
|
||||
null,
|
||||
''
|
||||
],
|
||||
'filled string' => [
|
||||
'string',
|
||||
null,
|
||||
'string'
|
||||
],
|
||||
'valid string, override set' => [
|
||||
'string',
|
||||
'override',
|
||||
'string'
|
||||
],
|
||||
'int, no override' => [
|
||||
1,
|
||||
null,
|
||||
''
|
||||
],
|
||||
'int, override set' => [
|
||||
1,
|
||||
'not int',
|
||||
'not int'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* @covers ::setStr
|
||||
* @dataProvider varSetTypeStringProvider
|
||||
* @testdox setStr $input with override $default will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param string|null $default
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testSetString(mixed $input, ?string $default, string $expected): void
|
||||
{
|
||||
if ($default === null) {
|
||||
$set_var = SetVarType::setStr($input);
|
||||
} else {
|
||||
$set_var = SetVarType::setStr($input, $default);
|
||||
}
|
||||
$this->assertIsString($set_var);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$set_var
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function varMakeTypeStringProvider(): array
|
||||
{
|
||||
// 0: input
|
||||
// 1: default (null default)
|
||||
// 2: expected
|
||||
return [
|
||||
'empty string' => [
|
||||
'',
|
||||
null,
|
||||
''
|
||||
],
|
||||
'filled string' => [
|
||||
'string',
|
||||
null,
|
||||
'string'
|
||||
],
|
||||
'valid string, override set' => [
|
||||
'string',
|
||||
'override',
|
||||
'string'
|
||||
],
|
||||
'int, no override' => [
|
||||
1,
|
||||
null,
|
||||
'1'
|
||||
],
|
||||
'int, override set' => [
|
||||
1,
|
||||
'not int',
|
||||
'1'
|
||||
],
|
||||
// all the strange things here
|
||||
'function, override set' => [
|
||||
$foo = function () {
|
||||
return '';
|
||||
},
|
||||
'function',
|
||||
'function'
|
||||
],
|
||||
'hex value, override set' => [
|
||||
0x55,
|
||||
'hex',
|
||||
'85'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* @covers ::makeStr
|
||||
* @dataProvider varMakeTypeStringProvider
|
||||
* @testdox makeStr $input with override $default will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param string|null $default
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testMakeString(mixed $input, ?string $default, string $expected): void
|
||||
{
|
||||
if ($default === null) {
|
||||
$set_var = SetVarType::makeStr($input);
|
||||
} else {
|
||||
$set_var = SetVarType::makeStr($input, $default);
|
||||
}
|
||||
$this->assertIsString($set_var);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$set_var
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function varSetTypeIntProvider(): array
|
||||
{
|
||||
// 0: input
|
||||
// 1: default (null default)
|
||||
// 2: expected
|
||||
return [
|
||||
'int' => [
|
||||
1,
|
||||
null,
|
||||
1
|
||||
],
|
||||
'int, override set' => [
|
||||
1,
|
||||
-1,
|
||||
1
|
||||
],
|
||||
'string, no override' => [
|
||||
'string',
|
||||
null,
|
||||
0
|
||||
],
|
||||
'string, override' => [
|
||||
'string',
|
||||
-1,
|
||||
-1
|
||||
],
|
||||
'float' => [
|
||||
1.5,
|
||||
null,
|
||||
0
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* @covers ::setInt
|
||||
* @dataProvider varSetTypeIntProvider
|
||||
* @testdox setInt $input with override $default will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param int|null $default
|
||||
* @param int $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testSetInt(mixed $input, ?int $default, int $expected): void
|
||||
{
|
||||
if ($default === null) {
|
||||
$set_var = SetVarType::setInt($input);
|
||||
} else {
|
||||
$set_var = SetVarType::setInt($input, $default);
|
||||
}
|
||||
$this->assertIsInt($set_var);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$set_var
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function varMakeTypeIntProvider(): array
|
||||
{
|
||||
// 0: input
|
||||
// 1: default (null default)
|
||||
// 2: expected
|
||||
return [
|
||||
'int' => [
|
||||
1,
|
||||
null,
|
||||
1
|
||||
],
|
||||
'int, override set' => [
|
||||
1,
|
||||
-1,
|
||||
1
|
||||
],
|
||||
'string, no override' => [
|
||||
'string',
|
||||
null,
|
||||
0
|
||||
],
|
||||
'string, override' => [
|
||||
'string',
|
||||
-1,
|
||||
0
|
||||
],
|
||||
'float' => [
|
||||
1.5,
|
||||
null,
|
||||
1
|
||||
],
|
||||
// all the strange things here
|
||||
'function, override set' => [
|
||||
$foo = function () {
|
||||
return '';
|
||||
},
|
||||
-1,
|
||||
-1
|
||||
],
|
||||
'hex value, override set' => [
|
||||
0x55,
|
||||
-1,
|
||||
85
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* @covers ::makeInt
|
||||
* @dataProvider varMakeTypeIntProvider
|
||||
* @testdox makeInt $input with override $default will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param int|null $default
|
||||
* @param int $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testMakeInt(mixed $input, ?int $default, int $expected): void
|
||||
{
|
||||
if ($default === null) {
|
||||
$set_var = SetVarType::makeInt($input);
|
||||
} else {
|
||||
$set_var = SetVarType::makeInt($input, $default);
|
||||
}
|
||||
$this->assertIsInt($set_var);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$set_var
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function varSetTypeFloatProvider(): array
|
||||
{
|
||||
// 0: input
|
||||
// 1: default (null default)
|
||||
// 2: expected
|
||||
return [
|
||||
'float' => [
|
||||
1.5,
|
||||
null,
|
||||
1.5
|
||||
],
|
||||
'float, override set' => [
|
||||
1.5,
|
||||
-1.5,
|
||||
1.5
|
||||
],
|
||||
'string, no override' => [
|
||||
'string',
|
||||
null,
|
||||
0.0
|
||||
],
|
||||
'string, override' => [
|
||||
'string',
|
||||
1.5,
|
||||
1.5
|
||||
],
|
||||
'int' => [
|
||||
1,
|
||||
null,
|
||||
0.0
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* @covers ::setFloat
|
||||
* @dataProvider varSetTypeFloatProvider
|
||||
* @testdox setFloat $input with override $default will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param float|null $default
|
||||
* @param float $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testSetFloat(mixed $input, ?float $default, float $expected): void
|
||||
{
|
||||
if ($default === null) {
|
||||
$set_var = SetVarType::setFloat($input);
|
||||
} else {
|
||||
$set_var = SetVarType::setFloat($input, $default);
|
||||
}
|
||||
$this->assertIsFloat($set_var);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$set_var
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function varMakeTypeFloatProvider(): array
|
||||
{
|
||||
// 0: input
|
||||
// 1: default (null default)
|
||||
// 2: expected
|
||||
return [
|
||||
'float' => [
|
||||
1.5,
|
||||
null,
|
||||
1.5
|
||||
],
|
||||
'float, override set' => [
|
||||
1.5,
|
||||
-1.5,
|
||||
1.5
|
||||
],
|
||||
'string, no override' => [
|
||||
'string',
|
||||
null,
|
||||
0.0
|
||||
],
|
||||
'string, override' => [
|
||||
'string',
|
||||
1.5,
|
||||
0.0
|
||||
],
|
||||
'int' => [
|
||||
1,
|
||||
null,
|
||||
1.0
|
||||
],
|
||||
// all the strange things here
|
||||
'function, override set' => [
|
||||
$foo = function () {
|
||||
return '';
|
||||
},
|
||||
-1.0,
|
||||
-1.0
|
||||
],
|
||||
'hex value, override set' => [
|
||||
0x55,
|
||||
-1,
|
||||
85.0
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* @covers ::makeFloat
|
||||
* @dataProvider varMakeTypeFloatProvider
|
||||
* @testdox makeFloat $input with override $default will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param float|null $default
|
||||
* @param float $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testMakeFloat(mixed $input, ?float $default, float $expected): void
|
||||
{
|
||||
if ($default === null) {
|
||||
$set_var = SetVarType::makeFloat($input);
|
||||
} else {
|
||||
$set_var = SetVarType::makeFloat($input, $default);
|
||||
}
|
||||
$this->assertIsFloat($set_var);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$set_var
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function varSetTypeArrayProvider(): array
|
||||
{
|
||||
// 0: input
|
||||
// 1: default (null default)
|
||||
// 2: expected
|
||||
return [
|
||||
'array, empty' => [
|
||||
[],
|
||||
null,
|
||||
[]
|
||||
],
|
||||
'array, filled' => [
|
||||
['array'],
|
||||
null,
|
||||
['array']
|
||||
],
|
||||
'string, no override' => [
|
||||
'string',
|
||||
null,
|
||||
[]
|
||||
],
|
||||
'string, override' => [
|
||||
'string',
|
||||
['string'],
|
||||
['string']
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* @covers ::setArray
|
||||
* @dataProvider varSetTypeArrayProvider
|
||||
* @testdox setArray $input with override $default will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param array|null $default
|
||||
* @param array $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testSetArray(mixed $input, ?array $default, array $expected): void
|
||||
{
|
||||
if ($default === null) {
|
||||
$set_var = SetVarType::setArray($input);
|
||||
} else {
|
||||
$set_var = SetVarType::setArray($input, $default);
|
||||
}
|
||||
$this->assertIsArray($set_var);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$set_var
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function varSetTypeBoolProvider(): array
|
||||
{
|
||||
// 0: input
|
||||
// 1: default (null default)
|
||||
// 2: expected
|
||||
return [
|
||||
'bool true' => [
|
||||
true,
|
||||
null,
|
||||
true
|
||||
],
|
||||
'bool false' => [
|
||||
false,
|
||||
null,
|
||||
false
|
||||
],
|
||||
'string, no override' => [
|
||||
'string',
|
||||
null,
|
||||
false
|
||||
],
|
||||
'string, override' => [
|
||||
'string',
|
||||
true,
|
||||
true
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* @covers ::setBool
|
||||
* @dataProvider varSetTypeBoolProvider
|
||||
* @testdox setBool $input with override $default will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param bool|null $default
|
||||
* @param bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testSetBool(mixed $input, ?bool $default, bool $expected): void
|
||||
{
|
||||
if ($default === null) {
|
||||
$set_var = SetVarType::setBool($input);
|
||||
} else {
|
||||
$set_var = SetVarType::setBool($input, $default);
|
||||
}
|
||||
$this->assertIsBool($set_var);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$set_var
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function varMakeTypeBoolProvider(): array
|
||||
{
|
||||
// 0: input
|
||||
// 2: expected
|
||||
return [
|
||||
'true' => [
|
||||
true,
|
||||
null,
|
||||
true
|
||||
],
|
||||
'false' => [
|
||||
false,
|
||||
null,
|
||||
false
|
||||
],
|
||||
'string on' => [
|
||||
'on',
|
||||
null,
|
||||
true
|
||||
],
|
||||
'string off' => [
|
||||
'off',
|
||||
null,
|
||||
false
|
||||
],
|
||||
'invalid string' => [
|
||||
'sulzenbacher',
|
||||
null,
|
||||
false,
|
||||
],
|
||||
'invalid string, override' => [
|
||||
'sulzenbacher',
|
||||
true,
|
||||
true,
|
||||
],
|
||||
'array to default' => [
|
||||
[],
|
||||
null,
|
||||
false
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* @covers ::setBool
|
||||
* @dataProvider varMakeTypeBoolProvider
|
||||
* @testdox setBool $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param mixed $input
|
||||
* @param bool|null $default
|
||||
* @param bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testMakeBool(mixed $input, ?bool $default, bool $expected): void
|
||||
{
|
||||
if ($default === null) {
|
||||
$set_var = SetVarType::makeBool($input);
|
||||
} else {
|
||||
$set_var = SetVarType::makeBool($input, $default);
|
||||
}
|
||||
$this->assertIsBool($set_var);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$set_var
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
261
test/phpunit/Convert/CoreLibsConvertStringsTest.php
Normal file
261
test/phpunit/Convert/CoreLibsConvertStringsTest.php
Normal file
@@ -0,0 +1,261 @@
|
||||
<?php // phpcs:disable Generic.Files.LineLength
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Convert\Strings
|
||||
* @coversDefaultClass \CoreLibs\Convert\Strings
|
||||
* @testdox \CoreLibs\Convert\Strings method tests
|
||||
*/
|
||||
final class CoreLibsConvertStringsTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function splitFormatStringProvider(): array
|
||||
{
|
||||
// 0: input
|
||||
// 1: format
|
||||
// 2: split characters as string, null for default
|
||||
// 3: expected
|
||||
return [
|
||||
'all empty string' => [
|
||||
'',
|
||||
'',
|
||||
null,
|
||||
''
|
||||
],
|
||||
'empty input string' => [
|
||||
'',
|
||||
'2-2',
|
||||
null,
|
||||
''
|
||||
],
|
||||
'empty format string string' => [
|
||||
'1234',
|
||||
'',
|
||||
null,
|
||||
'1234'
|
||||
],
|
||||
'string format match' => [
|
||||
'1234',
|
||||
'2-2',
|
||||
null,
|
||||
'12-34'
|
||||
],
|
||||
'string format trailing match' => [
|
||||
'1234',
|
||||
'2-2-',
|
||||
null,
|
||||
'12-34'
|
||||
],
|
||||
'string format leading match' => [
|
||||
'1234',
|
||||
'-2-2',
|
||||
null,
|
||||
'12-34'
|
||||
],
|
||||
'string format double inside match' => [
|
||||
'1234',
|
||||
'2--2',
|
||||
null,
|
||||
'12--34',
|
||||
],
|
||||
'string format short first' => [
|
||||
'1',
|
||||
'2-2',
|
||||
null,
|
||||
'1'
|
||||
],
|
||||
'string format match first' => [
|
||||
'12',
|
||||
'2-2',
|
||||
null,
|
||||
'12'
|
||||
],
|
||||
'string format short second' => [
|
||||
'123',
|
||||
'2-2',
|
||||
null,
|
||||
'12-3'
|
||||
],
|
||||
'string format too long' => [
|
||||
'1234567',
|
||||
'2-2',
|
||||
null,
|
||||
'12-34-567'
|
||||
],
|
||||
'string format invalid format string' => [
|
||||
'1234',
|
||||
'2_2',
|
||||
null,
|
||||
'1234'
|
||||
],
|
||||
'different split character' => [
|
||||
'1234',
|
||||
'2_2',
|
||||
'_',
|
||||
'12_34'
|
||||
],
|
||||
'mixed split characters' => [
|
||||
'123456',
|
||||
'2-2_2',
|
||||
'-_',
|
||||
'12-34_56'
|
||||
],
|
||||
'length mixed' => [
|
||||
'ABCD12345568ABC13',
|
||||
'2-4_5-2#4',
|
||||
'-_#',
|
||||
'AB-CD12_34556-8A#BC13'
|
||||
],
|
||||
'split with split chars in string' => [
|
||||
'12-34',
|
||||
'2-2',
|
||||
null,
|
||||
'12--3-4'
|
||||
],
|
||||
'mutltibyte string' => [
|
||||
'あいうえ',
|
||||
'2-2',
|
||||
null,
|
||||
'あいうえ'
|
||||
],
|
||||
'mutltibyte split string' => [
|
||||
'1234',
|
||||
'2-2',
|
||||
null,
|
||||
'1234'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* split format string
|
||||
*
|
||||
* @covers ::splitFormatString
|
||||
* @dataProvider splitFormatStringProvider
|
||||
* @testdox splitFormatString $input with format $format and splitters $split_characters will be $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $format
|
||||
* @param string|null $split_characters
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testSplitFormatString(
|
||||
string $input,
|
||||
string $format,
|
||||
?string $split_characters,
|
||||
string $expected
|
||||
): void {
|
||||
if ($split_characters === null) {
|
||||
$output = \CoreLibs\Convert\Strings::splitFormatString(
|
||||
$input,
|
||||
$format
|
||||
);
|
||||
} else {
|
||||
$output = \CoreLibs\Convert\Strings::splitFormatString(
|
||||
$input,
|
||||
$format,
|
||||
$split_characters
|
||||
);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function countSplitPartsProvider(): array
|
||||
{
|
||||
return [
|
||||
'0 elements' => [
|
||||
'',
|
||||
null,
|
||||
0
|
||||
],
|
||||
'1 element' => [
|
||||
'1',
|
||||
null,
|
||||
1,
|
||||
],
|
||||
'2 elements, trailing' => [
|
||||
'1-2-',
|
||||
null,
|
||||
2
|
||||
],
|
||||
'2 elements, leading' => [
|
||||
'-1-2',
|
||||
null,
|
||||
2
|
||||
],
|
||||
'2 elements, midde double' => [
|
||||
'1--2',
|
||||
null,
|
||||
2
|
||||
],
|
||||
'4 elements' => [
|
||||
'1-2-3-4',
|
||||
null,
|
||||
4
|
||||
],
|
||||
'3 elemenst, other splitter' => [
|
||||
'2-3_3',
|
||||
'-_',
|
||||
3
|
||||
],
|
||||
'illegal splitter' => [
|
||||
'あsdf',
|
||||
null,
|
||||
0
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* count split parts
|
||||
*
|
||||
* @covers ::countSplitParts
|
||||
* @dataProvider countSplitPartsProvider
|
||||
* @testdox countSplitParts $input with splitters $split_characters will be $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string|null $split_characters
|
||||
* @param int $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testCountSplitParts(
|
||||
string $input,
|
||||
?string $split_characters,
|
||||
int $expected
|
||||
): void {
|
||||
if ($split_characters === null) {
|
||||
$output = \CoreLibs\Convert\Strings::countSplitParts(
|
||||
$input
|
||||
);
|
||||
} else {
|
||||
$output = \CoreLibs\Convert\Strings::countSplitParts(
|
||||
$input,
|
||||
$split_characters
|
||||
);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$output
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
700
test/phpunit/Create/CoreLibsCreateEmailTest.php
Normal file
700
test/phpunit/Create/CoreLibsCreateEmailTest.php
Normal file
@@ -0,0 +1,700 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Create\Email
|
||||
* @coversDefaultClass \CoreLibs\Create\Email
|
||||
* @testdox \CoreLibs\Create\Email method tests
|
||||
*/
|
||||
final class CoreLibsCreateEmailTest extends TestCase
|
||||
{
|
||||
private static $log;
|
||||
|
||||
/**
|
||||
* start DB conneciton, setup DB, etc
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
self::$log = new \CoreLibs\Debug\Logging([
|
||||
'log_folder' => DIRECTORY_SEPARATOR . 'tmp',
|
||||
'file_id' => 'CoreLibs-Create-Email-Test',
|
||||
'debug_all' => true,
|
||||
'echo_all' => false,
|
||||
'print_all' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function encodeEmailNameProvider(): array
|
||||
{
|
||||
// 0: email
|
||||
// 1: name
|
||||
// 2: encoding
|
||||
// 3: kv_folding
|
||||
// 4: expected
|
||||
return [
|
||||
'all empty' => [
|
||||
'',
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
''
|
||||
],
|
||||
'email only' => [
|
||||
'test@test.com',
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
'test@test.com'
|
||||
],
|
||||
'email and name' => [
|
||||
'test@test.com',
|
||||
'Test Name',
|
||||
null,
|
||||
null,
|
||||
'"Test Name" <test@test.com>'
|
||||
],
|
||||
'name in mime encoded, default UTF-8' => [
|
||||
'test@test.com',
|
||||
'日本語',
|
||||
null,
|
||||
null,
|
||||
'"=?UTF-8?B?5pel5pys6Kqe?=" <test@test.com>'
|
||||
],
|
||||
'name in mime encoded with half width Katakana, default UTF-8' => [
|
||||
'test@test.com',
|
||||
'日本語カタカナパ',
|
||||
null,
|
||||
null,
|
||||
'"=?UTF-8?B?5pel5pys6Kqe7722776A7722776F776K776f?=" <test@test.com>'
|
||||
],
|
||||
'name in mime encoded with half width Katakana, folding on, default UTF-8' => [
|
||||
'test@test.com',
|
||||
'日本語カタカナパ',
|
||||
'UTF-8',
|
||||
true,
|
||||
'"=?UTF-8?B?5pel5pys6Kqe44Kr44K/44Kr44OK44OR?=" <test@test.com>'
|
||||
],
|
||||
'name in mime encoded, UTF-8 parameter' => [
|
||||
'test@test.com',
|
||||
'日本語',
|
||||
'UTF-8',
|
||||
null,
|
||||
'"=?UTF-8?B?5pel5pys6Kqe?=" <test@test.com>'
|
||||
],
|
||||
// does internal UTF-8 to ISO-2022-JP convert
|
||||
'encoding in ISO-2022-JP' => [
|
||||
'test@test.com',
|
||||
'日本語',
|
||||
'ISO-2022-JP',
|
||||
null,
|
||||
'"=?ISO-2022-JP?B?GyRCRnxLXDhsGyhC?=" <test@test.com>'
|
||||
],
|
||||
'encoding with half width Katakana in ISO-2022-JP' => [
|
||||
'test@test.com',
|
||||
'日本語カタカナパ',
|
||||
'ISO-2022-JP',
|
||||
null,
|
||||
'"=?ISO-2022-JP?B?GyRCRnxLXDhsGyhCPz8/Pz8/?=" <test@test.com>'
|
||||
],
|
||||
'encoding with half width Katakana, folding on in ISO-2022-JP' => [
|
||||
'test@test.com',
|
||||
'日本語カタカナパ',
|
||||
'ISO-2022-JP',
|
||||
true,
|
||||
// was ok php 8.1
|
||||
// '"=?ISO-2022-JP?B?GyRCRnxLXDhsGyhCPz8/Pz8=?=" <test@test.com>'
|
||||
// below ok php 8.1.12, 2022/12/9
|
||||
'"=?ISO-2022-JP?B?GyRCRnxLXDhsGyhCPz8/Pz8/?=" <test@test.com>'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @dataProvider encodeEmailNameProvider
|
||||
* @testdox encode email $email, name $name, encoding $encoding, folding $kv_folding will be $expected [$_dataName]
|
||||
*
|
||||
* @param string $email
|
||||
* @param string|null $name
|
||||
* @param string|null $encoding
|
||||
* @param bool|null $kv_folding
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testEncodeEmailName(
|
||||
string $email,
|
||||
?string $name,
|
||||
?string $encoding,
|
||||
?bool $kv_folding,
|
||||
string $expected
|
||||
): void {
|
||||
if ($name === null && $encoding === null && $kv_folding === null) {
|
||||
$encoded_email = \CoreLibs\Create\Email::encodeEmailName($email);
|
||||
} elseif ($encoding === null && $kv_folding === null) {
|
||||
$encoded_email = \CoreLibs\Create\Email::encodeEmailName($email, $name);
|
||||
} elseif ($kv_folding === null) {
|
||||
$encoded_email = \CoreLibs\Create\Email::encodeEmailName($email, $name, $encoding);
|
||||
} else {
|
||||
$encoded_email = \CoreLibs\Create\Email::encodeEmailName($email, $name, $encoding, $kv_folding);
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$encoded_email
|
||||
);
|
||||
}
|
||||
|
||||
public function sendEmailProvider(): array
|
||||
{
|
||||
// 0: subject
|
||||
// 1: body
|
||||
// 2: from email
|
||||
// 3: from name ('')
|
||||
// 4: array for to email
|
||||
// 5: replace content ([]/null)
|
||||
// 6: encoding (UTF-8/null)
|
||||
// 7: kv_folding
|
||||
// 8: return status
|
||||
// 9: expected content
|
||||
return [
|
||||
'all empty, fail -1' => [
|
||||
'subject' => '',
|
||||
'body' => '',
|
||||
'from_email' => '',
|
||||
'from_name' => '',
|
||||
'to_email' => [],
|
||||
'replace' => null,
|
||||
'encoding' => null,
|
||||
'kv_folding' => null,
|
||||
'expected_status' => -1,
|
||||
'expected_content' => [],
|
||||
],
|
||||
'missing to entry, fail -2' => [
|
||||
'subject' => 'SUBJECT',
|
||||
'body' => 'BODY',
|
||||
'from_email' => 'test@test.com',
|
||||
'from_name' => '',
|
||||
'to_email' => [],
|
||||
'replace' => null,
|
||||
'encoding' => null,
|
||||
'kv_folding' => null,
|
||||
'expected_status' => -2,
|
||||
'expected_content' => [],
|
||||
],
|
||||
'bad encoding, fail -3' => [
|
||||
'subject' => 'SUBJECT',
|
||||
'body' => 'BODY',
|
||||
'from_email' => 'test@test.com',
|
||||
'from_name' => '',
|
||||
'to_email' => ['to@test.com'],
|
||||
'replace' => null,
|
||||
'encoding' => 'IDONTEXISTENCODING',
|
||||
'kv_folding' => null,
|
||||
'expected_status' => -3,
|
||||
'expected_content' => [],
|
||||
],
|
||||
'sending email 1' => [
|
||||
'subject' => 'SUBJECT',
|
||||
'body' => 'BODY',
|
||||
'from_email' => 'test@test.com',
|
||||
'from_name' => '',
|
||||
'to_email' => [
|
||||
'test@test.com'
|
||||
],
|
||||
'replace' => null,
|
||||
'encoding' => null,
|
||||
'kv_folding' => null,
|
||||
'expected_status' => 2,
|
||||
'expected_content' => [
|
||||
[
|
||||
'header' => [
|
||||
'From' => 'test@test.com'
|
||||
],
|
||||
'to' => 'test@test.com',
|
||||
'subject' => 'SUBJECT',
|
||||
'body' => 'BODY',
|
||||
]
|
||||
],
|
||||
],
|
||||
'sending email 1, encoded' => [
|
||||
'subject' => 'SUBJECT 日本語',
|
||||
'body' => 'BODY 日本語',
|
||||
'from_email' => 'test@test.com',
|
||||
'from_name' => '',
|
||||
'to_email' => [
|
||||
'test@test.com'
|
||||
],
|
||||
'replace' => null,
|
||||
'encoding' => null,
|
||||
'kv_folding' => null,
|
||||
'expected_status' => 2,
|
||||
'expected_content' => [
|
||||
[
|
||||
'header' => [
|
||||
'From' => 'test@test.com'
|
||||
],
|
||||
'to' => 'test@test.com',
|
||||
'subject' => 'SUBJECT =?UTF-8?B?5pel5pys6Kqe?=',
|
||||
'body' => 'BODY 日本語',
|
||||
]
|
||||
],
|
||||
],
|
||||
'sending email 1, encoded, with half width katakanata' => [
|
||||
'subject' => 'SUBJECT 日本語カタカナパ',
|
||||
'body' => 'BODY 日本語',
|
||||
'from_email' => 'test@test.com',
|
||||
'from_name' => '',
|
||||
'to_email' => [
|
||||
'test@test.com'
|
||||
],
|
||||
'replace' => null,
|
||||
'encoding' => 'UTF-8',
|
||||
'kv_folding' => null,
|
||||
'expected_status' => 2,
|
||||
'expected_content' => [
|
||||
[
|
||||
'header' => [
|
||||
'From' => 'test@test.com'
|
||||
],
|
||||
'to' => 'test@test.com',
|
||||
'subject' => 'SUBJECT =?UTF-8?B?5pel5pys6Kqe7722776A7722776F776K776f?=',
|
||||
'body' => 'BODY 日本語',
|
||||
]
|
||||
],
|
||||
],
|
||||
'sending email 1, encoded, with half width katakanata, folding on' => [
|
||||
'subject' => 'SUBJECT 日本語カタカナパ',
|
||||
'body' => 'BODY 日本語',
|
||||
'from_email' => 'test@test.com',
|
||||
'from_name' => '',
|
||||
'to_email' => [
|
||||
'test@test.com'
|
||||
],
|
||||
'replace' => null,
|
||||
'encoding' => 'UTF-8',
|
||||
'kv_folding' => true,
|
||||
'expected_status' => 2,
|
||||
'expected_content' => [
|
||||
[
|
||||
'header' => [
|
||||
'From' => 'test@test.com'
|
||||
],
|
||||
'to' => 'test@test.com',
|
||||
'subject' => 'SUBJECT =?UTF-8?B?5pel5pys6Kqe44Kr44K/44Kr44OK44OR?=',
|
||||
'body' => 'BODY 日本語',
|
||||
]
|
||||
],
|
||||
],
|
||||
'sending email 1, encoded subject ISO-2022-JP' => [
|
||||
'subject' => 'SUBJECT 日本語',
|
||||
'body' => 'BODY 日本語',
|
||||
'from_email' => 'test@test.com',
|
||||
'from_name' => '',
|
||||
'to_email' => [
|
||||
'test@test.com'
|
||||
],
|
||||
'replace' => null,
|
||||
'encoding' => 'ISO-2022-JP',
|
||||
'kv_folding' => null,
|
||||
'expected_status' => 2,
|
||||
'expected_content' => [
|
||||
[
|
||||
'header' => [
|
||||
'From' => 'test@test.com'
|
||||
],
|
||||
'to' => 'test@test.com',
|
||||
'subject' => 'SUBJECT =?ISO-2022-JP?B?GyRCRnxLXDhsGyhC?=',
|
||||
// body is stored as UTF-8 in log and here, so both must be translated
|
||||
'body' => 'BODY 日本語',
|
||||
]
|
||||
],
|
||||
],
|
||||
'sending email 2' => [
|
||||
'subject' => 'SUBJECT',
|
||||
'body' => 'BODY',
|
||||
'from_email' => 'test@test.com',
|
||||
'from_name' => '',
|
||||
'to_email' => [
|
||||
'e1@test.com',
|
||||
'e2@test.com'
|
||||
],
|
||||
'replace' => null,
|
||||
'encoding' => null,
|
||||
'kv_folding' => null,
|
||||
'expected_status' => 2,
|
||||
'expected_content' => [
|
||||
[
|
||||
'header' => [
|
||||
'From' => 'test@test.com'
|
||||
],
|
||||
'to' => 'e1@test.com',
|
||||
'subject' => 'SUBJECT',
|
||||
'body' => 'BODY',
|
||||
],
|
||||
[
|
||||
'header' => [
|
||||
'From' => 'test@test.com'
|
||||
],
|
||||
'to' => 'e2@test.com',
|
||||
'subject' => 'SUBJECT',
|
||||
'body' => 'BODY',
|
||||
]
|
||||
],
|
||||
],
|
||||
'sending email 1: dynamic' => [
|
||||
'subject' => 'SUBJECT {FOO}',
|
||||
'body' => 'BODY {FOO} {VAR}',
|
||||
'from_email' => 'test@test.com',
|
||||
'from_name' => '',
|
||||
'to_email' => [
|
||||
'test@test.com'
|
||||
],
|
||||
'replace' => [
|
||||
'FOO' => 'foo',
|
||||
'VAR' => 'bar',
|
||||
],
|
||||
'encoding' => null,
|
||||
'kv_folding' => null,
|
||||
'expected_status' => 2,
|
||||
'expected_content' => [
|
||||
[
|
||||
'header' => [
|
||||
'From' => 'test@test.com'
|
||||
],
|
||||
'to' => 'test@test.com',
|
||||
'subject' => 'SUBJECT foo',
|
||||
'body' => 'BODY foo bar',
|
||||
]
|
||||
],
|
||||
],
|
||||
'sending email 1: dynamic encoded' => [
|
||||
'subject' => 'SUBJECT 日本語 {FOO}',
|
||||
'body' => 'BODY 日本語 {FOO} {VAR}',
|
||||
'from_email' => 'test@test.com',
|
||||
'from_name' => '',
|
||||
'to_email' => [
|
||||
'test@test.com'
|
||||
],
|
||||
'replace' => [
|
||||
'FOO' => 'foo',
|
||||
'VAR' => 'bar',
|
||||
],
|
||||
'encoding' => null,
|
||||
'kv_folding' => null,
|
||||
'expected_status' => 2,
|
||||
'expected_content' => [
|
||||
[
|
||||
'header' => [
|
||||
'From' => 'test@test.com'
|
||||
],
|
||||
'to' => 'test@test.com',
|
||||
'subject' => 'SUBJECT =?UTF-8?B?5pel5pys6KqeIGZvbw==?=',
|
||||
'body' => 'BODY 日本語 foo bar',
|
||||
]
|
||||
],
|
||||
],
|
||||
'sending email 1: dynamic, to override' => [
|
||||
'subject' => 'SUBJECT {FOO}',
|
||||
'body' => 'BODY {FOO} {VAR}',
|
||||
'from_email' => 'test@test.com',
|
||||
'from_name' => '',
|
||||
'to_email' => [
|
||||
[
|
||||
'email' => 'test@test.com',
|
||||
'replace' => [
|
||||
'FOO' => 'foo to'
|
||||
]
|
||||
]
|
||||
],
|
||||
'replace' => [
|
||||
'FOO' => 'foo',
|
||||
'VAR' => 'bar',
|
||||
],
|
||||
'encoding' => null,
|
||||
'kv_folding' => null,
|
||||
'expected_status' => 2,
|
||||
'expected_content' => [
|
||||
[
|
||||
'header' => [
|
||||
'From' => 'test@test.com'
|
||||
],
|
||||
'to' => 'test@test.com',
|
||||
'subject' => 'SUBJECT foo to',
|
||||
'body' => 'BODY foo to bar',
|
||||
]
|
||||
],
|
||||
],
|
||||
'sending email 1: dynamic, to override encoded' => [
|
||||
'subject' => 'SUBJECT 日本語 {FOO}',
|
||||
'body' => 'BODY 日本語 {FOO} {VAR}',
|
||||
'from_email' => 'test@test.com',
|
||||
'from_name' => '',
|
||||
'to_email' => [
|
||||
[
|
||||
'email' => 'test@test.com',
|
||||
'replace' => [
|
||||
'FOO' => 'foo to'
|
||||
]
|
||||
]
|
||||
],
|
||||
'replace' => [
|
||||
'FOO' => 'foo',
|
||||
'VAR' => 'bar',
|
||||
],
|
||||
'encoding' => null,
|
||||
'kv_folding' => null,
|
||||
'expected_status' => 2,
|
||||
'expected_content' => [
|
||||
[
|
||||
'header' => [
|
||||
'From' => 'test@test.com'
|
||||
],
|
||||
'to' => 'test@test.com',
|
||||
'subject' => 'SUBJECT =?UTF-8?B?5pel5pys6KqeIGZvbyB0bw==?=',
|
||||
'body' => 'BODY 日本語 foo to bar',
|
||||
]
|
||||
],
|
||||
],
|
||||
'sending email 3: dynamic, to mixed override' => [
|
||||
'subject' => 'SUBJECT {FOO}',
|
||||
'body' => 'BODY {FOO} {VAR}',
|
||||
'from_email' => 'test@test.com',
|
||||
'from_name' => '',
|
||||
'to_email' => [
|
||||
[
|
||||
'email' => 't1@test.com',
|
||||
'replace' => [
|
||||
'FOO' => 'foo to 1'
|
||||
]
|
||||
],
|
||||
[
|
||||
'email' => 't2@test.com',
|
||||
'replace' => [
|
||||
'FOO' => 'foo to 2'
|
||||
]
|
||||
],
|
||||
[
|
||||
'email' => 't3@test.com',
|
||||
],
|
||||
],
|
||||
'replace' => [
|
||||
'FOO' => 'foo',
|
||||
'VAR' => 'bar',
|
||||
],
|
||||
'encoding' => null,
|
||||
'kv_folding' => null,
|
||||
'expected_status' => 2,
|
||||
'expected_content' => [
|
||||
[
|
||||
'header' => [
|
||||
'From' => 'test@test.com'
|
||||
],
|
||||
'to' => 't1@test.com',
|
||||
'subject' => 'SUBJECT foo to 1',
|
||||
'body' => 'BODY foo to 1 bar',
|
||||
],
|
||||
[
|
||||
'header' => [
|
||||
'From' => 'test@test.com'
|
||||
],
|
||||
'to' => 't2@test.com',
|
||||
'subject' => 'SUBJECT foo to 2',
|
||||
'body' => 'BODY foo to 2 bar',
|
||||
],
|
||||
[
|
||||
'header' => [
|
||||
'From' => 'test@test.com'
|
||||
],
|
||||
'to' => 't3@test.com',
|
||||
'subject' => 'SUBJECT foo',
|
||||
'body' => 'BODY foo bar',
|
||||
],
|
||||
],
|
||||
],
|
||||
'sending email 3: dynamic, to mixed override encoded' => [
|
||||
'subject' => 'SUBJECT 日本語 {FOO}',
|
||||
'body' => 'BODY 日本語 {FOO} {VAR}',
|
||||
'from_email' => 'test@test.com',
|
||||
'from_name' => '',
|
||||
'to_email' => [
|
||||
[
|
||||
'email' => 't1@test.com',
|
||||
'replace' => [
|
||||
'FOO' => 'foo to 1'
|
||||
]
|
||||
],
|
||||
[
|
||||
'email' => 't2@test.com',
|
||||
'replace' => [
|
||||
'FOO' => 'foo to 2'
|
||||
]
|
||||
],
|
||||
[
|
||||
'email' => 't3@test.com',
|
||||
],
|
||||
],
|
||||
'replace' => [
|
||||
'FOO' => 'foo',
|
||||
'VAR' => 'bar',
|
||||
],
|
||||
'encoding' => null,
|
||||
'kv_folding' => null,
|
||||
'expected_status' => 2,
|
||||
'expected_content' => [
|
||||
[
|
||||
'header' => [
|
||||
'From' => 'test@test.com'
|
||||
],
|
||||
'to' => 't1@test.com',
|
||||
'subject' => 'SUBJECT =?UTF-8?B?5pel5pys6KqeIGZvbyB0byAx?=',
|
||||
'body' => 'BODY 日本語 foo to 1 bar',
|
||||
],
|
||||
[
|
||||
'header' => [
|
||||
'From' => 'test@test.com'
|
||||
],
|
||||
'to' => 't2@test.com',
|
||||
'subject' => 'SUBJECT =?UTF-8?B?5pel5pys6KqeIGZvbyB0byAy?=',
|
||||
'body' => 'BODY 日本語 foo to 2 bar',
|
||||
],
|
||||
[
|
||||
'header' => [
|
||||
'From' => 'test@test.com'
|
||||
],
|
||||
'to' => 't3@test.com',
|
||||
'subject' => 'SUBJECT =?UTF-8?B?5pel5pys6KqeIGZvbw==?=',
|
||||
'body' => 'BODY 日本語 foo bar',
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @dataProvider sendEmailProvider
|
||||
* @testdox email sending with expected status $expected_status [$_dataName]
|
||||
*
|
||||
* @param string $subject
|
||||
* @param string $body
|
||||
* @param string $from_email
|
||||
* @param string $from_name
|
||||
* @param array $to_email
|
||||
* @param array|null $replace
|
||||
* @param string|null $encoding
|
||||
* @param bool|null $kv_folding
|
||||
* @param int $expected_status
|
||||
* @param array $expected_content
|
||||
* @return void
|
||||
*/
|
||||
public function testSendEmail(
|
||||
string $subject,
|
||||
string $body,
|
||||
string $from_email,
|
||||
string $from_name,
|
||||
array $to_email,
|
||||
?array $replace,
|
||||
?string $encoding,
|
||||
?bool $kv_folding,
|
||||
int $expected_status,
|
||||
array $expected_content
|
||||
): void {
|
||||
if ($replace === null) {
|
||||
$replace = [];
|
||||
}
|
||||
if ($encoding === null) {
|
||||
$encoding = 'UTF-8';
|
||||
}
|
||||
if ($kv_folding === null) {
|
||||
$kv_folding = false;
|
||||
}
|
||||
// force new set for each run
|
||||
self::$log->setLogUniqueId(true);
|
||||
// set on of unique log id
|
||||
self::$log->setLogPer('run', true);
|
||||
// init logger
|
||||
$status = \CoreLibs\Create\Email::sendEmail(
|
||||
$subject,
|
||||
$body,
|
||||
$from_email,
|
||||
$from_name,
|
||||
$to_email,
|
||||
$replace,
|
||||
$encoding,
|
||||
$kv_folding,
|
||||
true,
|
||||
self::$log
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected_status,
|
||||
$status,
|
||||
'Assert sending status'
|
||||
);
|
||||
// assert content: must load JSON from log file
|
||||
if ($status == 2) {
|
||||
// open file, get last entry with 'SEND EMAIL JSON' key
|
||||
$file = file_get_contents(self::$log->getLogFileName());
|
||||
if ($file !== false) {
|
||||
// extract SEND EMAIL JSON line
|
||||
$found = preg_match_all("/^.* <SEND EMAIL JSON> - (.*)$/m", $file, $matches);
|
||||
// print "Found: $found | EMAIL: " . print_r($matches, true) . "\n";
|
||||
if (!empty($matches[1])) {
|
||||
foreach ($matches[1] as $pos => $email_json) {
|
||||
$email = \CoreLibs\Convert\Json::jsonConvertToArray($email_json);
|
||||
// print "EMAIL: " . print_r($email, true) . "\n";
|
||||
$this->assertEquals(
|
||||
$expected_content[$pos]['header']['From'] ?? 'MISSING FROM',
|
||||
$email['header']['From'] ?? '',
|
||||
'Email check: assert header from'
|
||||
);
|
||||
$this->assertEquals(
|
||||
'text/plain; charset=' . $encoding ?? 'UTF-8',
|
||||
$email['header']['Content-type'] ?? '',
|
||||
'Email check: assert header content type'
|
||||
);
|
||||
$this->assertEquals(
|
||||
'1.0',
|
||||
$email['header']['MIME-Version'] ?? '',
|
||||
'Email check: assert header mime version'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected_content[$pos]['to'] ?? 'MISSING TO',
|
||||
$email['to'] ?? '',
|
||||
'Email check: assert to'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected_content[$pos]['subject'] ?? 'MISSING SUBJECT',
|
||||
$email['subject'] ?? '',
|
||||
'Email check: assert subject'
|
||||
);
|
||||
// body must be translated back to encoding if encoding is not UTF-8
|
||||
$this->assertEquals(
|
||||
$encoding != 'UTF-8' ?
|
||||
mb_convert_encoding($expected_content[$pos]['body'] ?? '', $encoding, 'UTF-8') :
|
||||
$expected_content[$pos]['body'] ?? 'MISSING BODY',
|
||||
$email['encoding'] != 'UTF-8' ?
|
||||
mb_convert_encoding($email['body'] ?? '', $email['encoding'], 'UTF-8') :
|
||||
$email['body'] ?? '',
|
||||
'Email check: assert body'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
212
test/phpunit/Create/CoreLibsCreateHashTest.php
Normal file
212
test/phpunit/Create/CoreLibsCreateHashTest.php
Normal file
@@ -0,0 +1,212 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Create\Hash
|
||||
* @coversDefaultClass \CoreLibs\Create\Hash
|
||||
* @testdox \CoreLibs\Create\Hash method tests
|
||||
*/
|
||||
final class CoreLibsCreateHashTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function hashData(): array
|
||||
{
|
||||
return [
|
||||
'any string' => [
|
||||
'text' => 'Some String Text',
|
||||
'crc32b_reverse' => 'c5c21d91', // crc32b (in revere)
|
||||
'sha1Short' => '4d2bc9ba0', // sha1Short
|
||||
// via hash
|
||||
'crc32b' => '911dc2c5', // hash: crc32b
|
||||
'adler32' => '31aa05f1', // hash: alder32
|
||||
'fnv132' => '9df444f9', // hash: fnv132
|
||||
'fnv1a32' => '2c5f91b9', // hash: fnv1a32
|
||||
'joaat' => '50dab846', // hash: joaat
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function crc32bProvider(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->hashData() as $name => $values) {
|
||||
$list[$name . ' to crc32b reverse'] = [
|
||||
0 => $values['text'],
|
||||
1 => $values['crc32b_reverse'],
|
||||
];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function sha1ShortProvider(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->hashData() as $name => $values) {
|
||||
$list[$name . ' to sha1 short'] = [
|
||||
0 => $values['text'],
|
||||
1 => $values['crc32b_reverse'],
|
||||
2 => $values['sha1Short'],
|
||||
];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* test all hash functions
|
||||
* NOTE: if we add new hash functions in the __hash method
|
||||
* they need to be added here too (and in the master hashData array too)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function hashProvider(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->hashData() as $name => $values) {
|
||||
foreach ([null, 'crc32b', 'adler32', 'fnv132', 'fnv1a32', 'joaat'] as $_hash_type) {
|
||||
// default value test
|
||||
if ($_hash_type === null) {
|
||||
$hash_type = \CoreLibs\Create\Hash::STANDARD_HASH_SHORT;
|
||||
} else {
|
||||
$hash_type = $_hash_type;
|
||||
}
|
||||
$list[$name . ' to ' . $hash_type] = [
|
||||
0 => $values['text'],
|
||||
1 => $_hash_type,
|
||||
2 => $values[$hash_type]
|
||||
];
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function hashLongProvider(): array
|
||||
{
|
||||
$hash_source = 'Some String Text';
|
||||
return [
|
||||
'Long Hash check: ' . \CoreLibs\Create\Hash::STANDARD_HASH_LONG => [
|
||||
$hash_source,
|
||||
hash(\CoreLibs\Create\Hash::STANDARD_HASH_LONG, $hash_source)
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::__crc32b
|
||||
* @dataProvider crc32bProvider
|
||||
* @testdox __crc32b $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testCrc32b(string $input, string $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Create\Hash::__crc32b($input)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::__sha1Short
|
||||
* @dataProvider sha1ShortProvider
|
||||
* @testdox __sha1Short $input will be $expected (crc32b) and $expected_sha1 (sha1 short) [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testSha1Short(string $input, string $expected, string $expected_sha1): void
|
||||
{
|
||||
// uses crc32b
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Create\Hash::__sha1Short($input)
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Create\Hash::__sha1Short($input, false)
|
||||
);
|
||||
// sha1 type
|
||||
$this->assertEquals(
|
||||
$expected_sha1,
|
||||
\CoreLibs\Create\Hash::__sha1Short($input, true)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::__hash
|
||||
* @dataProvider hashProvider
|
||||
* @testdox __hash $input with $hash_type will be $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string|null $hash_type
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testHash(string $input, ?string $hash_type, string $expected): void
|
||||
{
|
||||
if ($hash_type === null) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Create\Hash::__hash($input)
|
||||
);
|
||||
} else {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Create\Hash::__hash($input, $hash_type)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::__hashLong
|
||||
* @dataProvider hashLongProvider
|
||||
* @testdox __hashLong $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testHashLong(string $input, string $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Create\Hash::__hashLong($input)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
205
test/phpunit/Create/CoreLibsCreateRandomKeyTest.php
Normal file
205
test/phpunit/Create/CoreLibsCreateRandomKeyTest.php
Normal file
@@ -0,0 +1,205 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Create\RandomKey
|
||||
* @coversDefaultClass \CoreLibs\Create\RandomKey
|
||||
* @testdox \CoreLibs\Create\RandomKey method tests
|
||||
*/
|
||||
final class CoreLibsCreateRandomKeyTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function keyLenghtProvider(): array
|
||||
{
|
||||
return [
|
||||
'valid key length' => [
|
||||
0 => 6,
|
||||
1 => true,
|
||||
2 => 6,
|
||||
],
|
||||
'negative key length' => [
|
||||
0 => -1,
|
||||
1 => false,
|
||||
2 => 4,
|
||||
],
|
||||
'tpp big key length' => [
|
||||
0 => 300,
|
||||
1 => false,
|
||||
2 => 4,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function randomKeyGenProvider(): array
|
||||
{
|
||||
return [
|
||||
'default key length' => [
|
||||
0 => null,
|
||||
1 => 4
|
||||
],
|
||||
'set -1 key length default' => [
|
||||
0 => -1,
|
||||
1 => 4,
|
||||
],
|
||||
'set too large key length' => [
|
||||
0 => 300,
|
||||
1 => 4,
|
||||
],
|
||||
'set override key lenght' => [
|
||||
0 => 6,
|
||||
1 => 6,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 1
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function keepKeyLengthProvider(): array
|
||||
{
|
||||
return [
|
||||
'set too large' => [
|
||||
0 => 6,
|
||||
1 => 300,
|
||||
2 => 6,
|
||||
],
|
||||
'set too small' => [
|
||||
0 => 8,
|
||||
1 => -2,
|
||||
2 => 8,
|
||||
],
|
||||
'change valid' => [
|
||||
0 => 10,
|
||||
1 => 6,
|
||||
2 => 6,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* run before each test and reset to default 4
|
||||
*
|
||||
* @before
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function resetKeyLength(): void
|
||||
{
|
||||
\CoreLibs\Create\RandomKey::setRandomKeyLength(4);
|
||||
}
|
||||
|
||||
/**
|
||||
* check that first length is 4
|
||||
*
|
||||
* @covers ::getRandomKeyLength
|
||||
* @testWith [4]
|
||||
* @testdox getRandomKeyLength on init will be $expected [$_dataName]
|
||||
*
|
||||
* @param integer $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testGetRandomKeyLengthInit(int $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Create\RandomKey::getRandomKeyLength()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::setRandomKeyLength
|
||||
* @covers ::getRandomKeyLength
|
||||
* @dataProvider keyLenghtProvider
|
||||
* @testdox setRandomKeyLength $input will be $expected, compare to $compare [$_dataName]
|
||||
*
|
||||
* @param integer $input
|
||||
* @param boolean $expected
|
||||
* @param integer $compare
|
||||
* @return void
|
||||
*/
|
||||
public function testSetRandomKeyLength(int $input, bool $expected, int $compare): void
|
||||
{
|
||||
// set
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Create\RandomKey::setRandomKeyLength($input)
|
||||
);
|
||||
// read test, if false, use compare check
|
||||
if ($expected === false) {
|
||||
$input = $compare;
|
||||
}
|
||||
$this->assertEquals(
|
||||
$input,
|
||||
\CoreLibs\Create\RandomKey::getRandomKeyLength()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::randomKeyGeyn
|
||||
* @dataProvider randomKeyGenProvider
|
||||
* @testdox randomKeyGen use $input key length $expected [$_dataName]
|
||||
*
|
||||
* @param integer|null $input
|
||||
* @param integer $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testRandomKeyGen(?int $input, int $expected): void
|
||||
{
|
||||
if ($input === null) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
strlen(\CoreLibs\Create\RandomKey::randomKeyGen())
|
||||
);
|
||||
} else {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
strlen(\CoreLibs\Create\RandomKey::randomKeyGen($input))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that if set to n and then invalid, it keeps the previous one
|
||||
* or if second change valid, second will be shown
|
||||
*
|
||||
* @covers ::setRandomKeyLength
|
||||
* @dataProvider keepKeyLengthProvider
|
||||
* @testdox keep setRandomKeyLength set with $input_valid and then $input_invalid will be $expected [$_dataName]
|
||||
*
|
||||
* @param integer $input_valid
|
||||
* @param integer $input_invalid
|
||||
* @param integer $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testKeepKeyLength(int $input_valid, int $input_invalid, int $expected): void
|
||||
{
|
||||
\CoreLibs\Create\RandomKey::setRandomKeyLength($input_valid);
|
||||
\CoreLibs\Create\RandomKey::setRandomKeyLength($input_invalid);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Create\RandomKey::getRandomKeyLength()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
472
test/phpunit/Create/CoreLibsCreateSessionTest.php
Normal file
472
test/phpunit/Create/CoreLibsCreateSessionTest.php
Normal file
@@ -0,0 +1,472 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
/**
|
||||
* Test class for Create\Session
|
||||
* @coversDefaultClass \CoreLibs\Create\Session
|
||||
* @testdox \CoreLibs\Create\Session method tests
|
||||
*/
|
||||
final class CoreLibsCreateSessionTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function sessionProvider(): array
|
||||
{
|
||||
// 0: session name as parameter or for GLOBAL value
|
||||
// 1: type p: parameter, g: global, d: php.ini default
|
||||
// 2: mock data as array
|
||||
// checkCliStatus: true/false,
|
||||
// getSessionStatus: PHP_SESSION_DISABLED for abort,
|
||||
// PHP_SESSION_NONE/ACTIVE for ok
|
||||
// setSessionName: true/false,
|
||||
// checkActiveSession: true/false, [1st call, 2nd call]
|
||||
// getSessionId: string or false
|
||||
// 3: exepcted name (session)
|
||||
// 4: expected error string
|
||||
return [
|
||||
'session parameter' => [
|
||||
'sessionNameParameter',
|
||||
'p',
|
||||
[
|
||||
'checkCliStatus' => false,
|
||||
'getSessionStatus' => PHP_SESSION_NONE,
|
||||
'setSessionName' => true,
|
||||
'checkActiveSession' => [false, true],
|
||||
'getSessionId' => '1234abcd4567'
|
||||
],
|
||||
'sessionNameParameter',
|
||||
''
|
||||
],
|
||||
'session globals' => [
|
||||
'sessionNameGlobals',
|
||||
'g',
|
||||
[
|
||||
'checkCliStatus' => false,
|
||||
'getSessionStatus' => PHP_SESSION_NONE,
|
||||
'setSessionName' => true,
|
||||
'checkActiveSession' => [false, true],
|
||||
'getSessionId' => '1234abcd4567'
|
||||
],
|
||||
'sessionNameGlobals',
|
||||
''
|
||||
],
|
||||
'session name default' => [
|
||||
'',
|
||||
'd',
|
||||
[
|
||||
'checkCliStatus' => false,
|
||||
'getSessionStatus' => PHP_SESSION_NONE,
|
||||
'setSessionName' => true,
|
||||
'checkActiveSession' => [false, true],
|
||||
'getSessionId' => '1234abcd4567'
|
||||
],
|
||||
'',
|
||||
''
|
||||
],
|
||||
// error checks
|
||||
// 1: we are in cli
|
||||
'on cli error' => [
|
||||
'',
|
||||
'd',
|
||||
[
|
||||
'checkCliStatus' => true,
|
||||
'getSessionStatus' => PHP_SESSION_NONE,
|
||||
'setSessionName' => true,
|
||||
'checkActiveSession' => [false, true],
|
||||
'getSessionId' => '1234abcd4567'
|
||||
],
|
||||
'',
|
||||
'[SESSION] No sessions in php cli'
|
||||
],
|
||||
// 2: session disabled
|
||||
'session disabled error' => [
|
||||
'',
|
||||
'd',
|
||||
[
|
||||
'checkCliStatus' => false,
|
||||
'getSessionStatus' => PHP_SESSION_DISABLED,
|
||||
'setSessionName' => true,
|
||||
'checkActiveSession' => [false, true],
|
||||
'getSessionId' => '1234abcd4567'
|
||||
],
|
||||
'',
|
||||
'[SESSION] Sessions are disabled'
|
||||
],
|
||||
// 3: invalid session name: string
|
||||
'invalid name chars error' => [
|
||||
'1invalid$session#;',
|
||||
'p',
|
||||
[
|
||||
'checkCliStatus' => false,
|
||||
'getSessionStatus' => PHP_SESSION_NONE,
|
||||
'setSessionName' => false,
|
||||
'checkActiveSession' => [false, true],
|
||||
'getSessionId' => '1234abcd4567'
|
||||
],
|
||||
'',
|
||||
'[SESSION] Invalid session name: 1invalid$session#;'
|
||||
],
|
||||
// 3: invalid session name: only numbers
|
||||
'invalid name numbers only error' => [
|
||||
'123',
|
||||
'p',
|
||||
[
|
||||
'checkCliStatus' => false,
|
||||
'getSessionStatus' => PHP_SESSION_NONE,
|
||||
'setSessionName' => false,
|
||||
'checkActiveSession' => [false, true],
|
||||
'getSessionId' => '1234abcd4567'
|
||||
],
|
||||
'',
|
||||
'[SESSION] Invalid session name: 123'
|
||||
],
|
||||
// 3: invalid session name: invalid name short
|
||||
// 3: invalid session name: too long (128)
|
||||
// 4: failed to start session (2nd false on check active session)
|
||||
'invalid name numbers only error' => [
|
||||
'',
|
||||
'd',
|
||||
[
|
||||
'checkCliStatus' => false,
|
||||
'getSessionStatus' => PHP_SESSION_NONE,
|
||||
'setSessionName' => true,
|
||||
'checkActiveSession' => [false, false],
|
||||
'getSessionId' => '1234abcd4567'
|
||||
],
|
||||
'',
|
||||
'[SESSION] Failed to activate session'
|
||||
],
|
||||
// 5: get session id return false
|
||||
'invalid name numbers only error' => [
|
||||
'',
|
||||
'd',
|
||||
[
|
||||
'checkCliStatus' => false,
|
||||
'getSessionStatus' => PHP_SESSION_NONE,
|
||||
'setSessionName' => true,
|
||||
'checkActiveSession' => [false, true],
|
||||
'getSessionId' => false
|
||||
],
|
||||
'',
|
||||
'[SESSION] getSessionId did not return a session id'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test session start
|
||||
*
|
||||
* @covers ::startSession
|
||||
* @dataProvider sessionProvider
|
||||
* @testdox startSession $input name for $type will be $expected (error: $expected_error) [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $type
|
||||
* @param array<mixed> $mock_data
|
||||
* @param string $expected
|
||||
* @param string $expected_error
|
||||
* @return void
|
||||
*/
|
||||
public function testStartSession(
|
||||
string $input,
|
||||
string $type,
|
||||
array $mock_data,
|
||||
string $expected,
|
||||
string $expected_error
|
||||
): void {
|
||||
// override expected
|
||||
if ($type == 'd') {
|
||||
$expected = ini_get('session.name');
|
||||
}
|
||||
/** @var \CoreLibs\Create\Session&MockObject $session_mock */
|
||||
$session_mock = $this->createPartialMock(
|
||||
\CoreLibs\Create\Session::class,
|
||||
[
|
||||
'checkCliStatus', 'getSessionStatus', 'checkActiveSession',
|
||||
'setSessionName', 'startSessionCall', 'getSessionId',
|
||||
'getSessionName'
|
||||
]
|
||||
);
|
||||
// set return values based requested input values
|
||||
// OK: true
|
||||
// error: false
|
||||
$session_mock->method('checkCliStatus')->willReturn($mock_data['checkCliStatus']);
|
||||
// OK: PHP_SESSION_ACTIVE, PHP_SESSION_NONE
|
||||
// error: PHP_SESSION_DISABLED
|
||||
$session_mock->method('getSessionStatus')->willReturn($mock_data['getSessionStatus']);
|
||||
// false: try start
|
||||
// true: skip start
|
||||
// note that on second call if false -> error
|
||||
$session_mock->method('checkActiveSession')
|
||||
->willReturnOnConsecutiveCalls(
|
||||
$mock_data['checkActiveSession'][0],
|
||||
$mock_data['checkActiveSession'][1],
|
||||
);
|
||||
// dummy set for session name
|
||||
$session_mock->method('setSessionName')->with($input)->willReturn($mock_data['setSessionName']);
|
||||
// set session name & return bsed on request data
|
||||
$session_mock->method('getSessionName')->willReturn($expected);
|
||||
// will not return anything
|
||||
$session_mock->method('startSessionCall');
|
||||
// in test case only return string
|
||||
// false: will return false
|
||||
$session_mock->method('getSessionId')->willReturn($mock_data['getSessionId']);
|
||||
|
||||
// regex for session id
|
||||
$ression_id_regex = "/^\w+$/";
|
||||
|
||||
unset($GLOBALS['SET_SESSION_NAME']);
|
||||
$session_id = '';
|
||||
switch ($type) {
|
||||
case 'p':
|
||||
$session_id = $session_mock->startSession($input);
|
||||
break;
|
||||
case 'g':
|
||||
$GLOBALS['SET_SESSION_NAME'] = $input;
|
||||
$session_id = $session_mock->startSession();
|
||||
break;
|
||||
case 'd':
|
||||
$session_id = $session_mock->startSession();
|
||||
break;
|
||||
}
|
||||
// asert checks
|
||||
if (!empty($session_id)) {
|
||||
$this->assertMatchesRegularExpression(
|
||||
$ression_id_regex,
|
||||
(string)$session_id,
|
||||
'session id regex from retrun'
|
||||
);
|
||||
$this->assertMatchesRegularExpression(
|
||||
$ression_id_regex,
|
||||
(string)$session_mock->getSessionId()
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$session_mock->getSessionName()
|
||||
);
|
||||
} else {
|
||||
// false checks
|
||||
$this->assertEquals(
|
||||
$expected_error,
|
||||
$session_mock->getErrorStr(),
|
||||
'error assert'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* provider for session name check
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function sessionNameProvider(): array
|
||||
{
|
||||
// 0: string for session
|
||||
// 1: expected return as bool
|
||||
return [
|
||||
'valid name' => [
|
||||
'abc',
|
||||
true
|
||||
],
|
||||
'valid name longer' => [
|
||||
'something-abc-123',
|
||||
true
|
||||
],
|
||||
'invalid name' => [
|
||||
'abc#abc',
|
||||
false
|
||||
],
|
||||
'only numbers' => [
|
||||
'123',
|
||||
false
|
||||
],
|
||||
'longer than 128 chars' => [
|
||||
'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz'
|
||||
. 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz'
|
||||
. 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz',
|
||||
false
|
||||
],
|
||||
'too short' => [
|
||||
'',
|
||||
false
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* test valid session name
|
||||
*
|
||||
* @covers ::checkValidSessionName
|
||||
* @dataProvider sessionNameProvider
|
||||
* @testdox checkValidSessionName $input seessionn name is $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testCheckValidSessionName(string $input, bool $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Create\Session::checkValidSessionName($input)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* provider for set/get tests
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function sessionDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'test' => [
|
||||
'foo',
|
||||
'bar',
|
||||
'bar',
|
||||
],
|
||||
'int key test' => [
|
||||
123,
|
||||
'bar',
|
||||
'bar',
|
||||
],
|
||||
// more complex value tests
|
||||
'array values' => [
|
||||
'array',
|
||||
[1, 2, 3],
|
||||
[1, 2, 3],
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* method call test
|
||||
*
|
||||
* @covers ::setS
|
||||
* @covers ::getS
|
||||
* @covers ::issetS
|
||||
* @covers ::unsetS
|
||||
* @dataProvider sessionDataProvider
|
||||
* @testdox setS/getS/issetS/unsetS $name with $input is $expected [$_dataName]
|
||||
*
|
||||
* @param string|int $name
|
||||
* @param mixed $input
|
||||
* @param mixed $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testMethodSetGet($name, $input, $expected): void
|
||||
{
|
||||
$session = new \CoreLibs\Create\Session();
|
||||
$session->setS($name, $input);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$session->getS($name),
|
||||
'method set assert'
|
||||
);
|
||||
// isset true
|
||||
$this->assertTrue(
|
||||
$session->issetS($name),
|
||||
'method isset assert ok'
|
||||
);
|
||||
$session->unsetS($name);
|
||||
$this->assertEquals(
|
||||
'',
|
||||
$session->getS($name),
|
||||
'method unset assert'
|
||||
);
|
||||
// iset false
|
||||
$this->assertFalse(
|
||||
$session->issetS($name),
|
||||
'method isset assert false'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* magic call test
|
||||
*
|
||||
* @covers ::__set
|
||||
* @covers ::__get
|
||||
* @covers ::__isset
|
||||
* @covers ::__unset
|
||||
* @dataProvider sessionDataProvider
|
||||
* @testdox __set/__get/__iseet/__unset $name with $input is $expected [$_dataName]
|
||||
*
|
||||
* @param string|int $name
|
||||
* @param mixed $input
|
||||
* @param mixed $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testMagicSetGet($name, $input, $expected): void
|
||||
{
|
||||
$session = new \CoreLibs\Create\Session();
|
||||
$session->$name = $input;
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$session->$name,
|
||||
'magic set assert'
|
||||
);
|
||||
// isset true
|
||||
$this->assertTrue(
|
||||
isset($session->$name),
|
||||
'magic isset assert ok'
|
||||
);
|
||||
unset($session->$name);
|
||||
$this->assertEquals(
|
||||
'',
|
||||
$session->$name,
|
||||
'magic unset assert'
|
||||
);
|
||||
// isset true
|
||||
$this->assertFalse(
|
||||
isset($session->$name),
|
||||
'magic isset assert false'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* unset all test
|
||||
*
|
||||
* @covers ::unsetAllS
|
||||
* @testdox unsetAllS test
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testUnsetAll(): void
|
||||
{
|
||||
$test_values = [
|
||||
'foo' => 'abc',
|
||||
'bar' => '123'
|
||||
];
|
||||
$session = new \CoreLibs\Create\Session();
|
||||
foreach ($test_values as $name => $value) {
|
||||
$session->setS($name, $value);
|
||||
// confirm set
|
||||
$this->assertEquals(
|
||||
$value,
|
||||
$session->getS($name),
|
||||
'set assert: ' . $name
|
||||
);
|
||||
}
|
||||
// unset all
|
||||
$session->unsetAllS();
|
||||
// check unset
|
||||
foreach (array_keys($test_values) as $name) {
|
||||
$this->assertEquals(
|
||||
'',
|
||||
$session->getS($name),
|
||||
'unsert assert: ' . $name
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
186
test/phpunit/Create/CoreLibsCreateUidsTest.php
Normal file
186
test/phpunit/Create/CoreLibsCreateUidsTest.php
Normal file
@@ -0,0 +1,186 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Create\Uids
|
||||
* @coversDefaultClass \CoreLibs\Create\Uids
|
||||
* @testdox \CoreLibs\Create\Uids method tests
|
||||
*/
|
||||
final class CoreLibsCreateUidsTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function uniqIdProvider(): array
|
||||
{
|
||||
return [
|
||||
'md5 hash' => [
|
||||
0 => 'md5',
|
||||
1 => 32,
|
||||
],
|
||||
'sha256 hash' => [
|
||||
0 => 'sha256',
|
||||
1 => 64
|
||||
],
|
||||
'ripemd160 hash' => [
|
||||
0 => 'ripemd160',
|
||||
1 => 40
|
||||
],
|
||||
'adler32 hash' => [
|
||||
0 => 'adler32',
|
||||
1 => 8
|
||||
],
|
||||
'not in list hash but valid' => [
|
||||
0 => 'sha3-512',
|
||||
1 => strlen(hash('sha3-512', 'A'))
|
||||
],
|
||||
'default hash not set' => [
|
||||
0 => null,
|
||||
1 => 64,
|
||||
],
|
||||
'invalid name' => [
|
||||
0 => 'iamnotavalidhash',
|
||||
1 => 64,
|
||||
],
|
||||
'auto: ' . \CoreLibs\Create\Uids::DEFAULT_HASH => [
|
||||
0 => \CoreLibs\Create\Uids::DEFAULT_HASH,
|
||||
1 => strlen(hash(\CoreLibs\Create\Uids::DEFAULT_HASH, 'A'))
|
||||
],
|
||||
'auto: ' . \CoreLibs\Create\Uids::STANDARD_HASH_LONG => [
|
||||
0 => \CoreLibs\Create\Uids::STANDARD_HASH_LONG,
|
||||
1 => strlen(hash(\CoreLibs\Create\Uids::STANDARD_HASH_LONG, 'A'))
|
||||
],
|
||||
'auto: ' . \CoreLibs\Create\Uids::STANDARD_HASH_SHORT => [
|
||||
0 => \CoreLibs\Create\Uids::STANDARD_HASH_SHORT,
|
||||
1 => strlen(hash(\CoreLibs\Create\Uids::STANDARD_HASH_SHORT, 'A'))
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function uniqIdLongProvider(): array
|
||||
{
|
||||
return [
|
||||
'uniq id long: ' . \CoreLibs\Create\Uids::STANDARD_HASH_LONG => [
|
||||
strlen(hash(\CoreLibs\Create\Uids::STANDARD_HASH_LONG, 'A'))
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* must match 7e78fe0d-59b8-4637-af7f-e88d221a7d1e
|
||||
*
|
||||
* @covers ::uuidv4
|
||||
* @testdox uuidv4 check that return is matching regex [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testUuidv4(): void
|
||||
{
|
||||
$uuid = \CoreLibs\Create\Uids::uuidv4();
|
||||
$this->assertMatchesRegularExpression(
|
||||
'/^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$/',
|
||||
$uuid
|
||||
);
|
||||
// $this->assertStringMatchesFormat(
|
||||
// '%4s%4s-%4s-%4s-%4s-%4s%4s%4s',
|
||||
// $uuid
|
||||
// );
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::uniqId
|
||||
* @dataProvider uniqIdProvider
|
||||
* @testdox uniqId $input will be length $expected [$_dataName]
|
||||
*
|
||||
* @param string|null $input
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testUniqId(?string $input, int $expected): void
|
||||
{
|
||||
if ($input === null) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
strlen(\CoreLibs\Create\Uids::uniqId())
|
||||
);
|
||||
} else {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
strlen(\CoreLibs\Create\Uids::uniqId($input))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Because we set a constant here, we can only run one test
|
||||
* so we test invalid one to force check
|
||||
*
|
||||
* @covers ::uniqId
|
||||
* @#dataProvider uniqIdProvider
|
||||
* @testWith ["invalidhash", 64]
|
||||
* @testdox uniqId use DEFAULT_HASH set $input with length $expected [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testUnidIdDefaultHash(string $input, int $expected): void
|
||||
{
|
||||
define('DEFAULT_HASH', $input);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
strlen(\CoreLibs\Create\Uids::uniqId())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Short id, always 8 in length
|
||||
*
|
||||
* @covers ::uniqIdShort
|
||||
* @testWith [8]
|
||||
* @testdox uniqIdShort will be length $expected [$_dataName]
|
||||
*
|
||||
* @param integer $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testUniqIdShort(int $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
strlen(\CoreLibs\Create\Uids::uniqIdShort())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Long Id, length can change
|
||||
*
|
||||
* @covers ::uniqIdLong
|
||||
* @dataProvider uniqIdLongProvider
|
||||
* @testdox uniqIdLong will be length $expected [$_dataName]
|
||||
*
|
||||
* @param integer $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testUniqIdLong(int $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
strlen(\CoreLibs\Create\Uids::uniqIdLong())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
48
test/phpunit/DB/CoreLibsDBExtendedArrayIOTest.php
Normal file
48
test/phpunit/DB/CoreLibsDBExtendedArrayIOTest.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for DB\Extended\ArrayIO
|
||||
* This will only test the PgSQL parts
|
||||
* @coversDefaultClass \CoreLibs\DB\Extended\ArrayIO
|
||||
* @coversDefaultClass \CoreLibs\DB\Extended\ArrayIO
|
||||
* @testdox \CoreLibs\Extended\ArrayIO method tests for extended DB interface
|
||||
*/
|
||||
final class CoreLibsDBExtendedArrayIOTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
if (!extension_loaded('pgsql')) {
|
||||
$this->markTestSkipped(
|
||||
'The PgSQL extension is not available.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @testdox DB\Extended\ArrayIO Class tests
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testArrayDBIO()
|
||||
{
|
||||
// $this->assertTrue(true, 'DB Extended ArrayIO Tests not implemented');
|
||||
$this->markTestIncomplete(
|
||||
'DB\Extended\ArrayIO Tests have not yet been implemented'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
4474
test/phpunit/DB/CoreLibsDBIOTest.php
Normal file
4474
test/phpunit/DB/CoreLibsDBIOTest.php
Normal file
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user