mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
49 lines
962 B
PHP
49 lines
962 B
PHP
<?php
|
|
|
|
namespace SilverStripe\Core\Config\Middleware;
|
|
|
|
/**
|
|
* Abstract flag-aware middleware
|
|
*/
|
|
trait MiddlewareCommon
|
|
{
|
|
/**
|
|
* Disable flag
|
|
*
|
|
* @var int
|
|
*/
|
|
protected $disableFlag = 0;
|
|
|
|
public function __construct($disableFlag = 0)
|
|
{
|
|
$this->disableFlag = $disableFlag;
|
|
}
|
|
|
|
/**
|
|
* Check if this middlware is enabled
|
|
*
|
|
* @param int|true $excludeMiddleware
|
|
* @return bool
|
|
*/
|
|
protected function enabled($excludeMiddleware)
|
|
{
|
|
if ($excludeMiddleware === true) {
|
|
return false;
|
|
}
|
|
if (!$this->disableFlag) {
|
|
return true;
|
|
}
|
|
return ($excludeMiddleware & $this->disableFlag) !== $this->disableFlag;
|
|
}
|
|
|
|
public function serialize()
|
|
{
|
|
return json_encode([$this->disableFlag]);
|
|
}
|
|
|
|
public function unserialize($serialized)
|
|
{
|
|
list($this->disableFlag) = json_decode($serialized, true);
|
|
}
|
|
}
|