php 5.5 - Downgrade class php 5.6 to 5.5 -
i founded class stack object layers , closures server isnt running on php 5.6 yet. , wondering how can convert ...$parameters
because cant fix replacing call_user_func_array()
buildcoreclosure()
method throw errors example because closure isnt array...
class stack { /** * method call on decoracted class. * * @var string */ protected $method; /** * container. */ protected $container; /** * middleware layers. * * @var array */ protected $layers = []; public function __construct(container $container = null, $method = null) { $this->container = $container ?: new container; $this->method = $method ?: 'handle'; } public function addlayer($class, $inner = true) { return $inner ? array_unshift($this->layers, $class) : array_push($this->layers, $class); } public function addinnerlayer($class) { return $this->addlayer($class); } public function addouterlayer($class) { return $this->addlayer($class, false); } protected function buildcoreclosure($object) { return function(...$arguments) use ($object) { $callable = $object instanceof closure ? $object : [$object, $this->method]; return $callable(...$arguments); }; } protected function buildlayerclosure($layer, closure $next) { return function(...$arguments) use ($layer, $next) { return $layer->execute(...array_merge($arguments, [$next])); }; } public function peel($object, array $parameters = []) { $next = $this->buildcoreclosure($object); foreach($this->layers $layer) { $layer = $this->container->get($layer); $next = $this->buildlayerclosure($layer, $next); } return $next(...$parameters); } }
by removing
...$arguments
in arguments list of each function , replacing following (early inside function)
$arguments = func_get_args();
you can achieve same value of arguments. arguments still passed func_get_args() when not defined in function's argument list.
Comments
Post a Comment