| Total Complexity | 10 |
| Total Lines | 37 |
| Duplicated Lines | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | class PreviewMode |
||
| 10 | { |
||
| 11 | private $active; |
||
| 12 | |||
| 13 | final public function __construct(bool $active) |
||
| 14 | { |
||
| 15 | $this->active = $active; |
||
| 16 | } |
||
| 17 | |||
| 18 | public static function fromRequest() |
||
| 19 | { |
||
| 20 | if(!config('thinktomorrow.chief.preview-mode') || Str::startsWith(request()->path(), 'admin/')) { |
||
| 21 | return new static(false); |
||
| 22 | } |
||
| 23 | |||
| 24 | $active = (session()->get('preview-mode', static::default()) === true && auth()->guard('chief')->check()); |
||
| 25 | |||
| 26 | return new static($active); |
||
| 27 | } |
||
| 28 | |||
| 29 | public static function toggle() |
||
| 30 | { |
||
| 31 | session()->put('preview-mode', !session()->get('preview-mode', static::default())); |
||
| 32 | } |
||
| 33 | |||
| 34 | public function check(): bool |
||
| 37 | } |
||
| 38 | |||
| 39 | private static function default(): bool |
||
| 46 | } |
||
| 47 | } |
||
| 48 |