Cachet/app/Http/Middleware/Timezone.php

62 lines
1.3 KiB
PHP
Raw Normal View History

<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Http\Middleware;
use Closure;
2016-02-02 20:46:46 +00:00
use Illuminate\Contracts\Config\Repository;
2016-02-11 11:35:40 +00:00
use Illuminate\Http\Request;
2016-10-08 10:37:21 +01:00
/**
* This is the timezone middleware class.
*
* @author James Brooks <james@alt-three.com>
* @author Graham Campbell <james@alt-three.com>
*/
class Timezone
{
2016-02-02 20:46:46 +00:00
/**
2016-02-02 20:49:00 +00:00
* The config repository instance.
2016-02-02 20:46:46 +00:00
*
* @var \Illuminate\Contracts\Config\Repository
*/
protected $config;
/**
2016-05-29 18:14:40 +01:00
* Creates a new timezone middleware instance.
2016-02-02 20:46:46 +00:00
*
* @param \Illuminate\Contracts\Config\Repository $config
*
* @return void
*/
public function __construct(Repository $config)
{
$this->config = $config;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
*
* @return mixed
*/
2016-02-11 11:35:40 +00:00
public function handle(Request $request, Closure $next)
{
if ($tz = $request->header('Time-Zone')) {
2016-02-02 20:46:46 +00:00
$this->config->set('cachet.timezone', $tz);
}
return $next($request);
}
}