Skip to content

Commit

Permalink
Merge pull request #35 from bluzphp/develop
Browse files Browse the repository at this point in the history
Migrate to PHP 7.1
Added `Scaffold` generator
  • Loading branch information
Anton authored Nov 24, 2017
2 parents 6f695fb + a36f841 commit 6e16590
Show file tree
Hide file tree
Showing 30 changed files with 749 additions and 599 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
language: php
php:
- 7.0
- 7.1
- 7.2
- master
matrix:
allow_failures:
- php: 7.2
- php: master
install:
# Composer
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
}
],
"require": {
"php": ">=7.0",
"php": ">=7.1",
"bluzphp/framework": "~7.8",
"codeception/codeception": "~2.3",
"composer/composer": "~1.5",
"robmorgan/phinx": "~0.9",
Expand All @@ -20,8 +21,7 @@
"symfony/filesystem": "~3.0",
"symfony/finder": "~3.0",
"symfony/process": "~3.0",
"symfony/yaml": "~3.0",
"bluzphp/framework": "~7.7"
"symfony/yaml": "~3.0"
},
"require-dev": {
"phpunit/phpunit": "~6.4",
Expand Down
12 changes: 7 additions & 5 deletions src/Application/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN')
* init
*
* @return void
* @throws \Bluz\Config\ConfigException
*/
public function init()
{
Expand Down Expand Up @@ -98,6 +99,7 @@ protected function registerCommands()
new Command\Generate\CrudCommand,
new Command\Generate\GridCommand,
new Command\Generate\RestCommand,
new Command\Generate\ScaffoldCommand,
new Command\Module\InstallCommand,
new Command\Module\ListCommand,
new Command\Module\RemoveCommand,
Expand All @@ -113,7 +115,7 @@ protected function registerCommands()
*
* @return string
*/
public function getWorkingPath()
public function getWorkingPath() : string
{
return getcwd();
}
Expand All @@ -124,7 +126,7 @@ public function getWorkingPath()
* @param string $name
* @return string
*/
public function getModulePath($name)
public function getModulePath($name) : string
{
return $this->getWorkingPath() . DIRECTORY_SEPARATOR
. 'application' . DIRECTORY_SEPARATOR
Expand All @@ -138,7 +140,7 @@ public function getModulePath($name)
* @param string $name
* @return string
*/
public function getModelPath($name)
public function getModelPath($name) : string
{
return $this->getWorkingPath() . DIRECTORY_SEPARATOR
. 'application' . DIRECTORY_SEPARATOR
Expand All @@ -150,7 +152,7 @@ public function getModelPath($name)
* @param string $name
* @return bool
*/
public function isModuleExists($name)
public function isModuleExists($name) : bool
{
return is_dir($this->getModulePath($name));
}
Expand All @@ -159,7 +161,7 @@ public function isModuleExists($name)
* @param string $name
* @return bool
*/
public function isModelExists($name)
public function isModelExists($name) : bool
{
return is_dir($this->getModelPath($name));
}
Expand Down
94 changes: 62 additions & 32 deletions src/Command/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

namespace Bluzman\Command;

use Bluz\Validator\Validator as v;
use Bluz\Proxy\Config;
use Bluz\Validator\Validator;
use Bluzman\Application\Application;
use Bluzman\Input\InputArgument;
use Bluzman\Input\InputException;
use Symfony\Component\Console;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -43,7 +45,7 @@ abstract class AbstractCommand extends Console\Command\Command
/**
* @param InputInterface $input
*/
public function setInput(InputInterface $input)
public function setInput(InputInterface $input) : void
{
$this->input = $input;
}
Expand All @@ -59,7 +61,7 @@ public function getInput()
/**
* @param OutputInterface $output
*/
public function setOutput(OutputInterface $output)
public function setOutput(OutputInterface $output) : void
{
$this->output = $output;
}
Expand All @@ -75,7 +77,7 @@ public function getOutput()
/**
* @param \Symfony\Component\Filesystem\Filesystem $fs
*/
public function setFs($fs)
public function setFs($fs) : void
{
$this->fs = $fs;
}
Expand All @@ -92,9 +94,11 @@ public function getFs()
}

/**
* @param InputInterface $input
* @param InputInterface $input
* @param OutputInterface $output
*
* @return void
* @throws \Bluz\Config\ConfigException
*/
final public function initialize(InputInterface $input, OutputInterface $output)
{
Expand All @@ -110,14 +114,14 @@ final public function initialize(InputInterface $input, OutputInterface $output)
$config->setEnvironment($input->getOption('env'));
$config->init();

\Bluz\Proxy\Config::setInstance($config);
Config::setInstance($config);
}

/**
* @param $message
* @return void
*/
public function write($message)
public function write($message) : void
{
$this->getOutput()->writeln($message);
}
Expand All @@ -126,7 +130,7 @@ public function write($message)
* @param $message
* @return void
*/
public function info($message)
public function info($message) : void
{
$this->write("<info>$message</info>");
}
Expand All @@ -135,7 +139,7 @@ public function info($message)
* @param $message
* @return void
*/
public function comment($message)
public function comment($message) : void
{
$this->write("<comment>$message</comment>");
}
Expand All @@ -144,7 +148,7 @@ public function comment($message)
* @param $message
* @return void
*/
public function question($message)
public function question($message) : void
{
$this->write("<question>$message</question>:");
}
Expand All @@ -153,7 +157,7 @@ public function question($message)
* @param $message
* @return void
*/
public function error($message)
public function error($message) : void
{
$this->write("<error>$message</error>");
}
Expand All @@ -170,42 +174,68 @@ public function callForContribute()
}

/**
* addModuleArgument
* Add Module Argument
*
* @param int $required
* @return AbstractCommand
* @return void
*/
protected function addModuleArgument($required = InputArgument::REQUIRED)
protected function addModuleArgument($required = InputArgument::REQUIRED) : void
{
$module = new InputArgument('module', $required, 'Module name is required');
$module->setValidator(
v::create()->string()->alphaNumeric('-_')->noWhitespace()
);

$this->getDefinition()->addArgument($module);
}

return $this;
/**
* Validate Module Argument
*
* @return void
* @throws \Bluzman\Input\InputException
*/
protected function validateModuleArgument() : void
{
$module = $this->getInput()->getArgument('module');

$validator = Validator::create()
->string()
->alphaNumeric('-_')
->noWhitespace();

if ($this->getDefinition()->getArgument('module')->isRequired()
&& !$validator->validate($module)) {
throw new InputException($validator->getError());
}
}

/**
* addControllerArgument
* Add Controller Argument
*
* @param int $required
* @return AbstractCommand
* @return void
*/
protected function addControllerArgument($required = InputArgument::REQUIRED)
protected function addControllerArgument($required = InputArgument::REQUIRED) : void
{
$controller = new InputArgument(
'controller',
$required,
'Controller name is required'
);
$controller->setValidator(
v::create()->string()->alphaNumeric('-_')->noWhitespace()
);

$controller = new InputArgument('controller', $required, 'Controller name is required');
$this->getDefinition()->addArgument($controller);
}

return $this;
/**
* Validate Module Argument
*
* @return void
* @throws \Bluzman\Input\InputException
*/
protected function validateControllerArgument() : void
{
$controller = $this->getInput()->getArgument('controller');

$validator = Validator::create()
->string()
->alphaNumeric('-_')
->noWhitespace();

if ($this->getDefinition()->getArgument('controller')->isRequired()
&& !$validator->validate($controller)) {
throw new InputException($validator->getError());
}
}
}
7 changes: 7 additions & 0 deletions src/Command/Db/AbstractDbCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ protected function execute(InputInterface $input, OutputInterface $output)

$phinxArguments['command'] = $commandName;
$phinxArguments['--configuration'] = PATH_APPLICATION . DS . 'configs' . DS . 'phinx.php';

// write database name to console
// to avoid any mistakes
$config = include $phinxArguments['--configuration'];
$this->write('<info>host</info> ' . $config['environments']['default']['host']);
$this->write('<info>name</info> ' . $config['environments']['default']['name']);

if ($command->getDefinition()->hasOption('environment')) {
$phinxArguments['--environment'] = 'default';
}
Expand Down
4 changes: 0 additions & 4 deletions src/Command/Db/StatusCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,5 @@ protected function configure()
// the "--help" option
->setHelp('This command is shorthand to phinx tool')
;

$env = new InputArgument('--environment', InputArgument::OPTIONAL, 'Environment', 'default');

$this->getDefinition()->addArgument($env);
}
}
Loading

0 comments on commit 6e16590

Please sign in to comment.