Completed
Push — master ( ae71bc...22904a )
by Joschi
02:57
created

TYPO3FluidView   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 6
Bugs 0 Features 3
Metric Value
wmc 5
c 6
b 0
f 3
lcom 0
cbo 5
dl 0
loc 88
ccs 37
cts 37
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setTemplatePaths() 0 22 1
A registerNamespaces() 0 4 1
A setAction() 0 5 1
A __construct() 0 15 2
1
<?php
2
3
/**
4
 * apparat-server
5
 *
6
 * @category    Apparat
7
 * @package     Apparat\Server
8
 * @subpackage  Apparat\Server\Ports
9
 * @author      Joschi Kuphal <[email protected]> / @jkphl
10
 * @copyright   Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl
11
 * @license     http://opensource.org/licenses/MIT The MIT License (MIT)
12
 */
13
14
/***********************************************************************************
15
 *  The MIT License (MIT)
16
 *
17
 *  Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl
18
 *
19
 *  Permission is hereby granted, free of charge, to any person obtaining a copy of
20
 *  this software and associated documentation files (the "Software"), to deal in
21
 *  the Software without restriction, including without limitation the rights to
22
 *  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
23
 *  the Software, and to permit persons to whom the Software is furnished to do so,
24
 *  subject to the following conditions:
25
 *
26
 *  The above copyright notice and this permission notice shall be included in all
27
 *  copies or substantial portions of the Software.
28
 *
29
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
31
 *  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
32
 *  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
33
 *  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
34
 *  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
 ***********************************************************************************/
36
37
namespace Apparat\Server\Ports\View;
38
39
use Apparat\Kernel\Tests\Kernel;
40
use Apparat\Server\Ports\Facade\ServerFacade;
41
use TYPO3Fluid\Fluid\Core\Cache\FluidCacheInterface;
42
use TYPO3Fluid\Fluid\Core\Cache\SimpleFileCache;
43
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
44
use TYPO3Fluid\Fluid\View\TemplateView;
45
46
/**
47
 * TYPO3 Fluid view
48
 *
49
 * @package Apparat\Server
50
 * @subpackage Apparat\Server\Ports
51
 */
52
class TYPO3FluidView extends TemplateView implements ViewInterface
53
{
54
    /**
55
     * Layouts
56
     *
57
     * @var string
58
     */
59
    const LAYOUTS = 'layouts';
60
    /**
61
     * Partials
62
     *
63
     * @var string
64
     */
65
    const PARTIALS = 'partials';
66
    /**
67
     * Templates
68
     *
69
     * @var string
70
     */
71
    const TEMPLATES = 'templates';
72
73
    /**
74
     * Constructor
75
     *
76
     * @param null|RenderingContextInterface $context
77
     */
78 77
    public function __construct(RenderingContextInterface $context = null)
79
    {
80 77
        parent::__construct($context);
81
82 77
        $this->setTemplatePaths();
83 77
        $this->registerNamespaces();
84
85
        // Enable the cache
86 77
        $fluidCacheDirectory = trim(getenv('FLUID_CACHE_DIRECTORY'));
87 77
        if (strlen($fluidCacheDirectory)) {
88
            /** @var FluidCacheInterface $fluidCache */
89 77
            $fluidCache = Kernel::create(SimpleFileCache::class, [$fluidCacheDirectory]);
90 77
            $this->setCache($fluidCache);
91 77
        }
92 77
    }
93
94
    /**
95
     * Set the template paths
96
     */
97 77
    protected function setTemplatePaths()
98
    {
99 77
        $paths = $this->getTemplatePaths();
100 77
        $paths->setLayoutRootPaths(
101 77
            array_merge(
102 77
                (array)ServerFacade::getViewResources(self::LAYOUTS),
103 77
                [__DIR__.DIRECTORY_SEPARATOR.'TYPO3Fluid'.DIRECTORY_SEPARATOR.'Layouts']
104 77
            )
105 77
        );
106 77
        $paths->setTemplateRootPaths(
107 77
            array_merge(
108 77
                (array)ServerFacade::getViewResources(self::TEMPLATES),
109 77
                [__DIR__.DIRECTORY_SEPARATOR.'TYPO3Fluid'.DIRECTORY_SEPARATOR.'Templates']
110 77
            )
111 77
        );
112 77
        $paths->setPartialRootPaths(
113 77
            array_merge(
114 77
                (array)ServerFacade::getViewResources(self::PARTIALS),
115 77
                [__DIR__.DIRECTORY_SEPARATOR.'TYPO3Fluid'.DIRECTORY_SEPARATOR.'Partials']
116 77
            )
117 77
        );
118 77
    }
119
120
    /**
121
     * Register default view helper namespaces
122
     */
123 77
    protected function registerNamespaces()
124
    {
125 77
        $this->getViewHelperResolver()->addNamespace('as', 'Apparat\\Server\\Ports\\ViewHelpers');
126 77
    }
127
128
    /**
129
     * Set the action name
130
     *
131
     * @param string $action Action name
132
     * @return ViewInterface Self reference
133
     */
134 77
    public function setAction($action)
135
    {
136 77
        $this->getRenderingContext()->setControllerAction($action);
137 77
        return $this;
138
    }
139
}
140