Remove deprecated classes and methods, deprecate all named constants
All named constants used inside classes have been deprecated and must now be set from method calls, class init, etc
This commit is contained in:
@@ -1,127 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* deprecated function calls
|
||||
* Language\Encoding::__mbMimeEncode -> Convert\MimeEncode::__mbMimeEncode
|
||||
* Langauge\Encoding::checkConvertEncoding -> Check\Encoding::checkConvertEncoding
|
||||
* Langauge\Encoding::setErrorChar -> Check\Encoding::setErrorChar
|
||||
* Langauge\Encoding::getErrorChar -> Check\Encoding::getErrorChar
|
||||
* Langauge\Encoding::convertEncoding -> Convert\Encoding::convertEncoding
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CoreLibs\Language;
|
||||
|
||||
class Encoding
|
||||
{
|
||||
/**
|
||||
* wrapper function for mb mime convert
|
||||
* for correct conversion with long strings
|
||||
*
|
||||
* @param string $string string to encode
|
||||
* @param string $encoding target encoding
|
||||
* @param string $line_break default line break is \r\n
|
||||
* @return string encoded string
|
||||
* @deprecated Use \CoreLibs\Convert\MimeEncode::__mbMimeEncode();
|
||||
*/
|
||||
public static function __mbMimeEncode(
|
||||
string $string,
|
||||
string $encoding,
|
||||
string $line_break = "\r\n"
|
||||
): string {
|
||||
return \CoreLibs\Convert\MimeEncode::__mbMimeEncode($string, $encoding, $line_break);
|
||||
}
|
||||
|
||||
/**
|
||||
* set error char
|
||||
*
|
||||
* @param string|int|null $string The character to use to represent
|
||||
* error chars
|
||||
* "long" for long, "none" for none
|
||||
* or a valid code point in int
|
||||
* like 0x2234 (8756, ∴)
|
||||
* default character is ? (63)
|
||||
* if null is set then "none"
|
||||
* @return void
|
||||
* @deprecated Use \CoreLibs\Check\Encoding::setErrorChar();
|
||||
*/
|
||||
public static function setErrorChar(string|int|null $string): void
|
||||
{
|
||||
\CoreLibs\Check\Encoding::setErrorChar($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* get the current set error character
|
||||
*
|
||||
* @param bool $return_substitute_func if set to true return the set
|
||||
* character from the php function
|
||||
* directly
|
||||
* @return string|int Set error character
|
||||
* @deprecated Use \CoreLibs\Check\Encoding::getErrorChar();
|
||||
*/
|
||||
public static function getErrorChar(bool $return_substitute_func = false): string|int
|
||||
{
|
||||
return \CoreLibs\Check\Encoding::getErrorChar($return_substitute_func);
|
||||
}
|
||||
|
||||
/**
|
||||
* test if a string can be safely convert between encodings.
|
||||
* mostly utf8 to shift jis
|
||||
* the default compare has a possibility of failure, especially with windows
|
||||
* it is recommended to the following in the script which uses this method:
|
||||
* mb_substitute_character(0x2234);
|
||||
* $class->mb_error_char = '∴';
|
||||
* if check to Shift JIS
|
||||
* if check to ISO-2022-JP
|
||||
* if check to ISO-2022-JP-MS
|
||||
* set three dots (∴) as wrong character for correct convert error detect
|
||||
* (this char is used, because it is one of the least used ones)
|
||||
*
|
||||
* @param string $string string to test
|
||||
* @param string $from_encoding encoding of string to test
|
||||
* @param string $to_encoding target encoding
|
||||
* @return array<string>|false false if no error or
|
||||
* array with failed characters
|
||||
* @deprecated Use \CoreLibs\Check\Encoding::checkConvertEncoding();
|
||||
*/
|
||||
public static function checkConvertEncoding(
|
||||
string $string,
|
||||
string $from_encoding,
|
||||
string $to_encoding
|
||||
): array|false {
|
||||
return \CoreLibs\Check\Encoding::checkConvertEncoding($string, $from_encoding, $to_encoding);
|
||||
}
|
||||
|
||||
/**
|
||||
* detects the source encoding of the string and if doesn't match
|
||||
* to the given target encoding it convert is
|
||||
* if source encoding is set and auto check is true (default) a second
|
||||
* check is done so that the source string encoding actually matches
|
||||
* will be skipped if source encoding detection is ascii
|
||||
*
|
||||
* @param string $string string to convert
|
||||
* @param string $to_encoding target encoding
|
||||
* @param string $source_encoding optional source encoding, will try to auto detect
|
||||
* @param bool $auto_check default true, if source encoding is set
|
||||
* check that the source is actually matching
|
||||
* to what we sav the source is
|
||||
* @return string encoding converted string
|
||||
* @deprecated Use \CoreLibs\Convert\Encoding::convertEncoding();
|
||||
*/
|
||||
public static function convertEncoding(
|
||||
string $string,
|
||||
string $to_encoding,
|
||||
string $source_encoding = '',
|
||||
bool $auto_check = true
|
||||
): string {
|
||||
return \CoreLibs\Convert\Encoding::convertEncoding(
|
||||
$string,
|
||||
$to_encoding,
|
||||
$source_encoding,
|
||||
$auto_check
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -14,6 +14,7 @@ class GetLocale
|
||||
/**
|
||||
* returns locale, lang, domain, encoding, path
|
||||
* from either parameter set or from sessions/config variables
|
||||
* NOTE: named constant usage is deprecated and will be removed in future
|
||||
*
|
||||
* @param string|null $locale override auto detect
|
||||
* @param string|null $domain override domain
|
||||
@@ -36,6 +37,10 @@ class GetLocale
|
||||
// parse from session (logged in)
|
||||
$locale = $_SESSION['DEFAULT_LOCALE'];
|
||||
} else {
|
||||
trigger_error(
|
||||
'setLocale: Unset $locale or unset SESSION locale is deprecated',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
// else parse from site locale
|
||||
$locale = defined('SITE_LOCALE') && !empty(SITE_LOCALE) ?
|
||||
SITE_LOCALE :
|
||||
@@ -50,8 +55,16 @@ class GetLocale
|
||||
empty($domain) ||
|
||||
!preg_match("/^\w+$/", $domain)
|
||||
) {
|
||||
// if no domain is set, fall back to content path
|
||||
$domain = str_replace('/', '', CONTENT_PATH);
|
||||
if (!empty($_SESSION['DEFAULT_DOMAIN'])) {
|
||||
$domain = $_SESSION['DEFAULT_DOMAIN'];
|
||||
} else {
|
||||
trigger_error(
|
||||
'setLocale: Unset $domain is deprecated',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
// if no domain is set, fall back to content path
|
||||
$domain = str_replace(DIRECTORY_SEPARATOR, '', CONTENT_PATH);
|
||||
}
|
||||
}
|
||||
// check that override encoding matches locale encoding
|
||||
// if locale encoding is set
|
||||
@@ -71,6 +84,10 @@ class GetLocale
|
||||
// else set from session
|
||||
$encoding = $_SESSION['DEFAULT_CHARSET'];
|
||||
} else {
|
||||
trigger_error(
|
||||
'setLocale: Short $locale with unset $encoding or unset SESSION encoding is deprecated',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
// else set from site encoding
|
||||
$encoding = defined('SITE_ENCODING') && !empty(SITE_ENCODING) ?
|
||||
SITE_ENCODING :
|
||||
@@ -85,7 +102,15 @@ class GetLocale
|
||||
empty($path) ||
|
||||
!is_dir($path)
|
||||
) {
|
||||
$path = BASE . INCLUDES . LOCALE;
|
||||
if (!empty($_SESSION['LOCALE_PATH'])) {
|
||||
$path = $_SESSION['LOCALE_PATH'];
|
||||
} else {
|
||||
trigger_error(
|
||||
'setLocale: Unset $path is deprecated',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
$path = BASE . INCLUDES . LOCALE;
|
||||
}
|
||||
}
|
||||
// extract lang & country from locale string, else set to en
|
||||
if (
|
||||
|
||||
@@ -82,10 +82,23 @@ class L10n
|
||||
string $path = ''
|
||||
) {
|
||||
// auto load language only if at least locale and domain is set
|
||||
if (!empty($locale) && !empty($domain)) {
|
||||
// New: path must be set too, or we fall through
|
||||
if (!empty($locale) && !empty($domain) && empty($path)) {
|
||||
/** @deprecated if locale and domain are set, path must be set too */
|
||||
trigger_error(
|
||||
'Empty path parameter is no longer allowed if locale and domain are set',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
}
|
||||
if (!empty($locale) && !empty($domain) && !empty($path)) {
|
||||
// check hack if domain and path is switched
|
||||
// Note this can be removed in future versions
|
||||
if (strstr($domain, DIRECTORY_SEPARATOR) !== false) {
|
||||
/** @deprecated domain must be 2nd and path must be third parameter */
|
||||
trigger_error(
|
||||
'L10n constructor parameter switch is no longer supported. domain is 2nd, path is 3rd parameter',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
$_domain = $path;
|
||||
$path = $domain;
|
||||
$domain = $_domain;
|
||||
@@ -122,9 +135,9 @@ class L10n
|
||||
/**
|
||||
* loads the mo file base on path, locale and domain set
|
||||
*
|
||||
* @param string $locale language name (optional), fallback is en
|
||||
* @param string $domain override CONTENT_PATH . $encoding name for mo file
|
||||
* @param string $path path, if empty fallback on default internal path
|
||||
* @param string $locale language name, if not set, try previous set
|
||||
* @param string $domain set name for mo file, if not set, try previous set
|
||||
* @param string $path path, if not set try to get from paths array, else self
|
||||
* @return GetTextReader the main gettext reader object
|
||||
*/
|
||||
public function getTranslator(
|
||||
@@ -160,6 +173,11 @@ class L10n
|
||||
} elseif (
|
||||
defined('BASE') && defined('INCLUDES') && defined('LOCALE')
|
||||
) {
|
||||
/** @deprecated Do not use this anymore, define path on class load */
|
||||
trigger_error(
|
||||
'parameter $path must be set. Setting via BASE, INCLUDES and LOCALE constants is deprecated',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
// set fallback base path if constant set
|
||||
$this->base_locale_path = BASE . INCLUDES . LOCALE;
|
||||
} else {
|
||||
@@ -240,6 +258,25 @@ class L10n
|
||||
return $this->l10n;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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}
|
||||
*/
|
||||
public function getLocaleAsArray(): array
|
||||
{
|
||||
$locale = L10n::parseLocale($this->getLocale());
|
||||
return [
|
||||
'locale' => $this->getLocale(),
|
||||
'lang' => $locale['lang']
|
||||
. (!empty($locale['country']) ? '_' . $locale['country'] : ''),
|
||||
'domain' => $this->getDomain(),
|
||||
'encoding' => $locale['charset'],
|
||||
'path' => $this->getBaseLocalePath(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* parse the locale string for further processing
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user