IndexController::indexAction()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 2 Features 1
Metric Value
c 5
b 2
f 1
dl 0
loc 16
rs 9.4285
cc 2
eloc 11
nc 2
nop 0
1
<?php
2
3
/**
4
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
5
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
6
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
7
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
8
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
9
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
10
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
12
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
13
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
14
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15
 *
16
 * This software consists of voluntary contributions made by many individuals
17
 * and is licensed under the MIT license.
18
 */
19
namespace LearnZF2Themes\Controller;
20
21
use Zend\Mvc\Controller\AbstractActionController;
22
use Zend\View\Model\ViewModel;
23
24
/**
25
 * @author Stanimir Dimitrov <[email protected]>
26
 */
27
class IndexController extends AbstractActionController
28
{
29
    /**
30
     * @var array
31
     */
32
    private $themesConfig = [];
33
34
    /**
35
     * @var mixed
36
     */
37
    private $reloadService = null;
38
39
    /**
40
     * @method __construct
41
     *
42
     * @param array $themesConfig
43
     * @param mixed $reloadService
44
     */
45
    public function __construct(array $themesConfig, $reloadService)
46
    {
47
        $this->themesConfig = $themesConfig;
48
        $this->reloadService = $reloadService;
49
    }
50
51
    /**
52
     * This action shows the list of all themes.
53
     *
54
     * @method indexAction
55
     *
56
     * @return ViewModel
57
     */
58
    public function indexAction()
59
    {
60
        $request = $this->getRequest();
61
        if ($request->isPost()) {
62
            $filename = __DIR__.'/../../../config/module.config.php';
63
            $settings = include $filename;
64
            $themeName = $request->getPost()['themeName'];
65
            $settings['theme']['name'] = $themeName;
66
            file_put_contents($filename, '<?php return '.var_export($settings, true).';');
67
            $this->reloadService->reload();
68
        }
69
70
        return new ViewModel([
71
            'themes' => $this->themesConfig,
72
        ]);
73
    }
74
}
75