Completed
Push — master ( 6f7432...aedcf9 )
by Joschi
07:55
created

TYPO3FluidView   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 2
Metric Value
wmc 3
c 3
b 0
f 2
lcom 0
cbo 3
dl 0
loc 78
ccs 28
cts 28
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
B setTemplatePaths() 0 26 1
A setAction() 0 5 1
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\Server\Ports\Facade\ServerFacade;
40
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
41
use TYPO3Fluid\Fluid\View\TemplateView;
42
43
/**
44
 * TYPO3 Fluid view
45
 *
46
 * @package Apparat\Server
47
 * @subpackage Apparat\Server\Ports
48
 */
49
class TYPO3FluidView extends TemplateView implements ViewInterface
50
{
51
    /**
52
     * Layouts
53
     *
54
     * @var string
55
     */
56
    const LAYOUTS = 'layouts';
57
    /**
58
     * Partials
59
     *
60
     * @var string
61
     */
62
    const PARTIALS = 'partials';
63
    /**
64
     * Templates
65
     *
66
     * @var string
67
     */
68
    const TEMPLATES = 'templates';
69
70
    /**
71
     * Constructor
72
     *
73
     * @param null|RenderingContextInterface $context
74
     */
75 71
    public function __construct(RenderingContextInterface $context = null)
76
    {
77
        // TODO Why gets this called twice?
78
//        var_dump($context);
79 71
        parent::__construct($context);
80 71
        $this->setTemplatePaths();
81 71
    }
82
83
    /**
84
     * Set the template paths
85
     *
86
     * @todo Enable externally configured paths
87
     */
88 71
    protected function setTemplatePaths()
89
    {
90 71
        $paths = $this->getTemplatePaths();
91 71
        $paths->setLayoutRootPaths(
92 71
            array_merge(
93 71
                (array)ServerFacade::getViewResources(self::LAYOUTS),
94 71
                [__DIR__.DIRECTORY_SEPARATOR.'TYPO3Fluid'.DIRECTORY_SEPARATOR.'Layouts']
95 71
            )
96 71
        );
97 71
        $paths->setTemplateRootPaths(
98 71
            array_merge(
99 71
                (array)ServerFacade::getViewResources(self::TEMPLATES),
100 71
                [__DIR__.DIRECTORY_SEPARATOR.'TYPO3Fluid'.DIRECTORY_SEPARATOR.'Templates']
101 71
            )
102 71
        );
103 71
        $paths->setPartialRootPaths(
104 71
            array_merge(
105 71
                (array)ServerFacade::getViewResources(self::PARTIALS),
106 71
                [__DIR__.DIRECTORY_SEPARATOR.'TYPO3Fluid'.DIRECTORY_SEPARATOR.'Partials']
107 71
            )
108 71
        );
109
110
        // Register the view helpers
111
        // TODO: Enable after https://github.com/TYPO3Fluid/Fluid/issues/114 has been resolved
112
//        $paths->registerNamespace('as', 'Apparat\\Server\\Ports\\ViewHelpers');
113 71
    }
114
115
    /**
116
     * Set the action name
117
     *
118
     * @param string $action Action name
119
     * @return ViewInterface Self reference
120
     */
121 71
    public function setAction($action)
122
    {
123 71
        $this->getRenderingContext()->setControllerAction($action);
124 71
        return $this;
125
    }
126
}
127