mirror of https://github.com/hauke68/Magallanes
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
107 lines
3.3 KiB
107 lines
3.3 KiB
13 years ago
|
<?php
|
||
11 years ago
|
/*
|
||
|
* This file is part of the Magallanes package.
|
||
|
*
|
||
|
* (c) Andrés Montañez <andres@andresmontanez.com>
|
||
|
*
|
||
|
* For the full copyright and license information, please view the LICENSE
|
||
|
* file that was distributed with this source code.
|
||
|
*/
|
||
|
|
||
11 years ago
|
namespace Mage\Command\BuiltIn;
|
||
|
|
||
|
use Mage\Command\AbstractCommand;
|
||
|
use Mage\Console;
|
||
|
|
||
|
use Exception;
|
||
|
|
||
|
/**
|
||
|
* Initializes a Magallanes Configuration into a Proyect
|
||
|
*
|
||
|
* @author Andrés Montañez <andres@andresmontanez.com>
|
||
|
*/
|
||
|
class InitCommand extends AbstractCommand
|
||
13 years ago
|
{
|
||
12 years ago
|
|
||
11 years ago
|
/**
|
||
|
* Command for Initalize a new Configuration Proyect
|
||
|
* @see \Mage\Command\AbstractCommand::run()
|
||
|
*/
|
||
13 years ago
|
public function run()
|
||
|
{
|
||
|
$configDir = '.mage';
|
||
13 years ago
|
|
||
11 years ago
|
Console::output('Initiating managing process for application with <dark_gray>Magallanes</dark_gray>');
|
||
13 years ago
|
|
||
13 years ago
|
// Check if there is already a config dir
|
||
|
if (file_exists($configDir)) {
|
||
11 years ago
|
Console::output('<light_red>Error!!</light_red> Already exists <dark_gray>.mage</dark_gray> directory.', 1, 2);
|
||
13 years ago
|
} else {
|
||
|
$results = array();
|
||
|
$results[] = mkdir($configDir);
|
||
|
$results[] = mkdir($configDir . '/logs');
|
||
12 years ago
|
$results[] = file_put_contents($configDir . '/logs/.gitignore', "*\n!.gitignore");
|
||
13 years ago
|
$results[] = mkdir($configDir . '/tasks');
|
||
12 years ago
|
$results[] = touch($configDir . '/tasks/.gitignore');
|
||
13 years ago
|
$results[] = mkdir($configDir . '/config');
|
||
|
$results[] = mkdir($configDir . '/config/environment');
|
||
12 years ago
|
$results[] = touch($configDir . '/config/environment/.gitignore');
|
||
|
$results[] = file_put_contents($configDir . '/config/general.yml', $this->getGeneralConfig());
|
||
13 years ago
|
|
||
13 years ago
|
if (!in_array(false, $results)) {
|
||
11 years ago
|
Console::output('<light_green>Success!!</light_green> The configuration for <dark_gray>Magallanes</dark_gray> has been generated at <blue>.mage</blue> directory.');
|
||
|
Console::output('<dark_gray>Please!! Review and adjust the configuration.</dark_gray>', 2, 2);
|
||
13 years ago
|
} else {
|
||
11 years ago
|
Console::output('<light_red>Error!!</light_red> Unable to generate the configuration.', 1, 2);
|
||
13 years ago
|
}
|
||
|
}
|
||
|
}
|
||
12 years ago
|
|
||
11 years ago
|
/**
|
||
|
* Returns the Global Configuration
|
||
|
* @return string
|
||
|
*/
|
||
12 years ago
|
protected function getGeneralConfig()
|
||
|
{
|
||
|
// Assamble Global Settings
|
||
|
$projectName = $this->getConfig()->getParameter('name', '');
|
||
|
$notificationEmail = $this->getConfig()->getParameter('email', '');
|
||
|
$notificationEnabled = ($notificationEmail != '') ? 'true' : 'false';
|
||
|
|
||
|
$globalSettings = str_replace(
|
||
|
array(
|
||
|
'%projectName%',
|
||
|
'%notificationEmail%',
|
||
|
'%notificationEnabled%',
|
||
|
'%loggingEnabled%',
|
||
|
'%maxlogs%',
|
||
|
),
|
||
|
array(
|
||
|
$projectName,
|
||
|
$notificationEmail,
|
||
|
$notificationEnabled,
|
||
|
'true',
|
||
|
30
|
||
|
),
|
||
|
$this->generalTemplate
|
||
|
);
|
||
|
|
||
|
return $globalSettings;
|
||
|
}
|
||
11 years ago
|
|
||
|
/**
|
||
|
* Returns the YAML Template for the Global Configuration
|
||
|
* @return string
|
||
|
*/
|
||
|
protected function getGeneralConfigTemplate()
|
||
|
{
|
||
|
$template = '# global settings' . PHP_EOL
|
||
|
. 'name: %projectName%' . PHP_EOL
|
||
|
. 'email: %notificationEmail%' . PHP_EOL
|
||
|
. 'notifications: %notificationEnabled%' . PHP_EOL
|
||
|
. 'logging: %loggingEnabled%' . PHP_EOL
|
||
|
. 'maxlogs: %maxlogs%' . PHP_EOL;
|
||
|
|
||
|
return $template;
|
||
|
}
|
||
13 years ago
|
}
|