32 $original = $callable;
34 $callable = $this->resolveCallable($callable);
35 if (!is_callable($callable)) {
38 $msg =
"Handler for $description is not callable: " . $this->describeCallable($original);
44 $use_object = $this->acceptsObject($callable);
83 $callback = $this->resolveCallable($callback);
84 return $callback && is_callable($callback);
95 if (is_string($callable)) {
96 if (
false !== strpos($callable,
'::')) {
97 $callable = explode(
'::', $callable);
100 return new \ReflectionFunction($callable);
103 if (is_array($callable)) {
104 return new \ReflectionMethod($callable[0], $callable[1]);
106 if ($callable instanceof \
Closure) {
107 return new \ReflectionFunction($callable);
109 if (is_object($callable)) {
110 return new \ReflectionMethod($callable,
'__invoke');
113 throw new \InvalidArgumentException(
'invalid $callable');
123 private function resolveCallable($callable) {
124 if (is_callable($callable)) {
128 if (is_string($callable)
129 && preg_match(DiContainer::CLASS_NAME_PATTERN_53, $callable)
130 && class_exists($callable)) {
132 $callable =
new $callable;
135 return is_callable($callable) ? $callable : null;
145 private function acceptsObject($callable) {
147 $type = (string) $this->getParamTypeForCallable($callable);
148 if (0 === strpos(
$type,
'Elgg\\')) {
165 $params = $this->getReflector($callable)->getParameters();
170 return $this->getType(
$params[$index]);
180 public function getType(\ReflectionParameter $param) {
184 if (method_exists($param,
'getType')
185 && (
$type = $param->getType())
186 &&
$type->isBuiltin()) {
187 return (
string)
$type;
191 if ($param->isArray()) {
196 if ($param->isCallable()) {
201 if (preg_match(
'~\[\s<\w+?>\s([\S]+)~s', (
string) $param, $m)) {
202 if ($m[1][0] !==
'$') {
220 if (is_string($callable)) {
223 if (is_array($callable) && array_keys($callable) === [0, 1] && is_string($callable[1])) {
224 if (is_string($callable[0])) {
225 return "{$callable[0]}::{$callable[1]}";
227 return "(" . get_class($callable[0]) .
")->{$callable[1]}";
229 if ($callable instanceof \
Closure) {
230 $ref = new \ReflectionFunction($callable);
231 $file = $ref->getFileName();
232 $line = $ref->getStartLine();
234 if ($file_root && 0 === strpos(
$file, $file_root)) {
238 return "(Closure {$file}:{$line})";
240 if (is_object($callable)) {
241 return "(" . get_class($callable) .
")->__invoke()";
243 return print_r($callable,
true);
254 if (is_string($callable)) {
257 if (is_array($callable)) {
258 if (is_string($callable[0])) {
259 return "{$callable[0]}::{$callable[1]}";
261 return get_class($callable[0]) .
"::{$callable[1]}";
263 if ($callable instanceof \
Closure) {
266 if (is_object($callable)) {
267 return get_class($callable) .
"::__invoke";
isCallable($callback)
Test is callback is callable Unlike is_callable(), this function also tests invokable classes...
if(!$item instanceof ElggRiverItem) $object
if(!array_key_exists($filename, $text_files)) $file
$params
Saves global plugin settings.
Helpers for providing callable-based APIs.
getParamTypeForCallable($callable, $index=0)
Get the type for a parameter of a callable.
$args
Some servers don't allow PHP to check the rewrite, so try via AJAX.
getType(\ReflectionParameter $param)
Get the type of a parameter.
getReflector($callable)
Get the reflection interface for a callable.
The object passed to invokable class name handlers.
The object passed to invokable class name handlers.
fingerprintCallable($callable)
Get a string that uniquely identifies a callback across requests (for caching)
describeCallable($callable, $file_root= '')
Get a string description of a callback.
call($callable, $object, $args)
Call the handler with the hook/event object.
_elgg_services()
Get the global service provider.
if(elgg_view_exists("plugins/{$plugin_id}/settings")) $description