for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace TusPhp\Middleware;
class Middleware
{
/** @var array */
protected $globalMiddleware = [];
/**
* Middleware constructor.
*/
public function __construct()
$this->globalMiddleware = [
GlobalHeaders::class => new GlobalHeaders,
Cors::class => new Cors,
];
}
* Get registered middleware.
*
* @return array
public function list() : array
return $this->globalMiddleware;
* Get before middleware.
public function before() : array
$before = [];
foreach ($this->globalMiddleware as $m) {
if ($m->before()) {
$before[] = $m;
return $before;
* Get after middleware.
public function after() : array
$after = [];
if ( ! $m->before()) {
$after[] = $m;
return $after;
* Set middleware.
* @param array $middleware
* @return Middleware
public function add(...$middleware) : self
foreach ($middleware as $m) {
if ($m instanceof TusMiddlewareInterface) {
$this->globalMiddleware[get_class($m)] = $m;
} else if (is_string($m)) {
$this->globalMiddleware[$m] = new $m;
return $this;
* Skip middleware.
* @param array ...$middleware
public function skip(...$middleware) : self
unset($this->globalMiddleware[$m]);