aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2017-08-29 15:26:24 +0200
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2017-08-29 15:26:24 +0200
commitdff3ae964675f6773c1d0bcc73fa0e5844920593 (patch)
treed5eefc250585102714acc769a7b33c38cb77c33c
parent725b01f9e69c55983e249359a1b7c04555e4ec75 (diff)
downloadConsistency-dff3ae964675f6773c1d0bcc73fa0e5844920593.zip
Consistency-dff3ae964675f6773c1d0bcc73fa0e5844920593.tar.gz
Consistency-dff3ae964675f6773c1d0bcc73fa0e5844920593.tar.bz2
chore(path) Move code into the `Source` directory.
-rw-r--r--Source/Autoloader.php (renamed from Autoloader.php)0
-rw-r--r--Source/Consistency.php (renamed from Consistency.php)0
-rw-r--r--Source/Exception.php (renamed from Exception.php)0
-rw-r--r--Source/Prelude.php (renamed from Prelude.php)0
-rw-r--r--Source/Xcallable.php (renamed from Xcallable.php)80
-rw-r--r--composer.json6
6 files changed, 46 insertions, 40 deletions
diff --git a/Autoloader.php b/Source/Autoloader.php
index ad5e604..ad5e604 100644
--- a/Autoloader.php
+++ b/Source/Autoloader.php
diff --git a/Consistency.php b/Source/Consistency.php
index e082311..e082311 100644
--- a/Consistency.php
+++ b/Source/Consistency.php
diff --git a/Exception.php b/Source/Exception.php
index 40baaff..40baaff 100644
--- a/Exception.php
+++ b/Source/Exception.php
diff --git a/Prelude.php b/Source/Prelude.php
index e40b604..e40b604 100644
--- a/Prelude.php
+++ b/Source/Prelude.php
diff --git a/Xcallable.php b/Source/Xcallable.php
index bb7917d..ee94803 100644
--- a/Xcallable.php
+++ b/Source/Xcallable.php
@@ -40,36 +40,34 @@ namespace Hoa\Consistency;
use Hoa\Event;
use Hoa\Stream;
+use Reflector;
+use ReflectionClass;
+use ReflectionFunction;
+use ReflectionMethod;
+use ReflectionObject;
/**
- * Class Hoa\Consistency\Xcallable.
- *
- * Build a callable object, i.e. function, class::method, object->method or
- * closure, they all have the same behaviour. This callable is an extension of
+ * Build a callable object, i.e. `function`, `class::method`, `object->method` or
+ * closure. They all have the same behaviour. This callable is an extension of
* native PHP callable (aka callback) to integrate Hoa's structures.
- *
- * @license New BSD License
*/
class Xcallable
{
/**
- * Callback, with the PHP format.
- *
- * @var mixed
+ * Callback with the PHP format.
*/
protected $_callback = null;
/**
* Callable hash.
- *
- * @var string
*/
protected $_hash = null;
/**
- * Build a callback.
+ * Allocates a xcallable based on a callback.
+ *
* Accepted forms:
* * `'function'`,
* * `'class::method'`,
@@ -80,8 +78,21 @@ class Xcallable
* * `['class', 'method']`,
* * `[$object, 'method']`.
*
- * @param mixed $call First callable part.
- * @param mixed $able Second callable part (if needed).
+ * # Examples
+ *
+ * ```php
+ * $toUpper = new Hoa\Consistency\Xcallable('strtoupper');
+ * assert('FOO' === $toUpper('foo'));
+ * ```
+ *
+ * # Exceptions
+ *
+ * A `Hoa\Consistency\Exception` exception is thrown if the callback form
+ * is invalid.
+ *
+ * ```php,must_throw(Hoa\Consistency\Exception)
+ * new Hoa\Consistency\Xcallable('Foo:');
+ * ```
*/
public function __construct($call, $able = '')
{
@@ -152,12 +163,11 @@ class Xcallable
* @param ...
* @return mixed
*/
- public function __invoke()
+ public function __invoke(...$arguments)
{
- $arguments = func_get_args();
- $valid = $this->getValidCallback($arguments);
+ $callback = $this->getValidCallback($arguments);
- return call_user_func_array($valid, $arguments);
+ return $callback(...$arguments);
}
/**
@@ -168,7 +178,7 @@ class Xcallable
*/
public function distributeArguments(array $arguments)
{
- return call_user_func_array([$this, '__invoke'], $arguments);
+ return $this->__invoke(...$arguments);
}
/**
@@ -269,39 +279,35 @@ class Xcallable
/**
* Get appropriated reflection instance.
- *
- * @param ...
- * @return \Reflector
*/
- public function getReflection(): \Reflector
+ public function getReflection(...$arguments): Reflector
{
- $arguments = func_get_args();
- $valid = $this->getValidCallback($arguments);
+ $callback = $this->getValidCallback($arguments);
- if (is_string($valid)) {
- return new \ReflectionFunction($valid);
+ if (is_string($callback)) {
+ return new ReflectionFunction($callback);
}
- if ($valid instanceof \Closure) {
- return new \ReflectionFunction($valid);
+ if ($callback instanceof \Closure) {
+ return new ReflectionFunction($callback);
}
- if (is_array($valid)) {
- if (is_string($valid[0])) {
- if (false === method_exists($valid[0], $valid[1])) {
- return new \ReflectionClass($valid[0]);
+ if (is_array($callback)) {
+ if (is_string($callback[0])) {
+ if (false === method_exists($callback[0], $callback[1])) {
+ return new ReflectionClass($callback[0]);
}
- return new \ReflectionMethod($valid[0], $valid[1]);
+ return new ReflectionMethod($callback[0], $callback[1]);
}
- $object = new \ReflectionObject($valid[0]);
+ $object = new ReflectionObject($callback[0]);
- if (null === $valid[1]) {
+ if (null === $callback[1]) {
return $object;
}
- return $object->getMethod($valid[1]);
+ return $object->getMethod($callback[1]);
}
}
diff --git a/composer.json b/composer.json
index f8c0247..3383aa2 100644
--- a/composer.json
+++ b/composer.json
@@ -24,7 +24,7 @@
"source": "https://central.hoa-project.net/Resource/Library/Consistency"
},
"require": {
- "php": ">=7.1",
+ "php": ">=7.1"
},
"require-dev": {
"hoa/stream": "~2.0",
@@ -32,9 +32,9 @@
},
"autoload": {
"psr-4": {
- "Hoa\\Consistency\\": "."
+ "Hoa\\Consistency\\": "Source"
},
- "files": ["Prelude.php"]
+ "files": ["Source/Prelude.php"]
},
"extra": {
"branch-alias": {