PluginProbe
Elementor Website Builder – more than just a page builder / 3.27.4
Elementor Website Builder – more than just a page builder v3.27.4
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / vendor_prefixed / php-di / invoker / src / Reflection / CallableReflection.php

CallableReflection.php in Elementor Website Builder – more than just a page builder 3.27.4, at vendor_prefixed/php-di/invoker/src/Reflection/CallableReflection.php

48 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare (strict_types=1);
4 namespace ElementorDeps\Invoker\Reflection;
5
6 use Closure;
7 use ElementorDeps\Invoker\Exception\NotCallableException;
8 use ReflectionException;
9 use ReflectionFunction;
10 use ReflectionFunctionAbstract;
11 use ReflectionMethod;
12 /**
13 * Create a reflection object from a callable or a callable-like.
14 *
15 * @internal
16 */
17 class CallableReflection
18 {
19 /**
20 * @param callable|array|string $callable Can be a callable or a callable-like.
21 * @throws NotCallableException|ReflectionException
22 */
23 public static function create($callable) : ReflectionFunctionAbstract
24 {
25 // Closure
26 if ($callable instanceof Closure) {
27 return new ReflectionFunction($callable);
28 }
29 // Array callable
30 if (\is_array($callable)) {
31 [$class, $method] = $callable;
32 if (!\method_exists($class, $method)) {
33 throw NotCallableException::fromInvalidCallable($callable);
34 }
35 return new ReflectionMethod($class, $method);
36 }
37 // Callable object (i.e. implementing __invoke())
38 if (\is_object($callable) && \method_exists($callable, '__invoke')) {
39 return new ReflectionMethod($callable, '__invoke');
40 }
41 // Standard function
42 if (\is_string($callable) && \function_exists($callable)) {
43 return new ReflectionFunction($callable);
44 }
45 throw new NotCallableException(\sprintf('%s is not a callable', \is_string($callable) ? $callable : 'Instance of ' . \get_class($callable)));
46 }
47 }
48