Passed
Push — develop ( 28c299...928e2a )
by Mathias
12:40
created

AssetsInstallController::factory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
c 0
b 0
f 0
ccs 4
cts 4
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of the YAWIK project.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Core\Controller\Console;
11
12
use Interop\Container\ContainerInterface;
13
use Symfony\Component\Console\Input\ArgvInput;
14
use Symfony\Component\Console\Input\InputInterface;
15
use Symfony\Component\Console\Output\ConsoleOutput;
16
use Symfony\Component\Console\Output\OutputInterface;
17
use Symfony\Component\Filesystem\Filesystem;
18
use Yawik\Composer\AssetsInstaller;
19
use Zend\ModuleManager\ModuleManager;
20
use Zend\Mvc\Console\Controller\AbstractConsoleController;
21
22
/**
23
 * Class AssetsInstallController
24
 *
25
 * @package     Core\Controller\Console
26
 * @author      Anthonius Munthi <[email protected]>
27
 * @since       0.32.0
28
 */
29
class AssetsInstallController extends AbstractConsoleController
30
{
31
    /**
32
     * @var Filesystem
33
     */
34
    private $filesystem;
35
36
    /**
37
     * An array list of injected modules
38
     * @var array
39
     */
40
    private $modules = [];
41
42
    /**
43
     * @var InputInterface
44
     */
45
    private $input;
46
47
    /**
48
     * @var OutputInterface
49
     */
50
    private $output;
51
52
    /**
53
     * @var AssetsInstaller
54
     */
55
    protected $installer;
56
57
    /**
58
     * AssetsInstallController constructor.
59
     * @param array $modules List of installed modules
60
     */
61 3
    public function __construct(array $modules = [])
62
    {
63 3
        $this->modules      = $modules;
64 3
        $this->filesystem   = new Filesystem();
65 3
        $this->input        = new ArgvInput();
66 3
        $this->output       = new ConsoleOutput();
67 3
        $this->installer    = new AssetsInstaller();
68 3
    }
69
70
    /**
71
     * Creates new object
72
     * @param   ContainerInterface $container
73
     * @return AssetsInstallController
74
     */
75 3
    public static function factory(ContainerInterface $container)
76
    {
77
        /* @var ModuleManager $manager */
78 3
        $manager = $container->get('ModuleManager');
79 3
        $modules = $manager->getLoadedModules();
80
81 3
        return new static($modules);
82
    }
83
84
    /**
85
     * @param InputInterface $input
86
     * @return AssetsInstallController
87
     */
88 3
    public function setInput($input)
89
    {
90 3
        $this->input = $input;
91
92 3
        return $this;
93
    }
94
95
    /**
96
     * @param OutputInterface $output
97
     * @return AssetsInstallController
98
     */
99 3
    public function setOutput($output)
100
    {
101 3
        $this->output = $output;
102
103 3
        return $this;
104
    }
105
106 3
    public function setInstaller(AssetsInstaller $installer)
107
    {
108 3
        $this->installer = $installer;
109 3
    }
110
111 3
    public function indexAction()
112
    {
113
        /* @var \Zend\Console\Request $request */
114 3
        $modules        = $this->modules;
115 3
        $request        = $this->getRequest();
116 3
        $symlink        = $request->getParam('symlink');
117 3
        $relative       = $request->getParam('relative');
118 3
        $installer      = $this->installer;
119 3
        $assets         = $installer->getModulesAsset($modules);
120
121
        // setup expected method
122 3
        if ($relative) {
123 1
            $expectedMethod = AssetsInstaller::METHOD_RELATIVE_SYMLINK;
124 2
        } elseif ($symlink) {
125 1
            $expectedMethod = AssetsInstaller::METHOD_ABSOLUTE_SYMLINK;
126
        } else {
127 1
            $expectedMethod = AssetsInstaller::METHOD_COPY;
128
        }
129
130 3
        $installer->setInput($this->input);
131 3
        $installer->setOutput($this->output);
132 3
        $installer->install($assets, $expectedMethod);
133 3
    }
134
}
135