Skip to content

Commit

Permalink
Merge branch 'release/2.1.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
mblaschke committed Jul 30, 2015
2 parents 80e0e00 + 6b19371 commit 6010636
Show file tree
Hide file tree
Showing 99 changed files with 2,219 additions and 1,484 deletions.
4 changes: 4 additions & 0 deletions Documentation/Examples/macos-docker-clitools.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[db]
dsn = "mysql:host=192.168.56.2;port=13306"
username = "root"
password = "dev"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CliTools for Docker, PHP und MySQL development

[![latest v2.1.1](https://img.shields.io/badge/latest-v2.1.1-green.svg?style=flat)](https://github.com/mblaschke/clitools/releases/tag/2.1.1)
[![latest v2.1.3](https://img.shields.io/badge/latest-v2.1.3-green.svg?style=flat)](https://github.com/mblaschke/clitools/releases/tag/2.1.3)
[![License GPL3](https://img.shields.io/badge/license-GPL3-blue.svg?style=flat)](/LICENSE)
[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/mblaschke/clitools.svg)](http://isitmaintained.com/project/mblaschke/clitools "Average time to resolve an issue")
[![Percentage of issues still open](http://isitmaintained.com/badge/open/mblaschke/clitools.svg)](http://isitmaintained.com/project/mblaschke/clitools "Percentage of issues still open")
Expand Down
81 changes: 52 additions & 29 deletions src/app/CliTools/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

use CliTools\Console\Formatter\OutputFormatterStyle;
use CliTools\Database\DatabaseConnection;
use CliTools\Service\SettingsService;
use CliTools\Console\Formatter\OutputFormatterStyle;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\ArgvInput;

class Application extends \Symfony\Component\Console\Application {
class Application extends \Symfony\Component\Console\Application
{

/**
* Configuration
Expand All @@ -40,7 +41,7 @@ class Application extends \Symfony\Component\Console\Application {
'class' => array(),
'ignore' => array(),
),
'_files' => array(),
'_files' => array(),
);

/**
Expand All @@ -67,7 +68,8 @@ class Application extends \Symfony\Component\Console\Application {
*
* @param string $file Config file (.ini)
*/
public function loadConfig($file) {
public function loadConfig($file)
{
if (is_readable($file)) {
$parsedConfig = parse_ini_file($file, true);
$this->config = array_replace_recursive($this->config, $parsedConfig);
Expand All @@ -85,7 +87,8 @@ public function loadConfig($file) {
*
* @return null
*/
public function getConfigValue($area, $confKey, $defaultValue = null) {
public function getConfigValue($area, $confKey, $defaultValue = null)
{
$ret = $defaultValue;

if (isset($this->config[$area][$confKey])) {
Expand All @@ -98,7 +101,8 @@ public function getConfigValue($area, $confKey, $defaultValue = null) {
/**
* Initialize
*/
public function initialize() {
public function initialize()
{
$this->initializeErrorHandler();
$this->initializeChecks();
$this->initializeConfiguration();
Expand All @@ -110,14 +114,16 @@ public function initialize() {
*
* @param callable $func
*/
public function registerTearDown(callable $func) {
public function registerTearDown(callable $func)
{
$this->tearDownFuncList[] = $func;
}

/**
* Call teardown callbacks
*/
public function callTearDown() {
public function callTearDown()
{
foreach ($this->tearDownFuncList as $func) {
call_user_func($func);
}
Expand All @@ -137,7 +143,8 @@ public function callTearDown() {
* @return int 0 if everything went fine, or an error code
* @throws \Exception
*/
public function doRun(InputInterface $input, OutputInterface $output) {
public function doRun(InputInterface $input, OutputInterface $output)
{
$ret = 0;

try {
Expand All @@ -151,7 +158,8 @@ public function doRun(InputInterface $input, OutputInterface $output) {
if (!empty($command) && $command instanceof \CliTools\Console\Filter\AnyParameterFilterInterface) {
// Remove all paramters and fake input without any paramters
// prevent eg. --help message
$argCount = $command->getDefinition()->getArgumentRequiredCount();
$argCount = $command->getDefinition()
->getArgumentRequiredCount();

$argvFiltered = array_splice($_SERVER['argv'], 0, 2 + $argCount);

Expand All @@ -162,7 +170,7 @@ public function doRun(InputInterface $input, OutputInterface $output) {
} else {
$ret = parent::doRun($input, $output);
}
} catch(\CliTools\Exception\StopException $e) {
} catch (\CliTools\Exception\StopException $e) {
$this->callTearDown();
$ret = (int)$e->getMessage();
} catch (\Exception $e) {
Expand All @@ -182,36 +190,42 @@ public function doRun(InputInterface $input, OutputInterface $output) {
* @param InputInterface $input An InputInterface instance
* @param OutputInterface $output An OutputInterface instance
*/
protected function configureIO(InputInterface $input, OutputInterface $output) {
protected function configureIO(InputInterface $input, OutputInterface $output)
{
parent::configureIO($input, $output);

$style = new OutputFormatterStyle();
$style->setApplication($this);
$style->setWrap('-', '-');
$output->getFormatter()->setStyle('h1', $style);
$output->getFormatter()
->setStyle('h1', $style);

$style = new OutputFormatterStyle();
$style->setPaddingOutside(' ===> ');
$output->getFormatter()->setStyle('h2', $style);
$output->getFormatter()
->setStyle('h2', $style);

$style = new OutputFormatterStyle();
$style->setPaddingOutside(' - ');
$output->getFormatter()->setStyle('p', $style);
$output->getFormatter()
->setStyle('p', $style);

$style = new OutputFormatterStyle('white', 'red');
$style->setPadding(' [EE] ');
$output->getFormatter()->setStyle('p-error', $style);
$output->getFormatter()
->setStyle('p-error', $style);
}

/**
* Initialize POSIX trap
*/
protected function initializePosixTrap() {
protected function initializePosixTrap()
{
declare(ticks = 1);

$me = $this;

$signalHandler = function ($signal) use($me) {
$signalHandler = function ($signal) use ($me) {
$me->callTearDown();

// Prevent terminal messup
Expand All @@ -225,7 +239,8 @@ protected function initializePosixTrap() {
/**
* Init error handler
*/
protected function initializeErrorHandler() {
protected function initializeErrorHandler()
{
$errorHandler = function ($errno, $errstr, $errfile, $errline) {
$msg = array(
'Message: ' . $errstr,
Expand All @@ -244,7 +259,8 @@ protected function initializeErrorHandler() {
/**
* PHP Checks
*/
protected function initializeChecks() {
protected function initializeChecks()
{
if (!function_exists('pcntl_signal')) {
echo ' [ERROR] PHP-Module pcnt not loaded';
exit(1);
Expand All @@ -254,7 +270,8 @@ protected function initializeChecks() {
/**
* Initialize configuration
*/
protected function initializeConfiguration() {
protected function initializeConfiguration()
{
$isRunningAsRoot = $this->isRunningAsRoot();

//#########################
Expand Down Expand Up @@ -289,7 +306,10 @@ protected function initializeConfiguration() {
foreach ($this->config['commands']['class'] as $class) {
if ($this->checkCommandClass($class)) {
// check OnlyRoot filter
if (!$isRunningAsRoot && is_subclass_of($class, '\CliTools\Console\Filter\OnlyRootFilterInterface')
if (!$isRunningAsRoot && is_subclass_of(
$class,
'\CliTools\Console\Filter\OnlyRootFilterInterface'
)
) {
// class only useable for root
continue;
Expand All @@ -308,7 +328,8 @@ protected function initializeConfiguration() {
*
* @return bool
*/
protected function checkCommandClass($class) {
protected function checkCommandClass($class)
{
// Ignores (deprecated)
foreach ($this->config['commands']['ignore'] as $exclude) {

Expand All @@ -320,7 +341,6 @@ protected function checkCommandClass($class) {
if (preg_match($regExp, $class)) {
return false;
}

} elseif ($class === $exclude) {
// direct ignore
return false;
Expand All @@ -338,7 +358,6 @@ protected function checkCommandClass($class) {
if (preg_match($regExp, $class)) {
return false;
}

} elseif ($class === $exclude) {
// direct ignore
return false;
Expand All @@ -358,7 +377,8 @@ protected function checkCommandClass($class) {
*
* @return bool
*/
public function isRunningAsRoot() {
public function isRunningAsRoot()
{
$currentUid = (int)posix_getuid();

return $currentUid === 0;
Expand All @@ -369,10 +389,12 @@ public function isRunningAsRoot() {
*
* @return SettingsService
*/
public function getSettingsService() {
public function getSettingsService()
{
if ($this->settingsService === null) {
$this->settingsService = new SettingsService();
}

return $this->settingsService;
}

Expand All @@ -381,7 +403,8 @@ public function getSettingsService() {
*
* @param string $title Title
*/
public function setTerminalTitle($title) {
public function setTerminalTitle($title)
{
// DECSLPP.
echo "\033]0;" . 'ct: ' . $title . "\033\\";
}
Expand Down
Loading

0 comments on commit 6010636

Please sign in to comment.