Compare commits

...

7 Commits

Author SHA1 Message Date
Clemens Schwaighofer
fc57aabf5d Updates in SmartyExtend set var calls
Removed cms object from Frontend and replaced with optional smarty data
array (HEADER, DATA, DEBUG_DATA)
Updated admin call that if $cms is given above data will be extracted.
Added a CONTENT_PATH option for admin, must be set if $cms is set
Is used for the adbTopMenu call
Moved the $cms global check and trigger to the admin call branch only
2023-03-13 11:29:21 +09:00
Clemens Schwaighofer
d56ee68482 Fix missing default null in setSmartyVarsFrontend 2023-03-13 10:36:05 +09:00
Clemens Schwaighofer
b89ab09e12 SmartyExtend parameter phpdoc order fix 2023-03-13 09:25:50 +09:00
Clemens Schwaighofer
e873ade6c0 Change the SmartyExtended Vars set calls to use options array
Instead of having each parameter single, group them into an options array
so we do not have to worry about updating the whole function call.

Keep the main core call as is
2023-03-13 09:15:59 +09:00
Clemens Schwaighofer
5910b884ac Bug fix in SmartyExtend class and user name set 2023-03-10 15:25:54 +09:00
Clemens Schwaighofer
e3bd2c1c3b Remove more _SESSION calls in classes, test updates
Admin\EditBase now has ACL\Login class as mandatory class parameter
Output\Form\Generate has loginAcl array parameter as mandatory
2023-03-10 15:08:56 +09:00
Clemens Schwaighofer
90a8c5540f Deprecate the GetLocale class and replace with ACL\Login locales set
If ACL\Login is used, the loginGetLocale() call should be used to fetch
the locale data set during login

Language\L10n now has new encoding/charset optional parameter 4
If the locale does not have a charset set the defautl charset is UTF-8
unless set via the new parameter or setOverrideEncoding()

Because of the deprecation of the getLocales call the following methods
do no longer need $locales
- Admin\Backend
- Admin\EditBase
- Output\Form\Generate
- Template\SmartyExtend

They all use the new l10n->getLocaleAsArray() call to set all the local
variables

* Admin\EditBase has new parameter "options" to set
- cache_id
- compile_id
which must be passed on the SmartyExtend class init
2023-03-10 13:43:43 +09:00
90 changed files with 3149 additions and 292 deletions

View File

@@ -96,8 +96,6 @@ return [
"exclude_analysis_directory_list" => [
'www/vendor',
'www/tests',
'www/lib/Smarty',
'www/lib/smarty-4.3.0',
'www/templates_c',
'www/log',
'www/tmp',
@@ -118,10 +116,6 @@ return [
// ignore the old qq tests
'www/admin/qq_file_upload_front.php',
'www/admin/qq_file_upload_ajax.php',
// symlink ignore
'www/lib/smarty-4.3.0/libs/Smarty.class.php',
// legacy edit base (until removal)
'www/includes/edit_base.LEGACY.php'
],
// what not to show as problem

View File

@@ -7,6 +7,14 @@ namespace tests;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\MockObject\MockObject;
/*
Not yet covered tests:
- loginGetLocale
- loginGetHeaderColor
- loginGetPages
- loginGetEuid
*/
/**
* Test class for ACL\Login
* @coversDefaultClass \CoreLibs\ACL\Login
@@ -1114,6 +1122,7 @@ final class CoreLibsACLLoginTest extends TestCase
'logout_target' => '',
'site_locale' => 'en_US.UTF-8',
'site_domain' => 'admin',
'site_encoding' => 'UTF-8',
'locale_path' => __DIR__ . DIRECTORY_SEPARATOR
. 'includes' . DIRECTORY_SEPARATOR
. 'locale' . DIRECTORY_SEPARATOR,
@@ -1796,6 +1805,7 @@ final class CoreLibsACLLoginTest extends TestCase
'logout_target' => '',
'site_locale' => 'en_US.UTF-8',
'site_domain' => 'admin',
'site_encoding' => 'UTF-8',
'locale_path' => __DIR__ . DIRECTORY_SEPARATOR
. 'includes' . DIRECTORY_SEPARATOR
. 'locale' . DIRECTORY_SEPARATOR,
@@ -1909,6 +1919,7 @@ final class CoreLibsACLLoginTest extends TestCase
'logout_target' => '',
'site_locale' => 'en_US.UTF-8',
'site_domain' => 'admin',
'site_encoding' => 'UTF-8',
'locale_path' => __DIR__ . DIRECTORY_SEPARATOR
. 'includes' . DIRECTORY_SEPARATOR
. 'locale' . DIRECTORY_SEPARATOR,
@@ -1996,6 +2007,7 @@ final class CoreLibsACLLoginTest extends TestCase
'logout_target' => '',
'site_locale' => 'en_US.UTF-8',
'site_domain' => 'admin',
'site_encoding' => 'UTF-8',
'locale_path' => __DIR__ . DIRECTORY_SEPARATOR
. 'includes' . DIRECTORY_SEPARATOR
. 'locale' . DIRECTORY_SEPARATOR,
@@ -2091,6 +2103,7 @@ final class CoreLibsACLLoginTest extends TestCase
'logout_target' => '',
'site_locale' => 'en_US.UTF-8',
'site_domain' => 'admin',
'site_encoding' => 'UTF-8',
'locale_path' => __DIR__ . DIRECTORY_SEPARATOR
. 'includes' . DIRECTORY_SEPARATOR
. 'locale' . DIRECTORY_SEPARATOR,

View File

@@ -14,6 +14,13 @@ use PHPUnit\Framework\TestCase;
*/
final class CoreLibsLanguageGetLocaleTest extends TestCase
{
public const SITE_ENCODING = 'UTF-8';
public const SITE_LOCALE = 'en_US.UTF-8';
public const SITE_DOMAIN = 'admin';
public const LOCALE_PATH = __DIR__ . DIRECTORY_SEPARATOR
. 'includes' . DIRECTORY_SEPARATOR
. 'locale' . DIRECTORY_SEPARATOR;
/**
* set all constant variables that must be set before call
*
@@ -22,7 +29,7 @@ final class CoreLibsLanguageGetLocaleTest extends TestCase
public static function setUpBeforeClass(): void
{
// default web page encoding setting
if (!defined('DEFAULT_ENCODING')) {
/* if (!defined('DEFAULT_ENCODING')) {
define('DEFAULT_ENCODING', 'UTF-8');
}
if (!defined('DEFAULT_LOCALE')) {
@@ -35,9 +42,9 @@ final class CoreLibsLanguageGetLocaleTest extends TestCase
}
if (!defined('SITE_LOCALE')) {
define('SITE_LOCALE', DEFAULT_LOCALE);
}
} */
// just set
if (!defined('BASE')) {
/* if (!defined('BASE')) {
define('BASE', str_replace('/configs', '', __DIR__) . DIRECTORY_SEPARATOR);
}
if (!defined('INCLUDES')) {
@@ -51,7 +58,7 @@ final class CoreLibsLanguageGetLocaleTest extends TestCase
}
if (!defined('CONTENT_PATH')) {
define('CONTENT_PATH', 'frontend' . DIRECTORY_SEPARATOR);
}
} */
// array session
$_SESSION = [];
global $_SESSION;
@@ -62,7 +69,7 @@ final class CoreLibsLanguageGetLocaleTest extends TestCase
*
* @return array<mixed>
*/
public function setLocaleProvider(): array
/* public function setLocaleProvider(): array
{
return [
// 0: locale
@@ -233,7 +240,7 @@ final class CoreLibsLanguageGetLocaleTest extends TestCase
// TODO invalid params (bad path) (no override)
// TODO param calls, but with override set
];
}
} */
/**
* Undocumented function
@@ -252,7 +259,7 @@ final class CoreLibsLanguageGetLocaleTest extends TestCase
* @param string|null $deprecation_message
* @return void
*/
public function testsetLocale(
/* public function testsetLocale(
?string $language,
?string $domain,
?string $encoding,
@@ -347,6 +354,214 @@ final class CoreLibsLanguageGetLocaleTest extends TestCase
// unset all vars
$_SESSION = [];
unset($GLOBALS['OVERRIDE_LANG']);
} */
/**
* all the test data
*
* @return array<mixed>
*/
public function setLocaleFromSessionProvider(): array
{
return [
// 0: locale
// 1: domain
// 2: encoding
// 3: path
// 4: SESSION: DEFAULT_LOCALE
// 5: SESSION: DEFAULT_CHARSET
// 5: SESSION: DEFAULT_DOMAIN
// 6: SESSION: LOCALE_PATH
// 6: expected array
// 7: deprecation message
'all session vars set' => [
// lang, domain, encoding, path
self::SITE_LOCALE, self::SITE_DOMAIN, self::SITE_ENCODING, self::LOCALE_PATH,
// SESSION SETTINGS: locale, charset, domain, path
'ja_JP.UTF-8', 'UTF-8', 'admin', __DIR__ . '/locale_other/',
// return array
[
'locale' => 'ja_JP.UTF-8',
'lang' => 'ja_JP',
'domain' => 'admin',
'encoding' => 'UTF-8',
'path' => "/^\/(.*\/)?locale_other\/$/",
],
],
// param lang and domain (no override)
'no session set, only parameters' => [
// lang, domain, encoding, path
self::SITE_LOCALE, self::SITE_DOMAIN, self::SITE_ENCODING, self::LOCALE_PATH,
// SESSION SETTINGS: locale, charset, domain, path
null, null, null, null,
// return array
[
'locale' => 'en_US.UTF-8',
'lang' => 'en_US',
'domain' => 'admin',
'encoding' => 'UTF-8',
'path' => "/^\/(.*\/)?includes\/locale\/$/",
],
],
// special parse session check for locales
'all session vars set, short lang' => [
// lang, domain, encoding, path
self::SITE_LOCALE, self::SITE_DOMAIN, self::SITE_ENCODING, self::LOCALE_PATH,
// SESSION SETTINGS: locale, charset, domain, path
'ja', 'UTF-8', 'admin', __DIR__ . '/locale_other/',
// return array
[
'locale' => 'ja',
'lang' => 'ja',
'domain' => 'admin',
'encoding' => 'UTF-8',
'path' => "/^\/(.*\/)?locale_other\/$/",
],
],
// lang with modifier
// param lang and domain (no override)
'long locale, domain, encoding params, no sessions' => [
// lang, domain, encoding, path
self::SITE_LOCALE, self::SITE_DOMAIN, self::SITE_ENCODING, self::LOCALE_PATH,
// SESSION SETTINGS: locale, charset, domain, path
'de_CH.UTF-8@euro', 'admin', 'UTF-8', __DIR__ . '/includes/locale/',
// return array
[
'locale' => 'de_CH.UTF-8@euro',
'lang' => 'de_CH',
'domain' => 'admin',
'encoding' => 'UTF-8',
'path' => "/^\/(.*\/)?includes\/locale\/$/",
],
],
// missing session values check
// special parse session check for locales
'session missing encoding, set from parameters' => [
// lang, domain, encoding, path
self::SITE_LOCALE, self::SITE_DOMAIN, self::SITE_ENCODING, self::LOCALE_PATH,
// SESSION SETTINGS: locale, charset, domain, path
'ja', null, 'admin', __DIR__ . '/locale_other/',
// return array
[
'locale' => 'ja',
'lang' => 'ja',
'domain' => 'admin',
'encoding' => 'UTF-8',
'path' => "/^\/(.*\/)?locale_other\/$/",
],
],
// null return check for invalid entries
'no session set, only parameters, all invalid' => [
// lang, domain, encoding, path
'###', '&&&&', '$$$$', 'foo_bar_path',
// SESSION SETTINGS: locale, charset, domain, path
null, null, null, null,
// return array
[
'locale' => null,
'lang' => null,
'domain' => null,
'encoding' => null,
'path' => null,
],
],
// invalid session names, fall backup
'all session vars are invalid, fallback' => [
// lang, domain, encoding, path
self::SITE_LOCALE, self::SITE_DOMAIN, self::SITE_ENCODING, self::LOCALE_PATH,
// SESSION SETTINGS: locale, charset, domain, path
'###', '&&&&', '$$$$', 'foo_bar_path',
// return array
[
'locale' => 'en_US.UTF-8',
'lang' => 'en_US',
'domain' => 'admin',
'encoding' => 'UTF-8',
'path' => "/^\/(.*\/)?includes\/locale\/$/",
],
],
];
}
/**
* Undocumented function
*
* @covers ::setLocale
* @dataProvider setLocaleFromSessionProvider
* @testdox lang settings lang $language, domain $domain, encoding $encoding, path $path; session lang: $SESSION_DEFAULT_LOCALE, session char: $SESSION_DEFAULT_CHARSET [$_dataName]
*
* @param string| $language
* @param string| $domain
* @param string| $encoding
* @param string| $path
* @param string|null $SESSION_DEFAULT_LOCALE
* @param string|null $SESSION_DEFAULT_CHARSET
* @param string|null $SESSION_DEFAULT_DOMAIN
* @param string|null $SESSION_LOCALE_PATH
* @param array<mixed> $expected
* @return void
*/
public function testsetLocaleFromSession(
string $language,
string $domain,
string $encoding,
string $path,
?string $SESSION_DEFAULT_LOCALE,
?string $SESSION_DEFAULT_CHARSET,
?string $SESSION_DEFAULT_DOMAIN,
?string $SESSION_LOCALE_PATH,
array $expected,
): void {
$return_lang_settings = [];
global $_SESSION;
// set override
if ($SESSION_DEFAULT_LOCALE !== null) {
$_SESSION['DEFAULT_LOCALE'] = $SESSION_DEFAULT_LOCALE;
}
if ($SESSION_DEFAULT_CHARSET !== null) {
$_SESSION['DEFAULT_CHARSET'] = $SESSION_DEFAULT_CHARSET;
}
if ($SESSION_DEFAULT_DOMAIN !== null) {
$_SESSION['DEFAULT_DOMAIN'] = $SESSION_DEFAULT_DOMAIN;
}
if ($SESSION_LOCALE_PATH !== null) {
$_SESSION['LOCALE_PATH'] = $SESSION_LOCALE_PATH;
}
$return_lang_settings = \CoreLibs\Language\GetLocale::setLocaleFromSession(
$language,
$domain,
$encoding,
$path
);
// print "RETURN: " . print_r($return_lang_settings, true) . "\n";
foreach (
[
'locale', 'lang', 'domain', 'encoding', 'path'
] as $key
) {
$value = $expected[$key];
if (
!empty($value) &&
strpos($value, "/") === 0
) {
// this is regex
$this->assertMatchesRegularExpression(
$value,
$return_lang_settings[$key] ?? '',
'assert regex failed for ' . $key
);
} else {
// assert equal
$this->assertEquals(
$value,
$return_lang_settings[$key],
'assert equal failed for ' . $key
);
}
}
// unset all vars
$_SESSION = [];
unset($GLOBALS['OVERRIDE_LANG']);
}
}

View File

@@ -84,94 +84,141 @@ final class CoreLibsLanguageL10nTest extends TestCase
{
return [
// 0: locale
// 1: domain
// 2: encoding
// 1: encoding
// 2: domain
// 3: path
// 4: locale expected
// 5: locale set expected
// 6: lang expected
// 7: encoding expected
// 8: domain exepcted
// 9: context (null for none)
// 10: test string in
// 11: test translated
// 12: deprecation message (until removed)
// 7: lang short expected
// 8: encoding expected
// 9: domain exepcted
// 10: context (null for none)
// 11: test string in
// 12: test translated
// 13: deprecation message (until removed)
// new style load
'gettext load en' => [
'en_US.UTF-8',
'UTF-8',
'frontend',
__DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR,
//
// 4, 5, 6, 7, 8, 9
'en_US.UTF-8',
'en_US',
'en_US',
'en',
'UTF-8',
'frontend',
// 10
null,
// 11, 12
'Original',
'Translated frontend en_US',
// 13
null,
],
'gettext load en' => [
'en_US.UTF-8',
'UTF-8',
'frontend',
__DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR,
//
'en_US.UTF-8',
'en_US',
'en_US',
'en',
'UTF-8',
'frontend',
//
'context',
//
'Original',
'Original context frontend en_US',
//
null,
],
'gettext load ja' => [
'ja_JP.UTF-8',
'UTF-8',
'admin',
__DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR,
//
'ja_JP.UTF-8',
'ja_JP',
'ja_JP',
'ja',
'UTF-8',
'admin',
//
null,
//
'Original',
'Translated admin ja_JP',
//
null,
],
// load short locale with different encoding
'gettext load short ja no encoding' => [
'ja',
'SJIS',
'admin',
__DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR,
//
'ja',
'ja',
'ja',
'ja',
'SJIS',
'admin',
//
null,
//
'Original',
'Translated admin ja_JP',
//
null,
],
// mixed path and domain [DEPRECATED]
'mixed path and domain [DEPRECATED]' => [
'en_US.UTF-8',
'UTF-8',
__DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR,
'frontend',
//
'en_US.UTF-8',
'en_US',
'en_US',
'en',
'UTF-8',
'frontend',
//
'context',
//
'Original',
'Original context frontend en_US',
//
'L10n constructor parameter switch is no longer supported. domain is 2nd, path is 3rd parameter'
],
// unset path
'unset path with locale and domain [DEPRECATED]' => [
'ja_JP.UTF-8',
'UTF-8',
'admin',
null,
//
'ja_JP.UTF-8',
'ja_JP',
'ja_JP',
'ja',
'UTF-8',
'admin',
//
null,
//
'Original',
'Translated admin ja_JP',
//
'Empty path parameter is no longer allowed if locale and domain are set',
],
// null set
@@ -179,15 +226,20 @@ final class CoreLibsLanguageL10nTest extends TestCase
'',
'',
'',
'',
//
'',
'',
'',
'',
'', // unset on empty call
'',
//
null,
//
'Original',
'Original',
//
null,
]
];
@@ -201,11 +253,13 @@ final class CoreLibsLanguageL10nTest extends TestCase
* @testdox check l10n init with Locale $locale, Path $path, Domain $domain, Legacy: $legacy with $context [$_dataName]
*
* @param string|null $locale
* @param string|null $encoding
* @param string|null $domain
* @param string|null $path
* @param string $locale_expected
* @param string $locale_set_expected
* @param string $lang_expected
* @param string $lang_short_expected
* @param string $encoding_expected
* @param string $domain_expected
* @param string|null $context
@@ -216,11 +270,13 @@ final class CoreLibsLanguageL10nTest extends TestCase
*/
public function testL10nObject(
?string $locale,
?string $encoding,
?string $domain,
?string $path,
string $locale_expected,
string $locale_set_expected,
string $lang_expected,
string $lang_short_expected,
string $encoding_expected,
string $domain_expected,
?string $context,
@@ -241,16 +297,18 @@ final class CoreLibsLanguageL10nTest extends TestCase
if ($locale === null) {
$l10n = new \CoreLibs\Language\L10n();
} elseif ($domain === null) {
// same as if locale is null
// deprecated, locale + domain must be set, handled like empty calls
$l10n = new \CoreLibs\Language\L10n($locale);
} elseif ($path === null) {
// deprecated, path must be set
// deprecated, path must be set, will thow DEPRECATION error, handled like empty
$l10n = new \CoreLibs\Language\L10n($locale, $domain);
} else {
} elseif ($encoding === null) {
// if encoding not found will be UTF-8
$l10n = new \CoreLibs\Language\L10n($locale, $domain, $path);
} else {
$l10n = new \CoreLibs\Language\L10n($locale, $domain, $path, $encoding);
}
restore_error_handler();
// print "LOC: " . $locale . ", " . $l10n->getLocale() . ", " . $locale_expected . "\n";
// print "MO: " . $l10n->getMoFile() . "\n";
$this->assertEquals(
$locale_expected,
@@ -286,6 +344,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
[
'locale' => $locale_expected,
'lang' => $lang_expected,
'lang_short' => $lang_short_expected,
'domain' => $domain_expected,
'encoding' => $encoding_expected,
'path' => $path

View File

@@ -0,0 +1 @@
ja_JP

View File

@@ -7,7 +7,8 @@
"phpstan/phpstan": "^1.10",
"phan/phan": "^5.4",
"phpstan/extension-installer": "^1.2",
"vimeo/psalm": "^5.7"
"vimeo/psalm": "^5.7",
"phpstan/phpstan-deprecation-rules": "^1.1"
},
"config": {
"allow-plugins": {

50
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "0394d224d0f07a238818542e4602ba86",
"content-hash": "c633a27ea30371ec870c8065ca4ae4cd",
"packages": [],
"packages-dev": [
{
@@ -1162,6 +1162,54 @@
],
"time": "2023-03-07T16:48:45+00:00"
},
{
"name": "phpstan/phpstan-deprecation-rules",
"version": "1.1.2",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan-deprecation-rules.git",
"reference": "bcc1e8cdf81c3da1a2ba9188ee94cd7e2a62e865"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan-deprecation-rules/zipball/bcc1e8cdf81c3da1a2ba9188ee94cd7e2a62e865",
"reference": "bcc1e8cdf81c3da1a2ba9188ee94cd7e2a62e865",
"shasum": ""
},
"require": {
"php": "^7.2 || ^8.0",
"phpstan/phpstan": "^1.10"
},
"require-dev": {
"php-parallel-lint/php-parallel-lint": "^1.2",
"phpstan/phpstan-php-parser": "^1.1",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^9.5"
},
"type": "phpstan-extension",
"extra": {
"phpstan": {
"includes": [
"rules.neon"
]
}
},
"autoload": {
"psr-4": {
"PHPStan\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "PHPStan rules for detecting usage of deprecated classes, methods, properties, constants and traits.",
"support": {
"issues": "https://github.com/phpstan/phpstan-deprecation-rules/issues",
"source": "https://github.com/phpstan/phpstan-deprecation-rules/tree/1.1.2"
},
"time": "2023-01-17T16:14:21+00:00"
},
{
"name": "psr/container",
"version": "2.0.2",

View File

@@ -10,23 +10,15 @@ parameters:
- %currentWorkingDirectory%/www
bootstrapFiles:
- %currentWorkingDirectory%/phpstan-bootstrap.php
# - %currentWorkingDirectory%/www/lib/autoloader.php
- %currentWorkingDirectory%/www/vendor/autoload.php
scanDirectories:
- www/vendor
scanFiles:
- www/configs/config.php
- www/configs/config.master.php
# if composer.json autoloader defined, this is not needed
# - www/lib/autoloader.php
# - www/vendor/autoload.php
excludePaths:
# do not check old qq file uploader tests
- www/admin/qq_file_upload_*.php
# ignore all test files
# - www/admin/class_test*.php
# extra in sub folder
- www/admin/subfolder/class_test*.php
- www/admin/error_test.php
# admin synlink files
- www/admin/edit_*.php
@@ -37,10 +29,6 @@ parameters:
# ignore admin header stuff
# - www/includes/admin_header.php # ignore the admin include stuff
- www/includes/admin_footer.php # ignore the admin include stuff
# deprecated files
- www/includes/admin_set_paths.php # ignore the admin include stuff
- www/includes/admin_smarty.php # ignore the admin include stuff
- www/includes/edit_base.LEGACY.php # old style
# folders with data no check needed
- www/templates_c
- www/cache
@@ -51,13 +39,9 @@ parameters:
- www/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%/www/lib/CoreLibs/DB/SQL/PgSQL.php
# this is ignored for now
- # in the class_test tree we allow deprecated calls
message: "#^Call to deprecated method #"
path: %currentWorkingDirectory%/www/admin/class_test.*.php
# - '#Expression in empty\(\) is always falsy.#'
# -
# message: '#Reflection error: [a-zA-Z0-9\\_]+ not found.#'

View File

@@ -14,8 +14,8 @@ return array(
'76cd0796156622033397994f25b0d8fc' => $vendorDir . '/amphp/amp/lib/Internal/functions.php',
'6e3fae29631ef280660b3cdad06f25a8' => $vendorDir . '/symfony/deprecation-contracts/function.php',
'b6b991a57620e2fb6b2f66f03fe9ddc2' => $vendorDir . '/symfony/string/Resources/functions.php',
'6cd5651c4fef5ed6b63e8d8b8ffbf3cc' => $vendorDir . '/amphp/byte-stream/lib/functions.php',
'9b38cf48e83f5d8f60375221cd213eee' => $vendorDir . '/phpstan/phpstan/bootstrap.php',
'6cd5651c4fef5ed6b63e8d8b8ffbf3cc' => $vendorDir . '/amphp/byte-stream/lib/functions.php',
'2b9d0f43f9552984cfa82fee95491826' => $vendorDir . '/sabre/event/lib/coroutine.php',
'd81bab31d3feb45bfe2f283ea3c8fdf7' => $vendorDir . '/sabre/event/lib/Loop/functions.php',
'a1cce3d26cc15c00fcd0b3354bd72c88' => $vendorDir . '/sabre/event/lib/Promise/functions.php',

View File

@@ -28,6 +28,7 @@ return array(
'Phan\\' => array($vendorDir . '/phan/phan/src/Phan'),
'PackageVersions\\' => array($vendorDir . '/composer/package-versions-deprecated/src/PackageVersions'),
'PHPStan\\ExtensionInstaller\\' => array($vendorDir . '/phpstan/extension-installer/src'),
'PHPStan\\' => array($vendorDir . '/phpstan/phpstan-deprecation-rules/src'),
'Microsoft\\PhpParser\\' => array($vendorDir . '/microsoft/tolerant-php-parser/src'),
'LanguageServerProtocol\\' => array($vendorDir . '/felixfbecker/language-server-protocol/src'),
'Fidry\\CpuCoreCounter\\' => array($vendorDir . '/fidry/cpu-core-counter/src'),

View File

@@ -15,8 +15,8 @@ class ComposerStaticInitdd705c6e8ab22e0d642372dec7767718
'76cd0796156622033397994f25b0d8fc' => __DIR__ . '/..' . '/amphp/amp/lib/Internal/functions.php',
'6e3fae29631ef280660b3cdad06f25a8' => __DIR__ . '/..' . '/symfony/deprecation-contracts/function.php',
'b6b991a57620e2fb6b2f66f03fe9ddc2' => __DIR__ . '/..' . '/symfony/string/Resources/functions.php',
'6cd5651c4fef5ed6b63e8d8b8ffbf3cc' => __DIR__ . '/..' . '/amphp/byte-stream/lib/functions.php',
'9b38cf48e83f5d8f60375221cd213eee' => __DIR__ . '/..' . '/phpstan/phpstan/bootstrap.php',
'6cd5651c4fef5ed6b63e8d8b8ffbf3cc' => __DIR__ . '/..' . '/amphp/byte-stream/lib/functions.php',
'2b9d0f43f9552984cfa82fee95491826' => __DIR__ . '/..' . '/sabre/event/lib/coroutine.php',
'd81bab31d3feb45bfe2f283ea3c8fdf7' => __DIR__ . '/..' . '/sabre/event/lib/Loop/functions.php',
'a1cce3d26cc15c00fcd0b3354bd72c88' => __DIR__ . '/..' . '/sabre/event/lib/Promise/functions.php',
@@ -64,6 +64,7 @@ class ComposerStaticInitdd705c6e8ab22e0d642372dec7767718
'Phan\\' => 5,
'PackageVersions\\' => 16,
'PHPStan\\ExtensionInstaller\\' => 27,
'PHPStan\\' => 8,
),
'M' =>
array (
@@ -182,6 +183,10 @@ class ComposerStaticInitdd705c6e8ab22e0d642372dec7767718
array (
0 => __DIR__ . '/..' . '/phpstan/extension-installer/src',
),
'PHPStan\\' =>
array (
0 => __DIR__ . '/..' . '/phpstan/phpstan-deprecation-rules/src',
),
'Microsoft\\PhpParser\\' =>
array (
0 => __DIR__ . '/..' . '/microsoft/tolerant-php-parser/src',

View File

@@ -1212,6 +1212,57 @@
],
"install-path": "../phpstan/phpstan"
},
{
"name": "phpstan/phpstan-deprecation-rules",
"version": "1.1.2",
"version_normalized": "1.1.2.0",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan-deprecation-rules.git",
"reference": "bcc1e8cdf81c3da1a2ba9188ee94cd7e2a62e865"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan-deprecation-rules/zipball/bcc1e8cdf81c3da1a2ba9188ee94cd7e2a62e865",
"reference": "bcc1e8cdf81c3da1a2ba9188ee94cd7e2a62e865",
"shasum": ""
},
"require": {
"php": "^7.2 || ^8.0",
"phpstan/phpstan": "^1.10"
},
"require-dev": {
"php-parallel-lint/php-parallel-lint": "^1.2",
"phpstan/phpstan-php-parser": "^1.1",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^9.5"
},
"time": "2023-01-17T16:14:21+00:00",
"type": "phpstan-extension",
"extra": {
"phpstan": {
"includes": [
"rules.neon"
]
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"PHPStan\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "PHPStan rules for detecting usage of deprecated classes, methods, properties, constants and traits.",
"support": {
"issues": "https://github.com/phpstan/phpstan-deprecation-rules/issues",
"source": "https://github.com/phpstan/phpstan-deprecation-rules/tree/1.1.2"
},
"install-path": "../phpstan/phpstan-deprecation-rules"
},
{
"name": "psr/container",
"version": "2.0.2",
@@ -2621,6 +2672,7 @@
"phpdocumentor/type-resolver",
"phpstan/extension-installer",
"phpstan/phpstan",
"phpstan/phpstan-deprecation-rules",
"psr/container",
"psr/log",
"sabre/event",

View File

@@ -196,6 +196,15 @@
'aliases' => array(),
'dev_requirement' => true,
),
'phpstan/phpstan-deprecation-rules' => array(
'pretty_version' => '1.1.2',
'version' => '1.1.2.0',
'reference' => 'bcc1e8cdf81c3da1a2ba9188ee94cd7e2a62e865',
'type' => 'phpstan-extension',
'install_path' => __DIR__ . '/../phpstan/phpstan-deprecation-rules',
'aliases' => array(),
'dev_requirement' => true,
),
'psalm/psalm' => array(
'dev_requirement' => true,
'provided' => array(

View File

@@ -0,0 +1,27 @@
root = true
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
trim_trailing_whitespace = true
[*.{php,phpt}]
indent_style = tab
indent_size = 4
[*.xml]
indent_style = tab
indent_size = 4
[*.neon]
indent_style = tab
indent_size = 4
[*.{yaml,yml}]
indent_style = space
indent_size = 2
[composer.json]
indent_style = tab
indent_size = 4

View File

@@ -0,0 +1,38 @@
# Rules for detecting usage of deprecated classes, methods, properties, constants and traits.
[![Build](https://github.com/phpstan/phpstan-deprecation-rules/workflows/Build/badge.svg)](https://github.com/phpstan/phpstan-deprecation-rules/actions)
[![Latest Stable Version](https://poser.pugx.org/phpstan/phpstan-deprecation-rules/v/stable)](https://packagist.org/packages/phpstan/phpstan-deprecation-rules)
[![License](https://poser.pugx.org/phpstan/phpstan-deprecation-rules/license)](https://packagist.org/packages/phpstan/phpstan-deprecation-rules)
* [PHPStan](https://phpstan.org/)
## Installation
To use this extension, require it in [Composer](https://getcomposer.org/):
```
composer require --dev phpstan/phpstan-deprecation-rules
```
If you also install [phpstan/extension-installer](https://github.com/phpstan/extension-installer) then you're all set!
<details>
<summary>Manual installation</summary>
If you don't want to use `phpstan/extension-installer`, include rules.neon in your project's PHPStan config:
```
includes:
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
```
</details>
## Deprecating code you don't own
This extension emits deprecation warnings on code, which uses properties/functions/methods/classes which are annotated as `@deprecated`.
In case you don't own the code which you want to be considered deprecated, use [PHPStan Stub Files](https://phpstan.org/user-guide/stub-files) to declare deprecations for vendor files like:
```
/** @deprecated */
class ThirdPartyClass {}
```

View File

@@ -0,0 +1,12 @@
{
"require-dev": {
"consistence-community/coding-standard": "^3.10",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
"slevomat/coding-standard": "^7.0"
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}

View File

@@ -0,0 +1,322 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "4485bbedba7bcc71ace5f69dbb9b6c47",
"packages": [],
"packages-dev": [
{
"name": "consistence-community/coding-standard",
"version": "3.11.1",
"source": {
"type": "git",
"url": "https://github.com/consistence-community/coding-standard.git",
"reference": "4632fead8c9ee8f50044fcbce9f66c797b34c0df"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/consistence-community/coding-standard/zipball/4632fead8c9ee8f50044fcbce9f66c797b34c0df",
"reference": "4632fead8c9ee8f50044fcbce9f66c797b34c0df",
"shasum": ""
},
"require": {
"php": ">=7.4",
"slevomat/coding-standard": "~7.0",
"squizlabs/php_codesniffer": "~3.6.0"
},
"replace": {
"consistence/coding-standard": "3.10.*"
},
"require-dev": {
"phing/phing": "2.16.4",
"php-parallel-lint/php-parallel-lint": "1.3.0",
"phpunit/phpunit": "9.5.4"
},
"type": "library",
"autoload": {
"psr-4": {
"Consistence\\": [
"Consistence"
]
},
"classmap": [
"Consistence"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Vašek Purchart",
"email": "me@vasekpurchart.cz",
"homepage": "http://vasekpurchart.cz"
}
],
"description": "Consistence - Coding Standard - PHP Code Sniffer rules",
"keywords": [
"Coding Standard",
"PHPCodeSniffer",
"codesniffer",
"coding",
"cs",
"phpcs",
"ruleset",
"sniffer",
"standard"
],
"support": {
"issues": "https://github.com/consistence-community/coding-standard/issues",
"source": "https://github.com/consistence-community/coding-standard/tree/3.11.1"
},
"time": "2021-05-03T18:13:22+00:00"
},
{
"name": "dealerdirect/phpcodesniffer-composer-installer",
"version": "v0.7.2",
"source": {
"type": "git",
"url": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer.git",
"reference": "1c968e542d8843d7cd71de3c5c9c3ff3ad71a1db"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/1c968e542d8843d7cd71de3c5c9c3ff3ad71a1db",
"reference": "1c968e542d8843d7cd71de3c5c9c3ff3ad71a1db",
"shasum": ""
},
"require": {
"composer-plugin-api": "^1.0 || ^2.0",
"php": ">=5.3",
"squizlabs/php_codesniffer": "^2.0 || ^3.1.0 || ^4.0"
},
"require-dev": {
"composer/composer": "*",
"php-parallel-lint/php-parallel-lint": "^1.3.1",
"phpcompatibility/php-compatibility": "^9.0"
},
"type": "composer-plugin",
"extra": {
"class": "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin"
},
"autoload": {
"psr-4": {
"Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Franck Nijhof",
"email": "franck.nijhof@dealerdirect.com",
"homepage": "http://www.frenck.nl",
"role": "Developer / IT Manager"
},
{
"name": "Contributors",
"homepage": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer/graphs/contributors"
}
],
"description": "PHP_CodeSniffer Standards Composer Installer Plugin",
"homepage": "http://www.dealerdirect.com",
"keywords": [
"PHPCodeSniffer",
"PHP_CodeSniffer",
"code quality",
"codesniffer",
"composer",
"installer",
"phpcbf",
"phpcs",
"plugin",
"qa",
"quality",
"standard",
"standards",
"style guide",
"stylecheck",
"tests"
],
"support": {
"issues": "https://github.com/dealerdirect/phpcodesniffer-composer-installer/issues",
"source": "https://github.com/dealerdirect/phpcodesniffer-composer-installer"
},
"time": "2022-02-04T12:51:07+00:00"
},
{
"name": "phpstan/phpdoc-parser",
"version": "1.5.1",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpdoc-parser.git",
"reference": "981cc368a216c988e862a75e526b6076987d1b50"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/981cc368a216c988e862a75e526b6076987d1b50",
"reference": "981cc368a216c988e862a75e526b6076987d1b50",
"shasum": ""
},
"require": {
"php": "^7.2 || ^8.0"
},
"require-dev": {
"php-parallel-lint/php-parallel-lint": "^1.2",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^1.5",
"phpstan/phpstan-strict-rules": "^1.0",
"phpunit/phpunit": "^9.5",
"symfony/process": "^5.2"
},
"type": "library",
"autoload": {
"psr-4": {
"PHPStan\\PhpDocParser\\": [
"src/"
]
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "PHPDoc parser with support for nullable, intersection and generic types",
"support": {
"issues": "https://github.com/phpstan/phpdoc-parser/issues",
"source": "https://github.com/phpstan/phpdoc-parser/tree/1.5.1"
},
"time": "2022-05-05T11:32:40+00:00"
},
{
"name": "slevomat/coding-standard",
"version": "7.2.1",
"source": {
"type": "git",
"url": "https://github.com/slevomat/coding-standard.git",
"reference": "aff06ae7a84e4534bf6f821dc982a93a5d477c90"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/slevomat/coding-standard/zipball/aff06ae7a84e4534bf6f821dc982a93a5d477c90",
"reference": "aff06ae7a84e4534bf6f821dc982a93a5d477c90",
"shasum": ""
},
"require": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7",
"php": "^7.2 || ^8.0",
"phpstan/phpdoc-parser": "^1.5.1",
"squizlabs/php_codesniffer": "^3.6.2"
},
"require-dev": {
"phing/phing": "2.17.3",
"php-parallel-lint/php-parallel-lint": "1.3.2",
"phpstan/phpstan": "1.4.10|1.7.1",
"phpstan/phpstan-deprecation-rules": "1.0.0",
"phpstan/phpstan-phpunit": "1.0.0|1.1.1",
"phpstan/phpstan-strict-rules": "1.2.3",
"phpunit/phpunit": "7.5.20|8.5.21|9.5.20"
},
"type": "phpcodesniffer-standard",
"extra": {
"branch-alias": {
"dev-master": "7.x-dev"
}
},
"autoload": {
"psr-4": {
"SlevomatCodingStandard\\": "SlevomatCodingStandard"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.",
"support": {
"issues": "https://github.com/slevomat/coding-standard/issues",
"source": "https://github.com/slevomat/coding-standard/tree/7.2.1"
},
"funding": [
{
"url": "https://github.com/kukulich",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/slevomat/coding-standard",
"type": "tidelift"
}
],
"time": "2022-05-25T10:58:12+00:00"
},
{
"name": "squizlabs/php_codesniffer",
"version": "3.6.2",
"source": {
"type": "git",
"url": "https://github.com/squizlabs/PHP_CodeSniffer.git",
"reference": "5e4e71592f69da17871dba6e80dd51bce74a351a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/5e4e71592f69da17871dba6e80dd51bce74a351a",
"reference": "5e4e71592f69da17871dba6e80dd51bce74a351a",
"shasum": ""
},
"require": {
"ext-simplexml": "*",
"ext-tokenizer": "*",
"ext-xmlwriter": "*",
"php": ">=5.4.0"
},
"require-dev": {
"phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0"
},
"bin": [
"bin/phpcs",
"bin/phpcbf"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.x-dev"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Greg Sherwood",
"role": "lead"
}
],
"description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.",
"homepage": "https://github.com/squizlabs/PHP_CodeSniffer",
"keywords": [
"phpcs",
"standards"
],
"support": {
"issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues",
"source": "https://github.com/squizlabs/PHP_CodeSniffer",
"wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki"
},
"time": "2021-12-12T21:44:58+00:00"
}
],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": [],
"plugin-api-version": "2.3.0"
}

View File

@@ -0,0 +1,43 @@
{
"name": "phpstan/phpstan-deprecation-rules",
"type": "phpstan-extension",
"description": "PHPStan rules for detecting usage of deprecated classes, methods, properties, constants and traits.",
"license": [
"MIT"
],
"require": {
"php": "^7.2 || ^8.0",
"phpstan/phpstan": "^1.10"
},
"require-dev": {
"php-parallel-lint/php-parallel-lint": "^1.2",
"phpstan/phpstan-phpunit": "^1.0",
"phpstan/phpstan-php-parser": "^1.1",
"phpunit/phpunit": "^9.5"
},
"config": {
"platform": {
"php": "7.4.6"
},
"sort-packages": true
},
"extra": {
"phpstan": {
"includes": [
"rules.neon"
]
}
},
"autoload": {
"psr-4": {
"PHPStan\\": "src/"
}
},
"autoload-dev": {
"classmap": [
"tests/"
]
},
"minimum-stability": "dev",
"prefer-stable": true
}

View File

@@ -0,0 +1,24 @@
parameters:
deprecationRulesInstalled: true
services:
-
class: PHPStan\Rules\Deprecations\DeprecatedClassHelper
rules:
- PHPStan\Rules\Deprecations\AccessDeprecatedPropertyRule
- PHPStan\Rules\Deprecations\AccessDeprecatedStaticPropertyRule
- PHPStan\Rules\Deprecations\CallToDeprecatedFunctionRule
- PHPStan\Rules\Deprecations\CallToDeprecatedMethodRule
- PHPStan\Rules\Deprecations\CallToDeprecatedStaticMethodRule
- PHPStan\Rules\Deprecations\FetchingClassConstOfDeprecatedClassRule
- PHPStan\Rules\Deprecations\FetchingDeprecatedConstRule
- PHPStan\Rules\Deprecations\ImplementationOfDeprecatedInterfaceRule
- PHPStan\Rules\Deprecations\InheritanceOfDeprecatedClassRule
- PHPStan\Rules\Deprecations\InheritanceOfDeprecatedInterfaceRule
- PHPStan\Rules\Deprecations\InstantiationOfDeprecatedClassRule
- PHPStan\Rules\Deprecations\TypeHintDeprecatedInClassMethodSignatureRule
- PHPStan\Rules\Deprecations\TypeHintDeprecatedInClosureSignatureRule
- PHPStan\Rules\Deprecations\TypeHintDeprecatedInFunctionSignatureRule
- PHPStan\Rules\Deprecations\UsageOfDeprecatedCastRule
- PHPStan\Rules\Deprecations\UsageOfDeprecatedTraitRule

View File

@@ -0,0 +1,80 @@
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Deprecations;
use PhpParser\Node;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Identifier;
use PHPStan\Analyser\Scope;
use PHPStan\Broker\ClassNotFoundException;
use PHPStan\Reflection\MissingPropertyFromReflectionException;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Rule;
use function sprintf;
/**
* @implements Rule<PropertyFetch>
*/
class AccessDeprecatedPropertyRule implements Rule
{
/** @var ReflectionProvider */
private $reflectionProvider;
public function __construct(ReflectionProvider $reflectionProvider)
{
$this->reflectionProvider = $reflectionProvider;
}
public function getNodeType(): string
{
return PropertyFetch::class;
}
public function processNode(Node $node, Scope $scope): array
{
if (DeprecatedScopeHelper::isScopeDeprecated($scope)) {
return [];
}
if (!$node->name instanceof Identifier) {
return [];
}
$propertyName = $node->name->name;
$propertyAccessedOnType = $scope->getType($node->var);
$referencedClasses = $propertyAccessedOnType->getObjectClassNames();
foreach ($referencedClasses as $referencedClass) {
try {
$classReflection = $this->reflectionProvider->getClass($referencedClass);
$propertyReflection = $classReflection->getProperty($propertyName, $scope);
if ($propertyReflection->isDeprecated()->yes()) {
$description = $propertyReflection->getDeprecatedDescription();
if ($description === null) {
return [sprintf(
'Access to deprecated property $%s of class %s.',
$propertyName,
$propertyReflection->getDeclaringClass()->getName()
)];
}
return [sprintf(
"Access to deprecated property $%s of class %s:\n%s",
$propertyName,
$propertyReflection->getDeclaringClass()->getName(),
$description
)];
}
} catch (ClassNotFoundException $e) {
// Other rules will notify if the class is not found
} catch (MissingPropertyFromReflectionException $e) {
// Other rules will notify if the property is not found
}
}
return [];
}
}

View File

@@ -0,0 +1,106 @@
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Deprecations;
use PhpParser\Node;
use PhpParser\Node\Expr\StaticPropertyFetch;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PHPStan\Analyser\Scope;
use PHPStan\Broker\ClassNotFoundException;
use PHPStan\Reflection\MissingPropertyFromReflectionException;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleLevelHelper;
use PHPStan\Type\ErrorType;
use PHPStan\Type\Type;
use function sprintf;
/**
* @implements Rule<StaticPropertyFetch>
*/
class AccessDeprecatedStaticPropertyRule implements Rule
{
/** @var ReflectionProvider */
private $reflectionProvider;
/** @var RuleLevelHelper */
private $ruleLevelHelper;
public function __construct(ReflectionProvider $reflectionProvider, RuleLevelHelper $ruleLevelHelper)
{
$this->reflectionProvider = $reflectionProvider;
$this->ruleLevelHelper = $ruleLevelHelper;
}
public function getNodeType(): string
{
return StaticPropertyFetch::class;
}
public function processNode(Node $node, Scope $scope): array
{
if (DeprecatedScopeHelper::isScopeDeprecated($scope)) {
return [];
}
if (!$node->name instanceof Identifier) {
return [];
}
$propertyName = $node->name->name;
$referencedClasses = [];
if ($node->class instanceof Name) {
$referencedClasses[] = (string) $node->class;
} else {
$classTypeResult = $this->ruleLevelHelper->findTypeToCheck(
$scope,
$node->class,
'', // We don't care about the error message
static function (Type $type) use ($propertyName): bool {
return $type->canAccessProperties()->yes() && $type->hasProperty($propertyName)->yes();
}
);
if ($classTypeResult->getType() instanceof ErrorType) {
return [];
}
$referencedClasses = $classTypeResult->getReferencedClasses();
}
foreach ($referencedClasses as $referencedClass) {
try {
$class = $this->reflectionProvider->getClass($referencedClass);
$property = $class->getProperty($propertyName, $scope);
} catch (ClassNotFoundException $e) {
continue;
} catch (MissingPropertyFromReflectionException $e) {
continue;
}
if ($property->isDeprecated()->yes()) {
$description = $property->getDeprecatedDescription();
if ($description === null) {
return [sprintf(
'Access to deprecated static property $%s of class %s.',
$propertyName,
$referencedClass
)];
}
return [sprintf(
"Access to deprecated static property $%s of class %s:\n%s",
$propertyName,
$referencedClass,
$description
)];
}
}
return [];
}
}

View File

@@ -0,0 +1,69 @@
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Deprecations;
use PhpParser\Node;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Name;
use PHPStan\Analyser\Scope;
use PHPStan\Broker\FunctionNotFoundException;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Rule;
use function sprintf;
/**
* @implements Rule<FuncCall>
*/
class CallToDeprecatedFunctionRule implements Rule
{
/** @var ReflectionProvider */
private $reflectionProvider;
public function __construct(ReflectionProvider $reflectionProvider)
{
$this->reflectionProvider = $reflectionProvider;
}
public function getNodeType(): string
{
return FuncCall::class;
}
public function processNode(Node $node, Scope $scope): array
{
if (DeprecatedScopeHelper::isScopeDeprecated($scope)) {
return [];
}
if (!($node->name instanceof Name)) {
return [];
}
try {
$function = $this->reflectionProvider->getFunction($node->name, $scope);
} catch (FunctionNotFoundException $e) {
// Other rules will notify if the function is not found
return [];
}
if ($function->isDeprecated()->yes()) {
$description = $function->getDeprecatedDescription();
if ($description === null) {
return [sprintf(
'Call to deprecated function %s().',
$function->getName()
)];
}
return [sprintf(
"Call to deprecated function %s():\n%s",
$function->getName(),
$description
)];
}
return [];
}
}

View File

@@ -0,0 +1,82 @@
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Deprecations;
use PhpParser\Node;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Identifier;
use PHPStan\Analyser\Scope;
use PHPStan\Broker\ClassNotFoundException;
use PHPStan\Reflection\MissingMethodFromReflectionException;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Rule;
use function sprintf;
/**
* @implements Rule<MethodCall>
*/
class CallToDeprecatedMethodRule implements Rule
{
/** @var ReflectionProvider */
private $reflectionProvider;
public function __construct(ReflectionProvider $reflectionProvider)
{
$this->reflectionProvider = $reflectionProvider;
}
public function getNodeType(): string
{
return MethodCall::class;
}
public function processNode(Node $node, Scope $scope): array
{
if (DeprecatedScopeHelper::isScopeDeprecated($scope)) {
return [];
}
if (!$node->name instanceof Identifier) {
return [];
}
$methodName = $node->name->name;
$methodCalledOnType = $scope->getType($node->var);
$referencedClasses = $methodCalledOnType->getObjectClassNames();
foreach ($referencedClasses as $referencedClass) {
try {
$classReflection = $this->reflectionProvider->getClass($referencedClass);
$methodReflection = $classReflection->getMethod($methodName, $scope);
if (!$methodReflection->isDeprecated()->yes()) {
continue;
}
$description = $methodReflection->getDeprecatedDescription();
if ($description === null) {
return [sprintf(
'Call to deprecated method %s() of class %s.',
$methodReflection->getName(),
$methodReflection->getDeclaringClass()->getName()
)];
}
return [sprintf(
"Call to deprecated method %s() of class %s:\n%s",
$methodReflection->getName(),
$methodReflection->getDeclaringClass()->getName(),
$description
)];
} catch (ClassNotFoundException $e) {
// Other rules will notify if the class is not found
} catch (MissingMethodFromReflectionException $e) {
// Other rules will notify if the the method is not found
}
}
return [];
}
}

View File

@@ -0,0 +1,128 @@
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Deprecations;
use PhpParser\Node;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PHPStan\Analyser\Scope;
use PHPStan\Broker\ClassNotFoundException;
use PHPStan\Reflection\MissingMethodFromReflectionException;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleLevelHelper;
use PHPStan\Type\ErrorType;
use PHPStan\Type\Type;
use function sprintf;
/**
* @implements Rule<StaticCall>
*/
class CallToDeprecatedStaticMethodRule implements Rule
{
/** @var ReflectionProvider */
private $reflectionProvider;
/** @var RuleLevelHelper */
private $ruleLevelHelper;
public function __construct(ReflectionProvider $reflectionProvider, RuleLevelHelper $ruleLevelHelper)
{
$this->reflectionProvider = $reflectionProvider;
$this->ruleLevelHelper = $ruleLevelHelper;
}
public function getNodeType(): string
{
return StaticCall::class;
}
public function processNode(Node $node, Scope $scope): array
{
if (DeprecatedScopeHelper::isScopeDeprecated($scope)) {
return [];
}
if (!$node->name instanceof Identifier) {
return [];
}
$methodName = $node->name->name;
$referencedClasses = [];
if ($node->class instanceof Name) {
$referencedClasses[] = $scope->resolveName($node->class);
} else {
$classTypeResult = $this->ruleLevelHelper->findTypeToCheck(
$scope,
$node->class,
'', // We don't care about the error message
static function (Type $type) use ($methodName): bool {
return $type->canCallMethods()->yes() && $type->hasMethod($methodName)->yes();
}
);
if ($classTypeResult->getType() instanceof ErrorType) {
return [];
}
$referencedClasses = $classTypeResult->getReferencedClasses();
}
$errors = [];
foreach ($referencedClasses as $referencedClass) {
try {
$class = $this->reflectionProvider->getClass($referencedClass);
$methodReflection = $class->getMethod($methodName, $scope);
} catch (ClassNotFoundException $e) {
continue;
} catch (MissingMethodFromReflectionException $e) {
continue;
}
if ($class->isDeprecated()) {
$classDescription = $class->getDeprecatedDescription();
if ($classDescription === null) {
$errors[] = sprintf(
'Call to method %s() of deprecated class %s.',
$methodReflection->getName(),
$methodReflection->getDeclaringClass()->getName()
);
} else {
$errors[] = sprintf(
"Call to method %s() of deprecated class %s:\n%s",
$methodReflection->getName(),
$methodReflection->getDeclaringClass()->getName(),
$classDescription
);
}
}
if (!$methodReflection->isDeprecated()->yes()) {
continue;
}
$description = $methodReflection->getDeprecatedDescription();
if ($description === null) {
$errors[] = sprintf(
'Call to deprecated method %s() of class %s.',
$methodReflection->getName(),
$methodReflection->getDeclaringClass()->getName()
);
} else {
$errors[] = sprintf(
"Call to deprecated method %s() of class %s:\n%s",
$methodReflection->getName(),
$methodReflection->getDeclaringClass()->getName(),
$description
);
}
}
return $errors;
}
}

View File

@@ -0,0 +1,64 @@
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Deprecations;
use PHPStan\Broker\ClassNotFoundException;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\ReflectionProvider;
use function sprintf;
class DeprecatedClassHelper
{
/** @var ReflectionProvider */
private $reflectionProvider;
public function __construct(ReflectionProvider $reflectionProvider)
{
$this->reflectionProvider = $reflectionProvider;
}
public function getClassType(ClassReflection $class): string
{
if ($class->isInterface()) {
return 'interface';
}
return 'class';
}
public function getClassDeprecationDescription(ClassReflection $class): string
{
$description = $class->getDeprecatedDescription();
if ($description === null) {
return '.';
}
return sprintf(":\n%s", $description);
}
/**
* @param string[] $referencedClasses
* @return ClassReflection[]
*/
public function filterDeprecatedClasses(array $referencedClasses): array
{
$deprecatedClasses = [];
foreach ($referencedClasses as $referencedClass) {
try {
$class = $this->reflectionProvider->getClass($referencedClass);
} catch (ClassNotFoundException $e) {
continue;
}
if (!$class->isDeprecated()) {
continue;
}
$deprecatedClasses[] = $class;
}
return $deprecatedClasses;
}
}

View File

@@ -0,0 +1,30 @@
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Deprecations;
use PHPStan\Analyser\Scope;
class DeprecatedScopeHelper
{
public static function isScopeDeprecated(Scope $scope): bool
{
$class = $scope->getClassReflection();
if ($class !== null && $class->isDeprecated()) {
return true;
}
$trait = $scope->getTraitReflection();
if ($trait !== null && $trait->isDeprecated()) {
return true;
}
$function = $scope->getFunction();
if ($function !== null && $function->isDeprecated()->yes()) {
return true;
}
return false;
}
}

View File

@@ -0,0 +1,135 @@
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Deprecations;
use PhpParser\Node;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PHPStan\Analyser\Scope;
use PHPStan\Broker\ClassNotFoundException;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleLevelHelper;
use PHPStan\Type\ErrorType;
use PHPStan\Type\Type;
use function sprintf;
use function strtolower;
/**
* @implements Rule<ClassConstFetch>
*/
class FetchingClassConstOfDeprecatedClassRule implements Rule
{
/** @var ReflectionProvider */
private $reflectionProvider;
/** @var RuleLevelHelper */
private $ruleLevelHelper;
public function __construct(ReflectionProvider $reflectionProvider, RuleLevelHelper $ruleLevelHelper)
{
$this->reflectionProvider = $reflectionProvider;
$this->ruleLevelHelper = $ruleLevelHelper;
}
public function getNodeType(): string
{
return ClassConstFetch::class;
}
public function processNode(Node $node, Scope $scope): array
{
if (DeprecatedScopeHelper::isScopeDeprecated($scope)) {
return [];
}
if (!$node->name instanceof Identifier) {
return [];
}
$constantName = $node->name->name;
$referencedClasses = [];
if ($node->class instanceof Name) {
$referencedClasses[] = $scope->resolveName($node->class);
} else {
$classTypeResult = $this->ruleLevelHelper->findTypeToCheck(
$scope,
$node->class,
'', // We don't care about the error message
static function (Type $type) use ($constantName): bool {
return $type->canAccessConstants()->yes() && $type->hasConstant($constantName)->yes();
}
);
if ($classTypeResult->getType() instanceof ErrorType) {
return [];
}
$referencedClasses = $classTypeResult->getReferencedClasses();
}
$errors = [];
foreach ($referencedClasses as $referencedClass) {
try {
$class = $this->reflectionProvider->getClass($referencedClass);
} catch (ClassNotFoundException $e) {
continue;
}
if ($class->isDeprecated()) {
$classDescription = $class->getDeprecatedDescription();
if ($classDescription === null) {
$errors[] = sprintf(
'Fetching class constant %s of deprecated class %s.',
$constantName,
$referencedClass
);
} else {
$errors[] = sprintf(
"Fetching class constant %s of deprecated class %s:\n%s",
$constantName,
$referencedClass,
$classDescription
);
}
}
if (strtolower($constantName) === 'class') {
continue;
}
if (!$class->hasConstant($constantName)) {
continue;
}
$constantReflection = $class->getConstant($constantName);
if (!$constantReflection->isDeprecated()->yes()) {
continue;
}
$description = $constantReflection->getDeprecatedDescription();
if ($description === null) {
$errors[] = sprintf(
'Fetching deprecated class constant %s of class %s.',
$constantName,
$referencedClass
);
} else {
$errors[] = sprintf(
"Fetching deprecated class constant %s of class %s:\n%s",
$constantName,
$referencedClass,
$description
);
}
}
return $errors;
}
}

View File

@@ -0,0 +1,70 @@
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Deprecations;
use PhpParser\Node;
use PhpParser\Node\Expr\ConstFetch;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Rule;
use function sprintf;
use const PHP_VERSION_ID;
/**
* @implements Rule<ConstFetch>
*/
class FetchingDeprecatedConstRule implements Rule
{
/** @var ReflectionProvider */
private $reflectionProvider;
/** @var array<string,string> */
private $deprecatedConstants = [];
public function __construct(ReflectionProvider $reflectionProvider)
{
$this->reflectionProvider = $reflectionProvider;
// phpcs:ignore SlevomatCodingStandard.ControlStructures.EarlyExit.EarlyExitNotUsed
if (PHP_VERSION_ID >= 70300) {
$this->deprecatedConstants['FILTER_FLAG_SCHEME_REQUIRED'] = 'Use of constant %s is deprecated since PHP 7.3.';
$this->deprecatedConstants['FILTER_FLAG_HOST_REQUIRED'] = 'Use of constant %s is deprecated since PHP 7.3.';
}
}
public function getNodeType(): string
{
return ConstFetch::class;
}
public function processNode(Node $node, Scope $scope): array
{
if (DeprecatedScopeHelper::isScopeDeprecated($scope)) {
return [];
}
if (!$this->reflectionProvider->hasConstant($node->name, $scope)) {
return [];
}
$constantReflection = $this->reflectionProvider->getConstant($node->name, $scope);
if ($constantReflection->isDeprecated()->yes()) {
return [sprintf(
$constantReflection->getDeprecatedDescription() ?? 'Use of constant %s is deprecated.',
$constantReflection->getName()
)];
}
if (isset($this->deprecatedConstants[$constantReflection->getName()])) {
return [sprintf(
$this->deprecatedConstants[$constantReflection->getName()],
$constantReflection->getName()
)];
}
return [];
}
}

View File

@@ -0,0 +1,100 @@
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Deprecations;
use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use PHPStan\Analyser\Scope;
use PHPStan\Broker\ClassNotFoundException;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Rule;
use function sprintf;
/**
* @implements Rule<Class_>
*/
class ImplementationOfDeprecatedInterfaceRule implements Rule
{
/** @var ReflectionProvider */
private $reflectionProvider;
public function __construct(ReflectionProvider $reflectionProvider)
{
$this->reflectionProvider = $reflectionProvider;
}
public function getNodeType(): string
{
return Class_::class;
}
public function processNode(Node $node, Scope $scope): array
{
if (DeprecatedScopeHelper::isScopeDeprecated($scope)) {
return [];
}
$errors = [];
$className = isset($node->namespacedName)
? (string) $node->namespacedName
: (string) $node->name;
try {
$class = $this->reflectionProvider->getClass($className);
} catch (ClassNotFoundException $e) {
return [];
}
if ($class->isDeprecated()) {
return [];
}
foreach ($node->implements as $implement) {
$interfaceName = (string) $implement;
try {
$interface = $this->reflectionProvider->getClass($interfaceName);
if ($interface->isDeprecated()) {
$description = $interface->getDeprecatedDescription();
if (!$class->isAnonymous()) {
if ($description === null) {
$errors[] = sprintf(
'Class %s implements deprecated interface %s.',
$className,
$interfaceName
);
} else {
$errors[] = sprintf(
"Class %s implements deprecated interface %s:\n%s",
$className,
$interfaceName,
$description
);
}
} else {
if ($description === null) {
$errors[] = sprintf(
'Anonymous class implements deprecated interface %s.',
$interfaceName
);
} else {
$errors[] = sprintf(
"Anonymous class implements deprecated interface %s:\n%s",
$interfaceName,
$description
);
}
}
}
} catch (ClassNotFoundException $e) {
// Other rules will notify if the interface is not found
}
}
return $errors;
}
}

View File

@@ -0,0 +1,97 @@
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Deprecations;
use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use PHPStan\Analyser\Scope;
use PHPStan\Broker\ClassNotFoundException;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Rule;
use function sprintf;
/**
* @implements Rule<Class_>
*/
class InheritanceOfDeprecatedClassRule implements Rule
{
/** @var ReflectionProvider */
private $reflectionProvider;
public function __construct(ReflectionProvider $reflectionProvider)
{
$this->reflectionProvider = $reflectionProvider;
}
public function getNodeType(): string
{
return Class_::class;
}
public function processNode(Node $node, Scope $scope): array
{
if (DeprecatedScopeHelper::isScopeDeprecated($scope)) {
return [];
}
if ($node->extends === null) {
return [];
}
$errors = [];
$className = isset($node->namespacedName)
? (string) $node->namespacedName
: (string) $node->name;
try {
$class = $this->reflectionProvider->getClass($className);
} catch (ClassNotFoundException $e) {
return [];
}
$parentClassName = (string) $node->extends;
try {
$parentClass = $this->reflectionProvider->getClass($parentClassName);
$description = $parentClass->getDeprecatedDescription();
if ($parentClass->isDeprecated()) {
if (!$class->isAnonymous()) {
if ($description === null) {
$errors[] = sprintf(
'Class %s extends deprecated class %s.',
$className,
$parentClassName
);
} else {
$errors[] = sprintf(
"Class %s extends deprecated class %s:\n%s",
$className,
$parentClassName,
$description
);
}
} else {
if ($description === null) {
$errors[] = sprintf(
'Anonymous class extends deprecated class %s.',
$parentClassName
);
} else {
$errors[] = sprintf(
"Anonymous class extends deprecated class %s:\n%s",
$parentClassName,
$description
);
}
}
}
} catch (ClassNotFoundException $e) {
// Other rules will notify if the interface is not found
}
return $errors;
}
}

View File

@@ -0,0 +1,87 @@
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Deprecations;
use PhpParser\Node;
use PhpParser\Node\Stmt\Interface_;
use PHPStan\Analyser\Scope;
use PHPStan\Broker\ClassNotFoundException;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Rule;
use function sprintf;
/**
* @implements Rule<Interface_>
*/
class InheritanceOfDeprecatedInterfaceRule implements Rule
{
/** @var ReflectionProvider */
private $reflectionProvider;
public function __construct(ReflectionProvider $reflectionProvider)
{
$this->reflectionProvider = $reflectionProvider;
}
public function getNodeType(): string
{
return Interface_::class;
}
public function processNode(Node $node, Scope $scope): array
{
if ($node->extends === null) {
return [];
}
$interfaceName = isset($node->namespacedName)
? (string) $node->namespacedName
: (string) $node->name;
try {
$interface = $this->reflectionProvider->getClass($interfaceName);
} catch (ClassNotFoundException $e) {
return [];
}
if ($interface->isDeprecated()) {
return [];
}
$errors = [];
foreach ($node->extends as $parentInterfaceName) {
$parentInterfaceName = (string) $parentInterfaceName;
try {
$parentInterface = $this->reflectionProvider->getClass($parentInterfaceName);
if (!$parentInterface->isDeprecated()) {
continue;
}
$description = $parentInterface->getDeprecatedDescription();
if ($description === null) {
$errors[] = sprintf(
'Interface %s extends deprecated interface %s.',
$interfaceName,
$parentInterfaceName
);
} else {
$errors[] = sprintf(
"Interface %s extends deprecated interface %s:\n%s",
$interfaceName,
$parentInterfaceName,
$description
);
}
} catch (ClassNotFoundException $e) {
// Other rules will notify if the interface is not found
}
}
return $errors;
}
}

View File

@@ -0,0 +1,104 @@
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Deprecations;
use PhpParser\Node;
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt\Class_;
use PHPStan\Analyser\Scope;
use PHPStan\Broker\ClassNotFoundException;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleLevelHelper;
use PHPStan\Type\ErrorType;
use function sprintf;
/**
* @implements Rule<New_>
*/
class InstantiationOfDeprecatedClassRule implements Rule
{
/** @var ReflectionProvider */
private $reflectionProvider;
/** @var RuleLevelHelper */
private $ruleLevelHelper;
public function __construct(ReflectionProvider $reflectionProvider, RuleLevelHelper $ruleLevelHelper)
{
$this->reflectionProvider = $reflectionProvider;
$this->ruleLevelHelper = $ruleLevelHelper;
}
public function getNodeType(): string
{
return New_::class;
}
public function processNode(Node $node, Scope $scope): array
{
if (DeprecatedScopeHelper::isScopeDeprecated($scope)) {
return [];
}
$referencedClasses = [];
if ($node->class instanceof Name) {
$referencedClasses[] = $scope->resolveName($node->class);
} elseif ($node->class instanceof Class_) {
if (!isset($node->class->namespacedName)) {
return [];
}
$referencedClasses[] = $scope->resolveName($node->class->namespacedName);
} else {
$classTypeResult = $this->ruleLevelHelper->findTypeToCheck(
$scope,
$node->class,
'', // We don't care about the error message
static function (): bool {
return true;
}
);
if ($classTypeResult->getType() instanceof ErrorType) {
return [];
}
$referencedClasses = $classTypeResult->getReferencedClasses();
}
$errors = [];
foreach ($referencedClasses as $referencedClass) {
try {
$class = $this->reflectionProvider->getClass($referencedClass);
} catch (ClassNotFoundException $e) {
continue;
}
if (!$class->isDeprecated()) {
continue;
}
$description = $class->getDeprecatedDescription();
if ($description === null) {
$errors[] = sprintf(
'Instantiation of deprecated class %s.',
$referencedClass
);
} else {
$errors[] = sprintf(
"Instantiation of deprecated class %s:\n%s",
$referencedClass,
$description
);
}
}
return $errors;
}
}

View File

@@ -0,0 +1,92 @@
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Deprecations;
use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Node\InClassMethodNode;
use PHPStan\Reflection\ParametersAcceptorSelector;
use PHPStan\Rules\Rule;
use function sprintf;
/**
* @implements Rule<InClassMethodNode>
*/
class TypeHintDeprecatedInClassMethodSignatureRule implements Rule
{
/** @var DeprecatedClassHelper */
private $deprecatedClassHelper;
public function __construct(DeprecatedClassHelper $deprecatedClassHelper)
{
$this->deprecatedClassHelper = $deprecatedClassHelper;
}
public function getNodeType(): string
{
return InClassMethodNode::class;
}
public function processNode(Node $node, Scope $scope): array
{
if (DeprecatedScopeHelper::isScopeDeprecated($scope)) {
return [];
}
$method = $node->getMethodReflection();
$methodSignature = ParametersAcceptorSelector::selectSingle($method->getVariants());
$errors = [];
foreach ($methodSignature->getParameters() as $parameter) {
$deprecatedClasses = $this->deprecatedClassHelper->filterDeprecatedClasses($parameter->getType()->getReferencedClasses());
foreach ($deprecatedClasses as $deprecatedClass) {
if ($method->getDeclaringClass()->isAnonymous()) {
$errors[] = sprintf(
'Parameter $%s of method %s() in anonymous class has typehint with deprecated %s %s%s',
$parameter->getName(),
$method->getName(),
$this->deprecatedClassHelper->getClassType($deprecatedClass),
$deprecatedClass->getName(),
$this->deprecatedClassHelper->getClassDeprecationDescription($deprecatedClass)
);
} else {
$errors[] = sprintf(
'Parameter $%s of method %s::%s() has typehint with deprecated %s %s%s',
$parameter->getName(),
$method->getDeclaringClass()->getName(),
$method->getName(),
$this->deprecatedClassHelper->getClassType($deprecatedClass),
$deprecatedClass->getName(),
$this->deprecatedClassHelper->getClassDeprecationDescription($deprecatedClass)
);
}
}
}
$deprecatedClasses = $this->deprecatedClassHelper->filterDeprecatedClasses($methodSignature->getReturnType()->getReferencedClasses());
foreach ($deprecatedClasses as $deprecatedClass) {
if ($method->getDeclaringClass()->isAnonymous()) {
$errors[] = sprintf(
'Return type of method %s() in anonymous class has typehint with deprecated %s %s%s',
$method->getName(),
$this->deprecatedClassHelper->getClassType($deprecatedClass),
$deprecatedClass->getName(),
$this->deprecatedClassHelper->getClassDeprecationDescription($deprecatedClass)
);
} else {
$errors[] = sprintf(
'Return type of method %s::%s() has typehint with deprecated %s %s%s',
$method->getDeclaringClass()->getName(),
$method->getName(),
$this->deprecatedClassHelper->getClassType($deprecatedClass),
$deprecatedClass->getName(),
$this->deprecatedClassHelper->getClassDeprecationDescription($deprecatedClass)
);
}
}
return $errors;
}
}

View File

@@ -0,0 +1,69 @@
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Deprecations;
use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Node\InClosureNode;
use PHPStan\Rules\Rule;
use PHPStan\ShouldNotHappenException;
use function sprintf;
/**
* @implements Rule<InClosureNode>
*/
class TypeHintDeprecatedInClosureSignatureRule implements Rule
{
/** @var DeprecatedClassHelper */
private $deprecatedClassHelper;
public function __construct(DeprecatedClassHelper $deprecatedClassHelper)
{
$this->deprecatedClassHelper = $deprecatedClassHelper;
}
public function getNodeType(): string
{
return InClosureNode::class;
}
public function processNode(Node $node, Scope $scope): array
{
if (DeprecatedScopeHelper::isScopeDeprecated($scope)) {
return [];
}
$functionSignature = $scope->getAnonymousFunctionReflection();
if ($functionSignature === null) {
throw new ShouldNotHappenException();
}
$errors = [];
foreach ($functionSignature->getParameters() as $parameter) {
$deprecatedClasses = $this->deprecatedClassHelper->filterDeprecatedClasses($parameter->getType()->getReferencedClasses());
foreach ($deprecatedClasses as $deprecatedClass) {
$errors[] = sprintf(
'Parameter $%s of anonymous function has typehint with deprecated %s %s%s',
$parameter->getName(),
$this->deprecatedClassHelper->getClassType($deprecatedClass),
$deprecatedClass->getName(),
$this->deprecatedClassHelper->getClassDeprecationDescription($deprecatedClass)
);
}
}
$deprecatedClasses = $this->deprecatedClassHelper->filterDeprecatedClasses($functionSignature->getReturnType()->getReferencedClasses());
foreach ($deprecatedClasses as $deprecatedClass) {
$errors[] = sprintf(
'Return type of anonymous function has typehint with deprecated %s %s%s',
$this->deprecatedClassHelper->getClassType($deprecatedClass),
$deprecatedClass->getName(),
$this->deprecatedClassHelper->getClassDeprecationDescription($deprecatedClass)
);
}
return $errors;
}
}

View File

@@ -0,0 +1,73 @@
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Deprecations;
use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Node\InFunctionNode;
use PHPStan\Reflection\ParametersAcceptorSelector;
use PHPStan\Rules\Rule;
use PHPStan\ShouldNotHappenException;
use function sprintf;
/**
* @implements Rule<InFunctionNode>
*/
class TypeHintDeprecatedInFunctionSignatureRule implements Rule
{
/** @var DeprecatedClassHelper */
private $deprecatedClassHelper;
public function __construct(DeprecatedClassHelper $deprecatedClassHelper)
{
$this->deprecatedClassHelper = $deprecatedClassHelper;
}
public function getNodeType(): string
{
return InFunctionNode::class;
}
public function processNode(Node $node, Scope $scope): array
{
if (DeprecatedScopeHelper::isScopeDeprecated($scope)) {
return [];
}
$function = $scope->getFunction();
if ($function === null) {
throw new ShouldNotHappenException();
}
$functionSignature = ParametersAcceptorSelector::selectSingle($function->getVariants());
$errors = [];
foreach ($functionSignature->getParameters() as $parameter) {
$deprecatedClasses = $this->deprecatedClassHelper->filterDeprecatedClasses($parameter->getType()->getReferencedClasses());
foreach ($deprecatedClasses as $deprecatedClass) {
$errors[] = sprintf(
'Parameter $%s of function %s() has typehint with deprecated %s %s%s',
$parameter->getName(),
$function->getName(),
$this->deprecatedClassHelper->getClassType($deprecatedClass),
$deprecatedClass->getName(),
$this->deprecatedClassHelper->getClassDeprecationDescription($deprecatedClass)
);
}
}
$deprecatedClasses = $this->deprecatedClassHelper->filterDeprecatedClasses($functionSignature->getReturnType()->getReferencedClasses());
foreach ($deprecatedClasses as $deprecatedClass) {
$errors[] = sprintf(
'Return type of function %s() has typehint with deprecated %s %s%s',
$function->getName(),
$this->deprecatedClassHelper->getClassType($deprecatedClass),
$deprecatedClass->getName(),
$this->deprecatedClassHelper->getClassDeprecationDescription($deprecatedClass)
);
}
return $errors;
}
}

View File

@@ -0,0 +1,52 @@
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Deprecations;
use PhpParser\Node;
use PhpParser\Node\Expr\Cast;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Rule;
use function sprintf;
/**
* @implements Rule<Cast>
*/
class UsageOfDeprecatedCastRule implements Rule
{
public function getNodeType(): string
{
return Cast::class;
}
public function processNode(Node $node, Scope $scope): array
{
if (DeprecatedScopeHelper::isScopeDeprecated($scope)) {
return [];
}
$castedType = $scope->getType($node->expr);
if (! $castedType->hasMethod('__toString')->yes()) {
return [];
}
$method = $castedType->getMethod('__toString', $scope);
if (! $method->isDeprecated()->yes()) {
return [];
}
$description = $method->getDeprecatedDescription();
if ($description === null) {
return [sprintf(
'Casting class %s to string is deprecated.',
$method->getDeclaringClass()->getName()
)];
}
return [sprintf(
"Casting class %s to string is deprecated.:\n%s",
$method->getDeclaringClass()->getName(),
$description
)];
}
}

View File

@@ -0,0 +1,79 @@
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Deprecations;
use PhpParser\Node;
use PhpParser\Node\Stmt\TraitUse;
use PHPStan\Analyser\Scope;
use PHPStan\Broker\ClassNotFoundException;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Rule;
use PHPStan\ShouldNotHappenException;
use function sprintf;
/**
* @implements Rule<TraitUse>
*/
class UsageOfDeprecatedTraitRule implements Rule
{
/** @var ReflectionProvider */
private $reflectionProvider;
public function __construct(ReflectionProvider $reflectionProvider)
{
$this->reflectionProvider = $reflectionProvider;
}
public function getNodeType(): string
{
return TraitUse::class;
}
public function processNode(Node $node, Scope $scope): array
{
if (DeprecatedScopeHelper::isScopeDeprecated($scope)) {
return [];
}
$classReflection = $scope->getClassReflection();
if ($classReflection === null) {
throw new ShouldNotHappenException();
}
$errors = [];
$className = $classReflection->getName();
foreach ($node->traits as $traitNameNode) {
$traitName = (string) $traitNameNode;
try {
$trait = $this->reflectionProvider->getClass($traitName);
if (!$trait->isDeprecated()) {
continue;
}
$description = $trait->getDeprecatedDescription();
if ($description === null) {
$errors[] = sprintf(
'Usage of deprecated trait %s in class %s.',
$traitName,
$className
);
} else {
$errors[] = sprintf(
"Usage of deprecated trait %s in class %s:\n%s",
$traitName,
$className,
$description
);
}
} catch (ClassNotFoundException $e) {
continue;
}
}
return $errors;
}
}

View File

@@ -11,6 +11,8 @@ $DEBUG_ALL = true;
$PRINT_ALL = true;
$DB_DEBUG = true;
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
ob_start();
// basic class test file
@@ -37,18 +39,17 @@ $log = new CoreLibs\Debug\Logging([
]);
// db config with logger
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
$locale = \CoreLibs\Language\GetLocale::setLocale();
$l10n = new \CoreLibs\Language\L10n(
$locale['locale'],
$locale['domain'],
$locale['path'],
SITE_LOCALE,
SITE_DOMAIN,
BASE . INCLUDES . LOCALE,
SITE_ENCODING
);
$backend = new CoreLibs\Admin\Backend(
$db,
$log,
$session,
$l10n,
$locale,
DEFAULT_ACL_LEVEL
);
use CoreLibs\Debug\Support;

View File

@@ -11,6 +11,8 @@ $DEBUG_ALL = true;
$PRINT_ALL = true;
$DB_DEBUG = true;
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
ob_start();
// basic class test file

View File

@@ -11,6 +11,8 @@ $DEBUG_ALL = true;
$PRINT_ALL = true;
$DB_DEBUG = true;
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
ob_start();
// basic class test file
define('USE_DATABASE', false);

View File

@@ -11,6 +11,8 @@ $DEBUG_ALL = true;
$PRINT_ALL = true;
$DB_DEBUG = true;
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
ob_start();
// basic class test file

View File

@@ -11,6 +11,8 @@ $DEBUG_ALL = true;
$PRINT_ALL = true;
$DB_DEBUG = true;
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
ob_start();
// basic class test file

View File

@@ -11,6 +11,8 @@ $DEBUG_ALL = true;
$PRINT_ALL = true;
$DB_DEBUG = true;
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
ob_start();
// basic class test file

View File

@@ -11,6 +11,8 @@ $DEBUG_ALL = true;
$PRINT_ALL = true;
$DB_DEBUG = true;
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
ob_start();
// basic class test file

View File

@@ -11,6 +11,8 @@ $DEBUG_ALL = true;
$PRINT_ALL = true;
$DB_DEBUG = true;
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
ob_start();
// basic class test file

View File

@@ -13,6 +13,8 @@ $PRINT_ALL = true;
$ECHO_ALL = true;
$DB_DEBUG = true;
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
ob_start();
// basic class test file

View File

@@ -11,6 +11,8 @@ $DEBUG_ALL = true;
$PRINT_ALL = true;
$DB_DEBUG = true;
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
ob_start();
// basic class test file

View File

@@ -13,6 +13,8 @@ $PRINT_ALL = false;
$ECHO_ALL = true;
$DB_DEBUG = true;
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
ob_start();
// basic class test file

View File

@@ -11,6 +11,8 @@ $DEBUG_ALL = true;
$PRINT_ALL = true;
$DB_DEBUG = true;
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
ob_start();
// basic class test file

View File

@@ -11,6 +11,8 @@ $DEBUG_ALL = true;
$PRINT_ALL = true;
$DB_DEBUG = true;
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
ob_start();
// basic class test file

View File

@@ -11,6 +11,8 @@ $DEBUG_ALL = true;
$PRINT_ALL = true;
$DB_DEBUG = true;
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
ob_start();
// basic class test file

View File

@@ -11,6 +11,8 @@ $DEBUG_ALL = true;
$PRINT_ALL = true;
$DB_DEBUG = true;
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
ob_start();
// basic class test file

View File

@@ -11,6 +11,8 @@ $DEBUG_ALL = true;
$PRINT_ALL = true;
$DB_DEBUG = true;
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
ob_start();
// basic class test file

View File

@@ -11,6 +11,8 @@ $DEBUG_ALL = true;
$PRINT_ALL = true;
$DB_DEBUG = true;
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
ob_start();
// basic class test file

View File

@@ -11,6 +11,8 @@ $DEBUG_ALL = true;
$PRINT_ALL = true;
$DB_DEBUG = true;
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
ob_start();
// basic class test file

View File

@@ -11,6 +11,8 @@ $DEBUG_ALL = true;
$PRINT_ALL = true;
$DB_DEBUG = true;
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
ob_start();
// basic class test file
@@ -54,20 +56,52 @@ echo "<br><b>AUTO DETECT</b><br>";
// DEPRECATED
// $get_locale = Language\GetLocale::setLocale();
// print "[AUTO, DEPRECATED]: " . Support::printAr($get_locale) . "<br>";
$get_locale = Language\GetLocale::setLocale(
$get_locale = Language\GetLocale::setLocaleFromSession(
SITE_LOCALE,
str_replace('/', '', CONTENT_PATH),
null,
'',
BASE . INCLUDES . LOCALE
);
print "[NAMED CONSTANTS OUTSIDE]: " . Support::printAr($get_locale) . "<br>";
$get_locale = Language\GetLocale::setLocale(
$get_locale = Language\GetLocale::setLocaleFromSession(
'en',
'foo',
'ISO-8895',
BASE . INCLUDES . LOCALE
);
print "[OVERRIDE]: " . Support::printAr($get_locale) . "<br>";
// must set session vars for setLangFromSession
// DEFAULT_LOCALE
// DEFAULT_DOMAIN
// DEFAULT_CHARSET (should be set from DEFAULT_LOCALE)
// LOCALE_PATH
$_SESSION['DEFAULT_LOCALE'] = 'ja_JP.UTF-8';
$_SESSION['DEFAULT_CHARSET'] = 'UTF-8';
$_SESSION['DEFAULT_DOMAIN'] = 'admin';
$_SESSION['LOCALE_PATH'] = BASE . INCLUDES . LOCALE;
$get_locale = Language\GetLocale::setLocaleFromSession(
SITE_LOCALE,
SITE_DOMAIN,
SITE_ENCODING,
BASE . INCLUDES . LOCALE
);
print "[SESSION SET]: " . Support::printAr($get_locale) . "<br>";
// must set session vars for setLangFromSession
// DEFAULT_LOCALE
// DEFAULT_DOMAIN
// DEFAULT_CHARSET (should be set from DEFAULT_LOCALE)
// LOCALE_PATH
$_SESSION['DEFAULT_LOCALE'] = '00000#####';
$_SESSION['DEFAULT_CHARSET'] = '';
$_SESSION['DEFAULT_DOMAIN'] = 'admin';
$_SESSION['LOCALE_PATH'] = BASE . INCLUDES . LOCALE;
$get_locale = Language\GetLocale::setLocaleFromSession(
SITE_LOCALE,
SITE_DOMAIN,
SITE_ENCODING,
BASE . INCLUDES . LOCALE
);
print "[SESSION SET INVALID]: " . Support::printAr($get_locale) . "<br>";
// try to load non existing
echo "<br><b>NEW TYPE</b><br>";
@@ -79,8 +113,8 @@ $domain = 'admin';
$encoding = 'UTF-8';
$path = BASE . INCLUDES . LOCALE;
// load direct
$l = new L10n($lang, $domain, $path);
echo "*<br>";
echo "* <b>NEW CLASS SET</b><br>";
$l = new L10n($lang, $domain, $path, $encoding);
echo "LANGUAGE WANT/SET: " . $lang . '/' . $l->getLocale() . "<br>";
echo "DOMAIN WANT/SET: " . $domain . '/' . $l->getDomain() . "<br>";
echo "LANGUAGE FILE: " . $l->getMoFile() . "<br>";
@@ -105,10 +139,11 @@ for ($n = 0; $n <= 3; $n++) {
echo "CONTEXT MULTI TEST $n: " . $single_string . "/" . $multi_string . " => "
. $l->__np($context, $single_string, $multi_string, $n) . "<br>";
}
echo "LOCALE: " . Support::printAr($l->getLocaleAsArray()) . "<br>";
// change domain
$domain = 'frontend';
echo "* <b>CHANGE DOMAIN $domain</b><br>";
$l->getTranslator('', $domain, $path);
echo "*<br>";
echo "LANGUAGE WANT/SET: " . $lang . '/' . $l->getLocale() . "<br>";
echo "DOMAIN WANT/SET: " . $domain . '/' . $l->getDomain() . "<br>";
echo "LANGUAGE FILE: " . $l->getMoFile() . "<br>";
@@ -118,11 +153,12 @@ echo "BASE PATH: " . $l->getBaseLocalePath() . "<br>";
echo "LOAD ERROR: " . $l->getLoadError() . "<br>";
echo "INPUT TEST: " . $string . " => " . $l->__($string) . "<br>";
echo "TROUGH LOAD: " . $l->getTranslatorClass()->gettext($string) . "<br>";
echo "LOCALE: " . Support::printAr($l->getLocaleAsArray()) . "<br>";
// change language short type
$lang = 'en';
$domain = 'admin';
echo "* <b>CHANGE LANG $lang AND DOMAIN $domain</b><br>";
$l->getTranslator($lang, $domain, $path);
echo "*<br>";
echo "LANGUAGE WANT/SET: " . $lang . '/' . $l->getLocale() . "<br>";
echo "DOMAIN WANT/SET: " . $domain . '/' . $l->getDomain() . "<br>";
echo "LANGUAGE FILE: " . $l->getMoFile() . "<br>";
@@ -132,10 +168,24 @@ echo "BASE PATH: " . $l->getBaseLocalePath() . "<br>";
echo "LOAD ERROR: " . $l->getLoadError() . "<br>";
echo "INPUT TEST: " . $string . " => " . $l->__($string) . "<br>";
echo "TROUGH LOAD: " . $l->getTranslatorClass()->gettext($string) . "<br>";
echo "LOCALE: " . Support::printAr($l->getLocaleAsArray()) . "<br>";
$encoding = 'SJIS';
echo "* <b>SET DIFFERENT CHARSET $encoding</b><br>";
$l->getTranslator($lang, $domain, $path, $encoding);
echo "LANGUAGE WANT/SET: " . $lang . '/' . $l->getLocale() . "<br>";
echo "DOMAIN WANT/SET: " . $domain . '/' . $l->getDomain() . "<br>";
echo "LANGUAGE FILE: " . $l->getMoFile() . "<br>";
echo "CONTENT PATH: " . $l->getBaseContentPath() . "<br>";
echo "DOMAIN PATH: " . $l->getTextDomain($domain) . "<br>";
echo "BASE PATH: " . $l->getBaseLocalePath() . "<br>";
echo "LOAD ERROR: " . $l->getLoadError() . "<br>";
echo "INPUT TEST: " . $string . " => " . $l->__($string) . "<br>";
echo "TROUGH LOAD: " . $l->getTranslatorClass()->gettext($string) . "<br>";
echo "LOCALE: " . Support::printAr($l->getLocaleAsArray()) . "<br>";
// chang to wrong language
$lang = 'tr';
echo "* <b>CHANGE NOT FOUND LANG $lang</b><br>";
$l->getTranslator($lang, $domain, $path);
echo "*<br>";
echo "LANGUAGE WANT/SET: " . $lang . '/' . $l->getLocale() . "<br>";
echo "DOMAIN WANT/SET: " . $domain . '/' . $l->getDomain() . "<br>";
echo "LANGUAGE FILE: " . $l->getMoFile() . "<br>";
@@ -145,6 +195,25 @@ echo "BASE PATH: " . $l->getBaseLocalePath() . "<br>";
echo "LOAD ERROR: " . $l->getLoadError() . "<br>";
echo "INPUT TEST: " . $string . " => " . $l->__($string) . "<br>";
echo "TROUGH LOAD: " . $l->getTranslatorClass()->gettext($string) . "<br>";
echo "LOCALE: " . Support::printAr($l->getLocaleAsArray()) . "<br>";
// set different encoding
$lang = 'ja';
$domain = 'admin';
$encoding = 'SJIS';
echo "* <b>CLASS NEW LAUNCH: $lang / $encoding</b><br>";
$path = BASE . INCLUDES . LOCALE;
// load direct
$l = new L10n($lang, $domain, $path, $encoding);
echo "LOCALE: " . Support::printAr($l->getLocaleAsArray()) . "<br>";
// lang with full set
$lang = 'ja_JP.UTF-8';
$domain = 'admin';
$encoding = 'SJIS';
echo "* <b>CLASS NEW LAUNCH: $lang / $encoding</b><br>";
$path = BASE . INCLUDES . LOCALE;
// load direct
$l = new L10n($lang, $domain, $path, $encoding);
echo "LOCALE: " . Support::printAr($l->getLocaleAsArray()) . "<br>";
$lang = 'en';
$domain = 'admin';
@@ -156,8 +225,10 @@ L10n::getInstance()->setDomain($domain);
echo "SET DOMAIN: " . L10n::getInstance()->getDomain() . "<br>";
L10n::getInstance()->setTextDomain($domain, $path);
echo "SET TEXT DOMAIN: " . L10n::getInstance()->getTextDomain($domain) . "<br>";
// L10n::getInstance()->setOverrideEncoding('SJIS');
// null call __bind_textdomain_codeset
echo "INPUT TEST: " . $string . " => " . L10n::getInstance()->getTranslator()->gettext($string) . "<br>";
echo "LOCALE: " . Support::printAr(L10n::getInstance()->getLocaleAsArray()) . "<br>";
echo "<br><b>FUNCTIONS</b><br>";
// real statisc test

View File

@@ -11,6 +11,8 @@ $DEBUG_ALL = true;
$PRINT_ALL = true;
$DB_DEBUG = true;
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
ob_start();
// basic class test file
@@ -40,9 +42,10 @@ $login = new CoreLibs\ACL\Login(
[
'auto_login' => false,
'default_acl_level' => DEFAULT_ACL_LEVEL,
'logout_target' => LOGOUT_TARGET,
'logout_target' => '',
'site_locale' => SITE_LOCALE,
'site_domain' => SITE_DOMAIN,
'site_encoding' => SITE_ENCODING,
'locale_path' => BASE . INCLUDES . LOCALE,
]
);
@@ -63,6 +66,7 @@ echo "MIN ACCESS PAGE: " . ($login->loginCheckAccessPage('admin') ? 'OK' : 'BAD'
echo "ACL: " . \CoreLibs\Debug\Support::printAr($login->loginGetAcl()) . "<br>";
echo "ACL (MIN): " . \CoreLibs\Debug\Support::printAr($login->loginGetAcl()['min'] ?? []) . "<br>";
echo "LOCALE: " . \CoreLibs\Debug\Support::printAr($login->loginGetLocale()) . "<br>";
// error message
print $log->printErrorMsg();

View File

@@ -11,6 +11,8 @@ $DEBUG_ALL = true;
$PRINT_ALL = true;
$DB_DEBUG = true;
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
ob_start();
// basic class test file

View File

@@ -11,6 +11,8 @@ $DEBUG_ALL = true;
$PRINT_ALL = true;
$DB_DEBUG = true;
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
ob_start();
// basic class test file

View File

@@ -11,6 +11,8 @@ $DEBUG_ALL = true;
$PRINT_ALL = true;
$DB_DEBUG = true;
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
ob_start();
// basic class test file

View File

@@ -11,6 +11,8 @@ $DEBUG_ALL = true;
$PRINT_ALL = true;
$DB_DEBUG = true;
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
ob_start();
// basic class test file
@@ -63,22 +65,20 @@ $log = new CoreLibs\Debug\Logging([
'echo_all' => $ECHO_ALL,
'print_all' => $PRINT_ALL,
]);
$locale = CoreLibs\Language\GetLocale::setLocale(
SITE_LOCALE,
SITE_DOMAIN,
SITE_ENCODING,
BASE . INCLUDES . LOCALE
);
$l10n = new CoreLibs\Language\L10n(
SITE_LOCALE,
SITE_DOMAIN,
BASE . INCLUDES . LOCALE
BASE . INCLUDES . LOCALE,
SITE_ENCODING
);
$form = new CoreLibs\Output\Form\Generate(
DB_CONFIG,
$log,
$l10n,
$locale,
[
'base' => 10,
'admin' => 0
],
table_arrays: $table_arrays
);

View File

@@ -11,6 +11,8 @@ $DEBUG_ALL = true;
$PRINT_ALL = true;
$DB_DEBUG = true;
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
ob_start();
// basic class test file

View File

@@ -11,6 +11,7 @@ $DEBUG_ALL = true;
$PRINT_ALL = true;
$DB_DEBUG = true;
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
ob_start();
@@ -35,17 +36,6 @@ $log = new CoreLibs\Debug\Logging([
'print_all' => $PRINT_ALL,
]);
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
$locale = \CoreLibs\Language\GetLocale::setLocale(
SITE_LOCALE,
SITE_DOMAIN,
SITE_ENCODING,
BASE . INCLUDES . LOCALE
);
$l10n = new \CoreLibs\Language\L10n(
$locale['locale'],
$locale['domain'],
$locale['path'],
);
$login = new CoreLibs\ACL\Login(
$db,
$log,
@@ -53,18 +43,26 @@ $login = new CoreLibs\ACL\Login(
[
'auto_login' => true,
'default_acl_level' => DEFAULT_ACL_LEVEL,
'logout_target' => LOGOUT_TARGET,
'site_locale' => $locale['locale'],
'site_domain' => $locale['domain'],
'locale_path' => $locale['path'],
'logout_target' => '',
'site_locale' => SITE_LOCALE,
'site_domain' => SITE_DOMAIN,
'site_encoding' => SITE_ENCODING,
'locale_path' => BASE . INCLUDES . LOCALE,
]
);
$locale = $login->loginGetLocale();
$l10n = new \CoreLibs\Language\L10n(
$locale['locale'],
$locale['domain'],
$locale['path'],
$locale['encoding'],
);
$backend = new CoreLibs\Admin\Backend(
$db,
$log,
$session,
$l10n,
$locale,
DEFAULT_ACL_LEVEL
);
$backend->db->dbInfo(true);

View File

@@ -11,6 +11,8 @@ $DEBUG_ALL = true;
$PRINT_ALL = true;
$DB_DEBUG = true;
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
ob_start();
// basic class test file

View File

@@ -11,6 +11,8 @@ $DEBUG_ALL = true;
$PRINT_ALL = true;
$DB_DEBUG = true;
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
ob_start();
// basic class test file

View File

@@ -11,6 +11,8 @@ $DEBUG_ALL = true;
$PRINT_ALL = true;
$DB_DEBUG = true;
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
ob_start();
// basic class test file

View File

@@ -7,6 +7,8 @@ $DEBUG_ALL = true;
$PRINT_ALL = true;
$DB_DEBUG = true;
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
/**
* Undocumented function
*

View File

@@ -7,6 +7,8 @@ $DEBUG_ALL = true;
$PRINT_ALL = true;
$DB_DEBUG = true;
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
/**
* Undocumented function
*

View File

@@ -11,6 +11,8 @@ $DEBUG_ALL = true;
$PRINT_ALL = true;
$DB_DEBUG = true;
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
ob_start();
// basic class test file
@@ -33,18 +35,25 @@ $log = new CoreLibs\Debug\Logging([
'echo_all' => $ECHO_ALL,
'print_all' => $PRINT_ALL,
]);
$locale = \CoreLibs\Language\GetLocale::setLocale();
$l10n = new \CoreLibs\Language\L10n(
$locale['locale'],
$locale['domain'],
$locale['path'],
SITE_LOCALE,
SITE_DOMAIN,
BASE . INCLUDES . LOCALE,
SITE_ENCODING
);
$smarty = new CoreLibs\Template\SmartyExtend(
$l10n,
$locale,
CACHE_ID,
COMPILE_ID,
);
$adm = new CoreLibs\Admin\Backend(
new CoreLibs\DB\IO(DB_CONFIG, $log),
$log,
new CoreLibs\Create\Session(EDIT_SESSION_NAME),
$l10n,
80
);
$adm->DATA['adm_set'] = 'SET from admin class';
$PAGE_NAME = 'TEST CLASS: SMARTY';
print "<!DOCTYPE html>";
@@ -134,16 +143,21 @@ $smarty->DATA['checkbox_test_pos_selected'] = ['0', '-1'];
$smarty->setSmartyVarsAdmin(
BASE . TEMPLATES_C,
BASE . CACHE,
CSS,
FONT,
JS,
DEFAULT_ENCODING,
G_TITLE,
ADMIN_STYLESHEET,
ADMIN_JAVASCRIPT,
PAGE_WIDTH
[
'compile_dir' => BASE . TEMPLATES_C,
'cache_dir' => BASE . CACHE,
'js' => JS,
'css' => CSS,
'font' => FONT,
'g_title' => G_TITLE,
'default_encoding' => DEFAULT_ENCODING,
'admin_stylesheet' => ADMIN_STYLESHEET,
'admin_javascript' => ADMIN_JAVASCRIPT,
'page_width' => PAGE_WIDTH,
'content_path' => CONTENT_PATH,
'user_name' => $_SESSION['USER_NAME'] ?? ''
],
$adm
);
// error message

View File

@@ -7,6 +7,8 @@ $DEBUG_ALL = true;
$PRINT_ALL = true;
$DB_DEBUG = true;
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
ob_start();
// basic class test file

View File

@@ -11,6 +11,8 @@ $DEBUG_ALL = true;
$PRINT_ALL = true;
$DB_DEBUG = true;
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
ob_start();
// basic class test file

View File

@@ -11,6 +11,8 @@ $DEBUG_ALL = true;
$PRINT_ALL = true;
$DB_DEBUG = true;
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
ob_start();
// basic class test file

View File

@@ -11,6 +11,8 @@ $DEBUG_ALL = true;
$PRINT_ALL = true;
$DB_DEBUG = true;
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
ob_start();
// basic class test file

View File

@@ -11,6 +11,8 @@ $DEBUG_ALL = true;
$PRINT_ALL = true;
$DB_DEBUG = true;
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
ob_start();
// basic class test file

View File

@@ -11,9 +11,7 @@ $DEBUG_ALL = 1;
$PRINT_ALL = 1;
$DB_DEBUG = 1;
if ($DEBUG_ALL) {
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
}
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
ob_start();
@@ -31,9 +29,9 @@ $log = new CoreLibs\Debug\Logging([
// add file date
'print_file_date' => true,
// set debug and print flags
'debug_all' => $DEBUG_ALL ?? false,
'debug_all' => $DEBUG_ALL,
'echo_all' => $ECHO_ALL ?? false,
'print_all' => $PRINT_ALL ?? false,
'print_all' => $PRINT_ALL,
]);
$PAGE_NAME = 'TEST CLASS: CONFIG DIRECT SUB';
@@ -47,7 +45,7 @@ print "DIR: " . DIR . "<br>";
print "BASE: " . BASE . "<br>";
print "ROOT: " . ROOT . "<br>";
print "BASE NAME: " . BASE_NAME . "<br>";
echo "Config path prefix: " . $CONFIG_PATH_PREFIX . "<br>";
echo "Config path prefix: " . ($CONFIG_PATH_PREFIX ?? '') . "<br>";
print "DB Name: " . DB_CONFIG_NAME . "<br>";
print "DB Config: " . \CoreLibs\Debug\Support::printAr(DB_CONFIG) . "<br>";

View File

@@ -1 +1 @@
../../4dev/tests/dotenv/test.env
../../4dev/tests/Get/dotenv/test.env

View File

@@ -9,9 +9,7 @@ $DEBUG_ALL = true;
$PRINT_ALL = true;
$DB_DEBUG = true;
if ($DEBUG_ALL) {
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
}
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
ob_start();
@@ -31,17 +29,31 @@ $log = new CoreLibs\Debug\Logging([
// add file date
'print_file_date' => true,
// set debug and print flags
'debug_all' => $DEBUG_ALL ?? false,
'debug_all' => $DEBUG_ALL,
'echo_all' => $ECHO_ALL ?? false,
'print_all' => $PRINT_ALL ?? false,
'print_all' => $PRINT_ALL,
]);
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
$login = new CoreLibs\ACL\Login($db, $log, $session);
$locale = \CoreLibs\Language\GetLocale::setLocale();
$login = new CoreLibs\ACL\Login(
$db,
$log,
$session,
[
'auto_login' => true,
'default_acl_level' => DEFAULT_ACL_LEVEL,
'logout_target' => '',
'site_locale' => SITE_LOCALE,
'site_domain' => SITE_DOMAIN,
'site_encoding' => SITE_ENCODING,
'locale_path' => BASE . INCLUDES . LOCALE,
]
);
$locale = $login->loginGetLocale();
$l10n = new \CoreLibs\Language\L10n(
$locale['locale'],
$locale['domain'],
$locale['path'],
$locale['encoding']
);
print "<!DOCTYPE html>";

View File

@@ -74,20 +74,35 @@ if (
// db config with logger
$db = new \CoreLibs\DB\IO(DB_CONFIG, $log);
// login & page access check
$login = new \CoreLibs\ACL\Login($db, $log, $session);
$login = new \CoreLibs\ACL\Login(
$db,
$log,
$session,
[
'auto_login' => true,
'default_acl_level' => DEFAULT_ACL_LEVEL,
'logout_target' => '',
'site_locale' => SITE_LOCALE,
'site_domain' => SITE_DOMAIN,
'site_encoding' => SITE_ENCODING,
'locale_path' => BASE . INCLUDES . LOCALE,
]
);
// lang, path, domain
// pre auto detect language after login
$locale = \CoreLibs\Language\GetLocale::setLocale();
$locale = $login->loginGetLocale();
// set lang and pass to smarty/backend
$l10n = new \CoreLibs\Language\L10n(
$locale['locale'],
$locale['domain'],
$locale['path'],
$locale['encoding']
);
// create smarty object
$smarty = new \CoreLibs\Template\SmartyExtend($l10n, $locale);
$smarty = new \CoreLibs\Template\SmartyExtend($l10n, CACHE_ID, COMPILE_ID);
// create new Backend class with db and loger attached
$cms = new \CoreLibs\Admin\Backend($db, $log, $session, $l10n, $locale);
$cms = new \CoreLibs\Admin\Backend($db, $log, $session, $l10n, DEFAULT_ACL_LEVEL);
// the menu show flag (what menu to show)
$cms->menu_show_flag = 'main';
// db info

View File

@@ -43,23 +43,46 @@ $log = new CoreLibs\Debug\Logging([
// db connection
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
// login page
$login = new CoreLibs\ACL\Login($db, $log, $session);
$login = new CoreLibs\ACL\Login(
$db,
$log,
$session,
[
'auto_login' => true,
'default_acl_level' => DEFAULT_ACL_LEVEL,
'logout_target' => '',
'site_locale' => SITE_LOCALE,
'site_domain' => SITE_DOMAIN,
'site_encoding' => SITE_ENCODING,
'locale_path' => BASE . INCLUDES . LOCALE,
]
);
// space for setting special debug flags
// $login->log->setLogLevelAll('debug', true);
// lang, path, domain
// pre auto detect language after login
$locale = \CoreLibs\Language\GetLocale::setLocale();
$locale = $login->loginGetLocale();
// set lang and pass to smarty/backend
$l10n = new \CoreLibs\Language\L10n(
$locale['locale'],
$locale['domain'],
$locale['path'],
$locale['encoding']
);
// flush and start
ob_end_flush();
// init smarty and form class
$edit_base = new CoreLibs\Admin\EditBase(DB_CONFIG, $log, $l10n, $locale);
$edit_base = new CoreLibs\Admin\EditBase(
DB_CONFIG,
$log,
$l10n,
$login,
[
'cache_id' => CACHE_ID,
'compile_id' => COMPILE_ID
]
);
// creates edit pages and runs actions
$edit_base->editBaseRun(
BASE . INCLUDES . TEMPLATES . CONTENT_PATH,

View File

@@ -39,7 +39,7 @@ function pop(theURL, winName, features) {
<form method="post">
<tr>
<td bgcolor="{$HEADER_COLOR}" class="normal">
Hello <b>{$USER_NAME|upper}</b> [{$EUID}] from the group <b>{$GROUP_NAME}</b> with Access Level <b>{$GROUP_LEVEL}</b>
Hello <b>{$USER_NAME|upper}</b> [{$EUID}] from the group <b>{$GROUP_NAME}</b> with Access Level <b>{$ACCESS_LEVEL}</b>
</td>
<td bgcolor="{$HEADER_COLOR}" class="normal" align="right">
<input type="submit" name="login_logout" value="Logout">

View File

@@ -1,6 +1,9 @@
<div>
SMARTY_TEST: {$SMARTY_TEST}
</div>
<div>
MERGE DATA: {$adm_set}
</div>
<div {popup width="250" caption="Info" text="Text block<br>Control"} style="border: 1px solid black; margin: 5px 0 5px 0; padding: 5px;">
POPUP HERE (hover mouse)
</div>

View File

@@ -196,7 +196,12 @@ class Login
/** @var array<string,mixed> options */
private $options = [];
/** @var array<string,string> locale options: locale, domain, encoding (opt), path */
private $locale = [];
private $locale = [
'locale' => '',
'domain' => '',
'encoding' => '',
'path' => '',
];
/** @var \CoreLibs\Debug\Logging logger */
public $log;
@@ -555,12 +560,12 @@ class Login
);
// set path
$options['locale_path'] = BASE . INCLUDES . LOCALE;
$_SESSION['LOCALE_PATH'] = $options['locale_path'];
}
$_SESSION['LOCALE_PATH'] = $options['locale_path'];
// LANG: LOCALE
if (empty($options['site_locale'])) {
trigger_error(
'loginMainCall: SITE_LOCALE or DEFAULT_LOCALE should not be used',
'loginMainCall: SITE_LOCALE should not be used',
E_USER_DEPRECATED
);
$options['site_locale'] = defined('SITE_LOCALE') && !empty(SITE_LOCALE) ?
@@ -580,7 +585,6 @@ class Login
);
// set domain
$options['site_domain'] = SITE_DOMAIN;
$_SESSION['DEFAULT_DOMAIN'] = $options['site_domain'];
} elseif (
defined('CONTENT_PATH')
) {
@@ -592,6 +596,16 @@ class Login
$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;
@@ -905,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']
@@ -1195,7 +1210,8 @@ class Login
}
/**
* set locale and load mo translator
* set locale
* if invalid, set to empty string
*
* @return void
*/
@@ -1204,22 +1220,52 @@ class Login
// ** LANGUAGE SET AFTER LOGIN **
// set the locale
if (
!empty($_SESSION['DEFAULT_LOCALE'])
!empty($_SESSION['DEFAULT_LOCALE']) &&
preg_match("/^[-A-Za-z0-9_.@]+$/", $_SESSION['DEFAULT_LOCALE'])
) {
$locale = $_SESSION['DEFAULT_LOCALE'];
} else {
} 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' => $this->options['site_domain'],
'path' => $this->options['locale_path'],
'domain' => $domain,
'encoding' => $encoding,
'path' => $path,
];
$this->l = new \CoreLibs\Language\L10n(
$this->locale['locale'],
$this->locale['domain'],
$this->locale['path']
);
}
/**
@@ -1824,6 +1870,12 @@ EOM;
$this->loginLogoutUser();
// ** LANGUAGE SET AFTER LOGIN **
$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();
@@ -2396,6 +2448,53 @@ EOM;
): 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__

View File

@@ -121,14 +121,13 @@ 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
@@ -142,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();

View File

@@ -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";
@@ -272,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']) {
@@ -574,7 +575,7 @@ class EditBase
$set_admin_stylesheet = $set_admin_stylesheet ?? ADMIN_STYLESHEET;
$set_default_encoding = $set_default_encoding ?? DEFAULT_ENCODING;
$set_css = $set_css ?? LAYOUT . CSS;
$set_css = $set_js ?? LAYOUT . JS;
$set_js = $set_js ?? LAYOUT . JS;
$set_root = $set_root ?? ROOT;
$set_content_path = $set_content_path ?? CONTENT_PATH;

View File

@@ -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
);

View File

@@ -251,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
);
@@ -274,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

View File

@@ -21,6 +21,7 @@ class GetLocale
* @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,
@@ -28,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) ||
@@ -137,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__

View File

@@ -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,15 +77,18 @@ 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
// New: path must be set too, or we fall through
@@ -103,7 +112,7 @@ class L10n
$path = $domain;
$domain = $_domain;
}
$this->getTranslator($locale, $domain, $path);
$this->getTranslator($locale, $domain, $path, $encoding);
}
}
@@ -137,13 +146,15 @@ class L10n
*
* @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 $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)) {
@@ -153,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;
@@ -186,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;
@@ -202,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])) {
@@ -225,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;
@@ -258,21 +277,36 @@ 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|null, domain: string, encoding: string|null, path: string}
* @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']
'lang' => ($locale['lang'] ?? '')
. (!empty($locale['country']) ? '_' . $locale['country'] : ''),
'lang_short' => $locale['lang'] ?? '',
'domain' => $this->getDomain(),
'encoding' => $locale['charset'],
'encoding' => $this->getEncoding(),
'path' => $this->getBaseLocalePath(),
];
}
@@ -515,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
*

View File

@@ -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;
@@ -308,7 +310,8 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
* @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,string> $locale locale array from ::setLocale
* @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
@@ -318,7 +321,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
array $db_config,
\CoreLibs\Debug\Logging $log,
\CoreLibs\Language\L10n $l10n,
array $locale,
array $login_acl,
?array $table_arrays = null,
) {
// init logger if not set
@@ -327,19 +330,19 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
$this->log->setLogPer('class', false);
// init the language class
$this->l = $l10n;
// legacy lang vars set
// 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(
@@ -377,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'];

View File

@@ -160,13 +160,11 @@ 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,
?string $cache_id = null,
?string $compile_id = null
) {
@@ -192,13 +190,12 @@ class SmartyExtend extends \Smarty
// 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();
@@ -455,92 +452,95 @@ 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
* @param array<string,string> $options list with the following value:
* compile_dir :BASE . TEMPLATES_C
* cache_dir :BASE . CACHE
* js :JS
* css :CSS
* font :FONT
* default_encoding :DEFAULT_ENCODING
* g_title :G_TITLE
* stylesheet :STYLESHEET
* javascript :JAVASCRIPT
* @param array<string,mixed> $smarty_data array of three keys
* that hold smarty set strings
* HEADER, DATA, DEBUG_DATA
* @return void
*/
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
array $options,
array $smarty_data
): void {
$this->setSmartyVars(
false,
$cms,
$compile_dir,
$cache_dir,
$set_js,
$set_css,
$set_font,
$set_default_encoding,
$set_g_title,
$smarty_data,
null,
$options['compile_dir'] ?? null,
$options['cache_dir'] ?? null,
$options['js'] ?? null,
$options['css'] ?? null,
$options['font'] ?? null,
$options['default_encoding'] ?? null,
$options['g_title'] ?? null,
null,
null,
null,
$set_stylesheet,
$set_javascript
null,
null,
$options['stylesheet'] ?? null,
$options['javascript'] ?? null
);
}
/**
* 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 array<string,string> $options list with the following value:
* compile_dir :BASE . TEMPLATES_C
* cache_dir :BASE . CACHE
* js :JS
* css :CSS
* font :FONT
* default_encoding :DEFAULT_ENCODING
* g_title :G_TITLE
* admin_stylesheet :ADMIN_STYLESHEET
* admin_javascript :ADMIN_JAVASCRIPT
* page_width :PAGE_WIDTH
* content_path :CONTENT_PATH
* user_name :_SESSION['USER_NAME']
* @param \CoreLibs\Admin\Backend|null $cms Optinal Admin Backend for
* smarty variables merge
* @return void
*/
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,
array $options,
?\CoreLibs\Admin\Backend $cms = null
): void {
// if we have cms data, check for array blocks and build
$smarty_data = [];
if ($cms !== null) {
$smarty_data = [
'HEADER' => $cms->HEADER,
'DATA' => $cms->DATA,
'DEBUG_DATA' => $cms->DEBUG_DATA
];
}
$this->setSmartyVars(
true,
$smarty_data,
$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,
$options['compile_dir'] ?? null,
$options['cache_dir'] ?? null,
$options['js'] ?? null,
$options['css'] ?? null,
$options['font'] ?? null,
$options['g_title'] ?? null,
$options['default_encoding'] ?? null,
$options['admin_stylesheet'] ?? null,
$options['admin_javascript'] ?? null,
$options['page_width'] ?? null,
$options['content_path'] ?? null,
$options['user_name'] ?? null,
null,
null
);
@@ -552,6 +552,7 @@ class SmartyExtend extends \Smarty
*
* @param bool $admin_call default false
* will set admin only variables
* @param array<string,mixed> $smarty_data smarty data to merge
* @param \CoreLibs\Admin\Backend|null $cms Optinal Admin Backend for
* smarty variables merge
* @param string|null $compile_dir BASE . TEMPLATES_C
@@ -564,12 +565,15 @@ class SmartyExtend extends \Smarty
* @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_content_path CONTENT_PATH (only if $cms set and admin)
* @param string|null $set_user_name _SESSION['USER_NAME']
* @param string|null $set_stylesheet STYLESHEET
* @param string|null $set_javascript JAVASCRIPT
* @return void
*/
private function setSmartyVars(
bool $admin_call,
array $smarty_data = [],
?\CoreLibs\Admin\Backend $cms = null,
?string $compile_dir = null,
?string $cache_dir = null,
@@ -581,8 +585,10 @@ class SmartyExtend extends \Smarty
?string $set_admin_stylesheet = null,
?string $set_admin_javascript = null,
?string $set_page_width = null,
?string $set_content_path = null,
?string $set_user_name = null,
?string $set_stylesheet = null,
?string $set_javascript = null
?string $set_javascript = null,
): void {
// trigger deprecation
if (
@@ -597,7 +603,8 @@ class SmartyExtend extends \Smarty
$admin_call === true && (
$set_admin_stylesheet === null ||
$set_admin_javascript === null ||
$set_page_width === null
$set_page_width === null ||
$set_user_name === null
)
) ||
(
@@ -605,6 +612,9 @@ class SmartyExtend extends \Smarty
$set_stylesheet === null ||
$set_javascript === null
)
) ||
(
$admin_call === true && $cms !== null && $set_content_path === null
)
) {
/** @deprecated setSmartyVars call without parameters */
@@ -624,24 +634,12 @@ class SmartyExtend extends \Smarty
$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_content_path = $set_content_path ?? CONTENT_PATH;
$set_stylesheet = $set_stylesheet ?? STYLESHEET;
$set_javascript = $set_javascript ?? JAVASCRIPT;
// 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);
}
$set_user_name = $set_user_name ?? $_SESSION['USER_NAME'] ?? '';
// merge additional smarty data
$this->mergeCmsSmartyVars($smarty_data);
// trigger flags
$this->HEADER['USE_PROTOTYPE'] = $this->USE_PROTOTYPE;
@@ -683,12 +681,27 @@ class SmartyExtend extends \Smarty
$this->DATA['FORM_ACTION'] = $this->FORM_ACTION;
// special for admin
if ($admin_call === true) {
// 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;
// set ACL extra show
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
$this->DATA['nav_menu'] = $cms->adbTopMenu();
$this->DATA['nav_menu'] = $cms->adbTopMenu(
$set_content_path
);
$this->DATA['nav_menu_count'] = count($this->DATA['nav_menu']);
// messages = ['msg' =>, 'class' => 'error/warning/...']
$this->DATA['messages'] = $cms->messages;
@@ -734,7 +747,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;
@@ -748,18 +761,18 @@ class SmartyExtend extends \Smarty
/**
* merge outside object HEADER/DATA/DEBUG_DATA vars into the smarty class
*
* @param \CoreLibs\Admin\Backend $cms object that has header/data/debug_data
* @param array<string,mixed> $smarty_data array that has header/data/debug_data
* @return void
*/
public function mergeCmsSmartyVars(\CoreLibs\Admin\Backend $cms): void
public function mergeCmsSmartyVars(array $smarty_data): void
{
// array merge HEADER, DATA, DEBUG DATA
foreach (['HEADER', 'DATA', 'DEBUG_DATA'] as $ext_smarty) {
if (
isset($cms->{$ext_smarty}) &&
is_array($cms->{$ext_smarty})
isset($smarty_data[$ext_smarty]) &&
is_array($smarty_data[$ext_smarty])
) {
$this->{$ext_smarty} = array_merge($this->{$ext_smarty}, $cms->{$ext_smarty});
$this->{$ext_smarty} = array_merge($this->{$ext_smarty}, $smarty_data[$ext_smarty]);
}
}
}