Update ErrorMsg with optional target_style string for one style

Applied to master or to target style
This commit is contained in:
Clemens Schwaighofer
2023-09-15 18:22:38 +09:00
parent de0ed058ca
commit fe459aec80
7 changed files with 70 additions and 50 deletions

10
composer.lock generated
View File

@@ -1180,16 +1180,16 @@
},
{
"name": "phpstan/phpstan",
"version": "1.10.33",
"version": "1.10.34",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan.git",
"reference": "03b1cf9f814ba0863c4e9affea49a4d1ed9a2ed1"
"reference": "7f806b6f1403e6914c778140e2ba07c293cb4901"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/03b1cf9f814ba0863c4e9affea49a4d1ed9a2ed1",
"reference": "03b1cf9f814ba0863c4e9affea49a4d1ed9a2ed1",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/7f806b6f1403e6914c778140e2ba07c293cb4901",
"reference": "7f806b6f1403e6914c778140e2ba07c293cb4901",
"shasum": ""
},
"require": {
@@ -1238,7 +1238,7 @@
"type": "tidelift"
}
],
"time": "2023-09-04T12:20:53+00:00"
"time": "2023-09-13T09:49:47+00:00"
},
{
"name": "phpstan/phpstan-deprecation-rules",

View File

@@ -1179,17 +1179,17 @@
},
{
"name": "phpstan/phpstan",
"version": "1.10.33",
"version_normalized": "1.10.33.0",
"version": "1.10.34",
"version_normalized": "1.10.34.0",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan.git",
"reference": "03b1cf9f814ba0863c4e9affea49a4d1ed9a2ed1"
"reference": "7f806b6f1403e6914c778140e2ba07c293cb4901"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/03b1cf9f814ba0863c4e9affea49a4d1ed9a2ed1",
"reference": "03b1cf9f814ba0863c4e9affea49a4d1ed9a2ed1",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/7f806b6f1403e6914c778140e2ba07c293cb4901",
"reference": "7f806b6f1403e6914c778140e2ba07c293cb4901",
"shasum": ""
},
"require": {
@@ -1198,7 +1198,7 @@
"conflict": {
"phpstan/phpstan-shim": "*"
},
"time": "2023-09-04T12:20:53+00:00",
"time": "2023-09-13T09:49:47+00:00",
"bin": [
"phpstan",
"phpstan.phar"

View File

@@ -191,9 +191,9 @@
'dev_requirement' => true,
),
'phpstan/phpstan' => array(
'pretty_version' => '1.10.33',
'version' => '1.10.33.0',
'reference' => '03b1cf9f814ba0863c4e9affea49a4d1ed9a2ed1',
'pretty_version' => '1.10.34',
'version' => '1.10.34.0',
'reference' => '7f806b6f1403e6914c778140e2ba07c293cb4901',
'type' => 'library',
'install_path' => __DIR__ . '/../phpstan/phpstan',
'aliases' => array(),

Binary file not shown.

View File

@@ -1,16 +1,16 @@
-----BEGIN PGP SIGNATURE-----
iQIzBAABCgAdFiEEynwsejDI6OEnSoR2UcZzBf/C5cAFAmT1y40ACgkQUcZzBf/C
5cDm6Q//VupQizxW3TICxhwzMDz05+nI8d72mn5vd94Niat90L1wPVHSZ9eBQSs3
xMGVKJufB/3tQp6rviYk0aFnTFsKYkgwQYSDk1P9D7VrcJdpB461P3FT4MGsRk8E
SSo55EuMGpiVvgoKbiPXeYV76yEpSMpelbKDNTm7iglLFVQKAnTv17aQv/UdBoYk
t/dOS0ovoWmjkj9837EA5o2FAkhA5njlpvRs1l5Jt/tZsZtJTcDjPYfP5kIGbOwp
V6xKYW7JYht+O0si3GxGmWGOE4VbOHLpUDpLMmVu53njjeGAIkPgX53TqBRbAbVL
FjpDSZYC08lE4WblqXZEP6aKqVqthQ4LcGfyZDvuWDgPGHf86cTvfHQvtqRY45kU
GhFDz6IfVlwBrfpc4hKfbhF6Q3Txm8ZSSfiVHim8JFjCqO+jn4qmaXGaOqbNUfv9
fLgg7Bbnu1tZdMv6JJP5Kmk0x5wp4m2vFxDd6NGfm7uz9182/LtXOjqQ0MuGfL+j
Dw53dl+WdUpr4Xk1m1GkYwDF9zLIwBB7dEghz6c4nbiGvh31MUk6N+4N2eGkjtWW
B1PPORcpxxXSlhtftCwsJVxRFodQu9cmI0qmw4EUEipFrkFuT7a1rNF48NFyfRMh
PcB/UcUHMCL7owhfQEEuPvqIPJS4saesCdFeJAM0MKuXB1nNGTQ=
=HpaR
iQIzBAABCgAdFiEEynwsejDI6OEnSoR2UcZzBf/C5cAFAmUBhZwACgkQUcZzBf/C
5cDAIA/+JOxOdWCg6b1+/Bs4Opm7cmILJzh3Rw1366MzXFHJhe2n7exemzTE3X2E
0HTjVVWoE0MpTt6knBgb+dulXTGm+yzJNIRLnCJFhsSdwUcxNAZMPozliZszGMcC
HhGC1Ya7RU5d9WEg/lCAKRjNgSeY8VTRRfa49m6TQPQwGinXBNpH6q665feziUX5
NB+rBMaWUDKp6GelPVrezEfME+SMfT66hW31n5m5paTwT+khk2Cenub5xXBUyXtz
saxSayOShlUPN8kZKOjS/L/FPnOApGwcKxkX2kMK0qDs8YQFYHibNgnyhrEOBRD1
UV9kBiU1+LUuxDcya8f0qo/gk6QN7Y/ywnIY3kTkqTYchCAAO+osu1amLYlInBSu
r0LtQQ8+/llQ/bP0XS6cC6247J1fxO9xYMMmKVBfJrul3Wi6ETRI5WIdEQTSc2Z+
rE00JY2X/vxJijUyGZ88+QDX3z7vGyaQJZiXq1XyjmBYw6w8UlxhGZcGGDIbTsb7
lACLR/t4hgtE69QXW+L4P2ngU0agk5XXojg/+r+CnCWD/TdKcvs1WTn4TyuMZOLa
2XF3h9/H0XMfE5LPlNJmb4YRjYjcNvPQwmGI4dmUMCJuTpjHUnpFXfswu4xgsaYV
xq756DVfrRyG9PyXFfJZ66P7jt5+wisrVsWh/X3nX69P0ruwwss=
=aOCq
-----END PGP SIGNATURE-----

View File

@@ -40,6 +40,7 @@ print "NU: " . ml::fromValue(100)->name . "<br>";
print "NU: " . ml::fromValue(1000)->name . "<br>";
$em->setErrorMsg('123', 'error', 'msg this is bad, not logged');
$em->setErrorMsg('123', 'error', 'msg this is bad, not logged', 'target-id', 'other-style');
$em->setErrorMsg('123', 'error', 'msg this is bad, logged', log_error:true);
$em->setErrorMsg('1000', 'info', 'This is good');
$em->setErrorMsg('9999', 'abort', 'BAD: This is critical (abort)');

View File

@@ -15,7 +15,7 @@ use CoreLibs\Logging\Logger\MessageLevel;
class ErrorMessage
{
/** @var array<int,array{id:string,level:string,str:string,target:string,highlight:string[]}> */
/** @var array<int,array{id:string,level:string,str:string,target:string,target_style:string,highlight:string[]}> */
private array $error_str = [];
/** @var \CoreLibs\Logging\Logging $log */
public \CoreLibs\Logging\Logging $log;
@@ -52,23 +52,28 @@ class ErrorMessage
* not set: unkown, will be logged as "emergency"
* target/highlight: id target name for frontend where to attach this message
* highlight is a list of other target points to highlight
* for highlight targets css names are $level without a prefix and should be
* nested in the target element "input .error { ... }"
* target_style: if not set uses 'error-' $level as css style. applies to targets or main only
*
* @param string $error_id Any internal error ID for this error
* @param string $level Error level in ok/info/warn/error
* @param string $str Error message (out)
* @param string $target alternate attachment point for this error message
* @param array<string> $highlight Any additional error data as error OR
* highlight points for field highlights
* @param string|null $message If abort/crash, non localized $str
* @param array<mixed> $context Additionl info for abort/crash messages
* @param bool|null $log_error [=null] log level 'error' to error, if null use global,
* else set for this call only
* @param string $error_id Any internal error ID for this error
* @param string $level Error level in ok/info/warn/error
* @param string $str Error message (out)
* @param string $target alternate attachment point for this error message
* @param string $target_style Alternate color style for the error message
* @param array<string> $highlight Any additional error data as error OR
* highlight points for field highlights
* @param string|null $message If abort/crash, non localized $str
* @param array<mixed> $context Additionl info for abort/crash messages
* @param bool|null $log_error [=null] log level 'error' to error, if null use global,
* else set for this call only
*/
public function setErrorMsg(
string $error_id,
string $level,
string $str,
string $target = '',
string $target_style = '',
array $highlight = [],
?string $message = null,
array $context = [],
@@ -88,6 +93,7 @@ class ErrorMessage
'level' => $level,
'str' => $str,
'target' => $target,
'target_style' => $target_style,
'highlight' => $highlight,
];
// write to log for abort/crash
@@ -126,28 +132,40 @@ class ErrorMessage
* Note, the parameter order is different and does not need an error id
* This is for backend alerts
*
* @param string $level error level (ok/warn/info/error)
* @param string $str error string
* @param string|null $error_id optional error id for precise error lookup
* @param string $target Alternate id name for output target on frontend
* @param array<string> $highlight Any additional error data as error OR
* highlight points for field highlights
* @param string|null $message If abort/crash, non localized $str
* @param array<mixed> $context Additionl info for abort/crash messages
* @param bool|null $log_error [=null] log level 'error' to error, if null use global,
* else set for this call only
* @param string $level error level (ok/warn/info/error)
* @param string $str error string
* @param string|null $error_id optional error id for precise error lookup
* @param string $target Alternate id name for output target on frontend
* @param string $target_style Alternate color style for the error message
* @param array<string> $highlight Any additional error data as error OR
* highlight points for field highlights
* @param string|null $message If abort/crash, non localized $str
* @param array<mixed> $context Additionl info for abort/crash messages
* @param bool|null $log_error [=null] log level 'error' to error, if null use global,
* else set for this call only
*/
public function setMessage(
string $level,
string $str,
?string $error_id = null,
string $target = '',
string $target_style = '',
array $highlight = [],
?string $message = null,
array $context = [],
?bool $log_error = null,
): void {
$this->setErrorMsg($error_id ?? '', $level, $str, $target, $highlight, $message, $context, $log_error);
$this->setErrorMsg(
$error_id ?? '',
$level,
$str,
$target,
$target_style,
$highlight,
$message,
$context,
$log_error
);
}
// *********************************************************************
@@ -178,7 +196,7 @@ class ErrorMessage
* Gets the LAST entry in the array list.
* If nothing found returns empty array set
*
* @return array{id:string,level:string,str:string,target:string,highlight:string[]} Error block
* @return array{id:string,level:string,str:string,target:string,target:string,highlight:string[]} Error block
*/
public function getLastErrorMsg(): array
{
@@ -187,6 +205,7 @@ class ErrorMessage
'str' => '',
'id' => '',
'target' => '',
'target_string' => '',
'highlight' => [],
];
}