You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
http/src/Handle.php

76 lines
1.5 KiB
PHP

<?php
namespace BitCommunism\Http;
class Handle
{
/**
* @var callable
*/
private $call;
/**
* @var array
*/
private $settings = [];
/**
* @var
*/
private $middleware = [];
public function __construct($call, $settings = [], $middleware = [])
{
if (is_string($call)) {
$call = [$call, 'handle'];
}
$this->call = $call;
$this->settings = $settings;
$this->middleware = $middleware;
}
/**
* @return callable
*/
public function getCall(): callable
{
return $this->call;
}
/**
* @return array
*/
public function getSettings(): array
{
return $this->settings;
}
/**
* @return mixed
*/
public function getMiddleware()
{
return $this->middleware;
}
public function withMiddleware($middleware): Handle
{
return new static($this->call, $this->settings, array_merge($this->middleware, [$middleware]));
}
public function mergeWithSettings($settings): Handle
{
return new static($this->call, array_merge($this->settings, $settings), $this->middleware);
}
public function withSettings($settings): Handle
{
return new static($this->call, $settings, $this->middleware);
}
public function withPrependedMiddleware($middlewares): Handle
{
return new static($this->call, $this->settings, array_merge($middlewares, $this->middleware));
}
}