ILIAS
trunk Revision v11.0_alpha-2638-g80c1d007f79
◀ ilDoc Overview
ProblemBuilder.php
Go to the documentation of this file.
1
<?php
2
19
declare(strict_types=1);
20
21
namespace
ILIAS\Refinery
;
22
23
use
Closure
;
24
25
trait
ProblemBuilder
26
{
30
abstract
protected
function
getError();
31
32
final
public
function
withProblemBuilder
(callable $builder): self
33
{
34
$clone = clone $this;
35
$clone->error = $builder;
36
return
$clone;
37
}
38
39
final
public
function
getErrorMessage
($value): string
40
{
41
$error
= $this->getError();
42
if
(!is_callable(
$error
)) {
43
return
$error
;
44
}
45
$lng_closure = $this->
getLngClosure
();
46
return
$error
($lng_closure, $value);
47
}
48
52
final
protected
function
getLngClosure
():
Closure
53
{
54
return
function
(
string
$lang_var, ...$args):
string
{
55
$error
= $this->
lng
->txt($lang_var);
56
57
if
($args === []) {
58
return
$error
;
59
}
60
61
return
sprintf(
$error
, ...
array_map
(
function
($v) {
62
if
(is_array($v)) {
63
return
"array"
;
64
} elseif (is_null($v)) {
65
return
"null"
;
66
} elseif (is_object($v) && !method_exists($v,
"__toString"
)) {
67
return
get_class($v);
68
}
69
return
$v;
70
}, $args));
71
};
72
}
73
}
ILIAS\Refinery
Definition:
ByTrying.php:21
array_map
Closure
ILIAS\Repository\lng
lng()
Definition:
trait.GlobalDICDomainServices.php:61
ProblemBuilder
ILIAS\Refinery\getLngClosure
getLngClosure()
Get the closure to be passed to the error-function that does i18n and sprintf.
Definition:
ProblemBuilder.php:52
ILIAS\Refinery\withProblemBuilder
withProblemBuilder(callable $builder)
Definition:
ProblemBuilder.php:32
ILIAS\Refinery\getErrorMessage
getErrorMessage($value)
Definition:
ProblemBuilder.php:39
ILIAS\$error
ilErrorHandling $error
Definition:
class.ilias.php:69
components
ILIAS
Refinery
src
ProblemBuilder.php
Generated on Sun Aug 31 2025 23:03:32 for ILIAS by
1.8.13 (using
Doxyfile
)