[英]Downgrade class php 5.6 to 5.5
我創建了一個用於堆疊對象層和閉包的類,但是我的服務器尚未在php 5.6上運行。 我想知道如何轉換...$parameters
因為我無法通過用call_user_func_array()
替換所有內容來修復它,因此buildCoreClosure()
方法將引發錯誤,例如,因為閉包不是數組...
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);
}
}
通過刪除
...$arguments
在每個函數的參數列表中,並將其替換為以下內容(在函數內部早期)
$arguments = func_get_args();
您可以實現相同的參數值。 即使未在函數的參數列表中定義,參數仍將傳遞給func_get_args()。
解決方法是將...$arguments
替換...$arguments
func_get_args()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.