Completed
Push — master ( fb8ce4...a7fcd1 )
by Cheren
02:00
created

ThemeMiddleware::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 1
eloc 6
nc 1
nop 3
1
<?php
2
/**
3
 * CakeCMS Core
4
 *
5
 * This file is part of the of the simple cms based on CakePHP 3.
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * @package     Core
10
 * @license     MIT
11
 * @copyright   MIT License http://www.opensource.org/licenses/mit-license.php
12
 * @link        https://github.com/CakeCMS/Core".
13
 * @author      Sergey Kalistratov <[email protected]>
14
 */
15
16
namespace Core\View\Middleware;
17
18
use Core\Theme;
19
use Core\Plugin;
20
use Cake\Http\Runner;
21
use Cake\Http\Response;
22
use Cake\Http\ServerRequest;
23
24
/**
25
 * Class ThemeMiddleware
26
 *
27
 * @package Core\View\Middleware
28
 */
29
class ThemeMiddleware
30
{
31
32
    /**
33
     * Serve assets if the path matches one.
34
     *
35
     * @param   ServerRequest $request
36
     * @param   Response $response
37
     * @param   Runner $next
38
     * @return  mixed
39
     */
40
    public function __invoke($request, $response, $next)
41
    {
42
        $theme    = Theme::setup($request->getParam('prefix'));
43
        $request  = $request->withParam('theme', $theme);
44
        $response = $next($request, $response);
45
46
        Plugin::loaded($theme);
47
        return $response;
48
    }
49
}
50