Skip to content

Commit 2f2e4ec

Browse files
author
Ivan Gavryshko
committed
MAGETWO-34511: Process config options
- added console application
1 parent eb92872 commit 2f2e4ec

File tree

4 files changed

+240
-0
lines changed

4 files changed

+240
-0
lines changed

setup/cli.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
try {
8+
require __DIR__ . '/../app/bootstrap.php';
9+
} catch (\Exception $e) {
10+
if (PHP_SAPI == 'cli') {
11+
echo 'Autoload error: ' . $e->getMessage();
12+
} else {
13+
echo <<<HTML
14+
<div style="font:12px/1.35em arial, helvetica, sans-serif;">
15+
<div style="margin:0 0 25px 0; border-bottom:1px solid #ccc;">
16+
<h3 style="margin:0;font-size:1.7em;font-weight:normal;text-transform:none;text-align:left;color:#2f2f2f;">
17+
Autoload error</h3>
18+
</div>
19+
<p>{$e->getMessage()}</p>
20+
</div>
21+
HTML;
22+
}
23+
exit(1);
24+
}
25+
26+
$application = new Magento\Setup\Console\Application('Magento2 CLI', '0.0.1');
27+
$application->run();
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Setup\Console;
8+
9+
use Symfony\Component\Console\Application as SymfonyApplication;
10+
use \Magento\Framework\App\Bootstrap;
11+
12+
/**
13+
* Magento2 CLI Application
14+
*
15+
* {@inheritdoc}
16+
*/
17+
class Application extends SymfonyApplication
18+
{
19+
/**
20+
* {@inheritdoc}
21+
*/
22+
protected function getDefaultCommands()
23+
{
24+
$commands = parent::getDefaultCommands();
25+
foreach ($this->getApplicationCommands() as $command) {
26+
$commands[] = $this->add($command);
27+
}
28+
29+
return $commands;
30+
}
31+
32+
/**
33+
* Gets application commands
34+
*
35+
* @return array
36+
*/
37+
protected function getApplicationCommands()
38+
{
39+
$commandsList = [];
40+
41+
$serviceManager = \Zend\Mvc\Application::init(require BP . '/setup/config/application.config.php')->getServiceManager();
42+
$setupFiles = glob(BP . '/setup/src/Magento/Setup/Console/Command/*Command.php');
43+
if ($setupFiles) {
44+
foreach ($setupFiles as $file) {
45+
if (preg_match("#(Magento/Setup/Console/Command/.*Command).php#", $file, $parts)) {
46+
$class = str_replace('/', '\\', $parts[1]);
47+
$commandObject = null;
48+
try {
49+
$commandObject = $serviceManager->create($class);
50+
} catch (\Exception $e) {
51+
try {
52+
echo "Could not create command using service manager: " . $e->getMessage() . "\n";
53+
$commandObject = new $class();
54+
} catch (\Exception $e) {
55+
}
56+
}
57+
if (null !== $commandObject) {
58+
$commandsList[] = $commandObject;
59+
}
60+
}
61+
}
62+
}
63+
64+
return $commandsList;
65+
}
66+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Setup\Console\Command;
8+
9+
use Symfony\Component\Console\Command\Command;
10+
use Symfony\Component\Console\Input\InputInterface;
11+
use Symfony\Component\Console\Output\OutputInterface;
12+
use Magento\Setup\Model\ConfigModel;
13+
14+
class ConfigInstallCommand extends Command
15+
{
16+
/**
17+
* @var ConfigModel
18+
*/
19+
protected $configModel;
20+
21+
/**
22+
* @var ConfigFilePool
23+
*/
24+
protected $configFilePool;
25+
26+
/**
27+
* Constructor
28+
*s
29+
* @param \Magento\Setup\Model\ConfigModel $configModel
30+
*/
31+
public function __construct(ConfigModel $configModel)
32+
{
33+
$this->configModel = $configModel;
34+
parent::__construct();
35+
}
36+
37+
/**
38+
* Initialization of the command
39+
*
40+
* @return void
41+
*/
42+
protected function configure()
43+
{
44+
$options = $this->configModel->getAvailableOptions();
45+
46+
$this
47+
->setName('config:install')
48+
->setDescription('Install deployment configuration')
49+
->setDefinition($options);
50+
}
51+
52+
/**
53+
* {@inheritdoc}
54+
*/
55+
protected function execute(InputInterface $input, OutputInterface $output)
56+
{
57+
// TODO: wrap into try catch
58+
// TODO: think about error and log message processing
59+
$this->configModel->process($input->getOptions());
60+
61+
}
62+
63+
64+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Setup\Model;
8+
9+
use Magento\Framework\Config\File\ConfigFilePool;
10+
11+
class ConfigModel
12+
{
13+
/**
14+
* @var \Magento\Setup\Model\ConfigOptionsCollector
15+
*/
16+
protected $collector;
17+
18+
/**
19+
* Constructor
20+
*
21+
* @param ConfigOptionsCollector $collector
22+
* @param \Magento\Framework\Config\File\ConfigFilePool $configFilePool
23+
*/
24+
public function __construct(ConfigOptionsCollector $collector, ConfigFilePool $configFilePool)
25+
{
26+
$this->configFilePool = $configFilePool;
27+
$this->collector = $collector;
28+
}
29+
30+
/**
31+
* Gets available config options
32+
*
33+
* @return array
34+
*/
35+
public function getAvailableOptions()
36+
{
37+
$optionCollection = [];
38+
$options = $this->collector->collectOptions();
39+
40+
foreach ($options as $option) {
41+
// TODO: we need to get rid of keys here
42+
if ($option['enabled']) {
43+
$optionCollection = array_merge($optionCollection, $option['options']);
44+
}
45+
}
46+
47+
return $optionCollection;
48+
}
49+
50+
/**
51+
* Process input options
52+
*
53+
* @param array $inputOptions
54+
*/
55+
public function process($inputOptions)
56+
{
57+
$fileConfigStorage = [];
58+
59+
$options = $this->collector->collectOptions();
60+
foreach ($options as $option) {
61+
if ($option['enabled']) {
62+
// TODO: add isset and check of instance here
63+
$conf = $option['configOption']->createConfig($inputOptions);
64+
65+
// TODO: this file should be returned by ConfigOption
66+
$defaultConfigFile = ConfigFilePool::APP_CONFIG;
67+
68+
if (isset($fileConfigStorage[$defaultConfigFile])) {
69+
$fileConfigStorage[$defaultConfigFile] = array_merge(
70+
$fileConfigStorage[$defaultConfigFile],
71+
$conf
72+
);
73+
} else {
74+
$fileConfigStorage[$defaultConfigFile] = $conf;
75+
}
76+
}
77+
}
78+
79+
var_dump($fileConfigStorage);
80+
81+
}
82+
83+
}

0 commit comments

Comments
 (0)