Ich habe eine Klasse zum Stacking von Objekt-Layern und Closures gegründet, aber mein Server läuft noch nicht auf PHP 5.6. Und ich frage mich, wie kann ich die ...$parameters
konvertieren, weil ich kann es beheben, indem alles mit call_user_func_array()
ersetzt dann die buildCoreClosure()
Methode Fehler zum Beispiel werfen, weil eine Schließung ein Array ist nicht ...Downgrade Klasse PHP 5.6 bis 5.5
class Stack
{
/**
* Method to call on the 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 as $layer)
{
$layer = $this->container->get($layer);
$next = $this->buildLayerClosure($layer, $next);
}
return $next(...$parameters);
}
}
Kühle Frage zu ersetzen. Ich habe zuvor Arrays von Parametern in diesem Fall verwendet, um zu vermeiden, dass sie alle aufgelistet werden müssen. –