19 protected const CLASS_NAME_PATTERN_53 =
'/^(\\\\?[a-z_\x7f-\xff][a-z0-9_\x7f-\xff]*)+$/i';
31 $original = $callable;
33 $callable = $this->resolveCallable($callable);
34 if (!is_callable($callable)) {
41 $type = $object::class;
47 $this->
getLogger()->warning(
"Handler for {$description} is not callable: " . $this->describeCallable($original));
81 $callback = $this->resolveCallable($callback);
82 return $callback && is_callable($callback);
93 if (is_callable($callable)) {
97 if (is_string($callable)
98 &&
preg_match(self::CLASS_NAME_PATTERN_53, $callable)
99 && class_exists($callable)) {
100 $callable =
new $callable;
103 return is_callable($callable) ? $callable : null;
116 if (is_string($callable)) {
120 if (is_array($callable) && array_keys($callable) === [0, 1] && is_string($callable[1])) {
121 if (is_string($callable[0])) {
122 return "{$callable[0]}::{$callable[1]}";
125 return '(' . get_class($callable[0]) .
")->{$callable[1]}";
128 if ($callable instanceof \Closure) {
129 $ref = new \ReflectionFunction($callable);
130 $file = $ref->getFileName();
131 $line = $ref->getStartLine();
133 if ($file_root && str_starts_with($file, $file_root)) {
137 return "(Closure {$file}:{$line})";
140 if (is_object($callable)) {
141 return '(' . get_class($callable) .
')->__invoke()';
144 return print_r($callable,
true);
isCallable($callback)
Test is callback is callable Unlike is_callable(), this function also tests invokable classes...
Helpers for providing callable-based APIs.
$args
Some servers don't allow PHP to check the rewrite, so try via AJAX.
trait Loggable
Enables adding a logger.
resolveCallable($callable)
Resolve a callable, possibly instantiating a class name.
describeCallable($callable, $file_root= '')
Get a string description of a callback.
call($callable, $object, $args)
Call the handler with the event object.
getLogger()
Returns logger.
if($email instanceof\Elgg\Email) $object
Models an event passed to event handlers.