Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3767733
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/omnitools/src/Reflection/CallableElement.php b/omnitools/src/Reflection/CallableElement.php
index 3a99449..9e10b41 100644
--- a/omnitools/src/Reflection/CallableElement.php
+++ b/omnitools/src/Reflection/CallableElement.php
@@ -1,75 +1,75 @@
<?php
declare(strict_types=1);
namespace Keruald\OmniTools\Reflection;
use Closure;
-use http\Exception\InvalidArgumentException;
+use InvalidArgumentException;
use ReflectionException;
use ReflectionFunction;
use ReflectionFunctionAbstract;
use ReflectionMethod;
class CallableElement {
private ReflectionFunctionAbstract $callable;
/**
* @throws ReflectionException
*/
public function __construct (callable $callable) {
$this->callable = self::getReflectionFunction($callable);
}
/**
* @throws ReflectionException
*/
private static function getReflectionFunction (callable $callable)
: ReflectionFunctionAbstract {
///
/// Functions
///
if ($callable instanceof Closure) {
return new ReflectionFunction($callable);
}
///
/// Objets and methods
///
if (is_array($callable)) {
return new ReflectionMethod($callable[0], $callable[1]);
}
if (is_object($callable)) {
// If __invoke() doesn't exist, the objet isn't a callable.
// Calling this method with such object would throw a TypeError
// before reaching this par of the code, so it is safe to assume
// we can correctly call it.
return new ReflectionMethod([$callable, '__invoke']);
}
///
/// Hybrid cases
///
if (is_string($callable)) {
if (!str_contains($callable, "::")) {
return new ReflectionFunction($callable);
}
return new ReflectionMethod($callable);
}
throw new InvalidArgumentException(
"Callable not recognized: " . gettype($callable)
);
}
public function countArguments () : int {
return $this->callable->getNumberOfParameters();
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Nov 25, 03:11 (20 h, 56 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2259418
Default Alt Text
(2 KB)
Attached To
Mode
rKERUALD Keruald libraries development repository
Attached
Detach File
Event Timeline
Log In to Comment