Skip to content

Commit

Permalink
dev 2.0.8: log, code format (#560)
Browse files Browse the repository at this point in the history
dev 2.0.8: log, code format
  • Loading branch information
inhere authored Jan 17, 2020
2 parents afc0dbf + ff5c16d commit 5d35972
Show file tree
Hide file tree
Showing 37 changed files with 303 additions and 304 deletions.
2 changes: 1 addition & 1 deletion src/annotation/src/Resource/AnnotationResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function __construct(array $config = [])
{
// Init $excludedPsr4Prefixes
$this->excludedPsr4Prefixes = self::DEFAULT_EXCLUDED_PSR4_PREFIXES;

// Can set property by array
ObjectHelper::init($this, $config);

Expand Down
31 changes: 17 additions & 14 deletions src/console/src/Input/AbstractInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
use Swoft\Console\Contract\InputInterface;
use Swoft\Console\Exception\CommandFlagException;
use function array_merge;
use function array_values;
use function getcwd;
use function is_bool;
use function is_int;
use function strpos;
use function trim;

/**
Expand Down Expand Up @@ -93,26 +95,27 @@ abstract public function toString(): string;

/**
* find command name. it is first argument.
*
* @param array $flags
*
* @return array
*/
protected function findCommand(): void
protected function findCommand(array $flags): array
{
if (!isset($this->args[0])) {
return;
if (!isset($flags[0])) {
return $flags;
}

$newArgs = [];

foreach ($this->args as $key => $value) {
if ($key === 0) {
$this->command = trim($value);
} elseif (is_int($key)) {
$newArgs[] = $value;
} else {
$newArgs[$key] = $value;
}
// Not input command name
if (strpos($flags[0], '-') === 0) {
return $flags;
}

$this->args = $newArgs;
$this->command = trim($flags[0]);

// remove first element, reset index key.
unset($flags[0]);
return array_values($flags);
}

/***********************************************************************************
Expand Down
9 changes: 4 additions & 5 deletions src/console/src/Input/Input.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,13 @@ public function __construct(array $args = null, bool $parsing = true)
$this->scriptFile = array_shift($args);
$this->fullScript = implode(' ', $args);

$this->flags = $args;
// find command name, other is flags
$this->flags = $this->findCommand($args);
$this->pwd = $this->getPwd();

if ($parsing) {
// list($this->args, $this->sOpts, $this->lOpts) = InputParser::fromArgv($args);
[$this->args, $this->sOpts, $this->lOpts] = Flags::parseArgv($args);

// find command name
$this->findCommand();
[$this->args, $this->sOpts, $this->lOpts] = Flags::parseArgv($this->flags);
}
}

Expand Down Expand Up @@ -133,6 +131,7 @@ public function parseFlags(array $info, bool $binding = false): void
}
}

// re-parsing
if ($this->flags) {
[$this->args, $this->sOpts, $this->lOpts] = Flags::parseArgv($this->flags, $config);

Expand Down
3 changes: 3 additions & 0 deletions src/console/test/unit/Input/InputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public function testInput(): void
$in = new Input($args);

$this->assertSame('input:test', $in->getCommand());
$this->assertSame([], $in->getArgs());
$this->assertSame(['-d', '12'], $in->getFlags());
$this->assertSame(['d' => '12'], $in->getOpts());
}

/**
Expand Down
25 changes: 9 additions & 16 deletions src/framework/run.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,21 @@
}
unset($file);
if (!defined('PHPUNIT_COMPOSER_INSTALL')) {
fwrite(STDERR,
'You need to set up the project dependencies using Composer:' . PHP_EOL . PHP_EOL . ' composer install' . PHP_EOL . PHP_EOL . 'You can learn all about Composer on https://getcomposer.org/.' . PHP_EOL);
$tips = <<<TXT
You need to set up the project dependencies using Composer:
composer install
You can learn all about Composer on https://getcomposer.org/
TXT;

fwrite(STDERR, $tips . PHP_EOL);
die(1);
} else {
if (array_reverse(explode('/', __DIR__))[0] ?? '' === 'tests') {
$vendor_dir = dirname(PHPUNIT_COMPOSER_INSTALL);
$bin_unit = "{$vendor_dir}/bin/phpunit";
$unit_uint = "{$vendor_dir}/phpunit/phpunit/phpunit";
if (file_exists($bin_unit)) {
@unlink($bin_unit);
@symlink(__FILE__, $bin_unit);
}
if (file_exists($unit_uint)) {
@unlink($unit_uint);
@symlink(__FILE__, $unit_uint);
}
}
}

if (!in_array('-c', $_SERVER['argv'])) {
$_SERVER['argv'][] = '-c';
$_SERVER['argv'][] = __DIR__ . '/phpunit.xml';
}

require PHPUNIT_COMPOSER_INSTALL;

$status = 0;
Expand Down
102 changes: 102 additions & 0 deletions src/framework/src/Concern/SwoftTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,44 @@
*/
trait SwoftTrait
{
/**
* @var bool
*/
protected $startConsole = true;

/**
* Can disable processor class before handle.
* eg.
* [
* Swoft\Processor\ConsoleProcessor::class => 1,
* ]
*
* @var array
*/
private $disabledProcessors = [];

/**
* Can disable AutoLoader class before handle.
* eg.
* [
* Swoft\Console\AutoLoader::class => 1,
* ]
*
* @var array
*/
private $disabledAutoLoaders = [];

/**
* Scans containing these namespace prefixes will be excluded.
*
* @var array
* eg.
* [
* 'PHPUnit\\',
* ]
*/
private $disabledPsr4Prefixes = [];

/**
* Get env name
*
Expand Down Expand Up @@ -186,4 +224,68 @@ public function afterConsole(): bool
{
return true;
}

/**
* @return array
*/
public function getDisabledProcessors(): array
{
return $this->disabledProcessors;
}

/**
* @return array
*/
public function getDisabledAutoLoaders(): array
{
return $this->disabledAutoLoaders;
}

/**
* @return array
*/
public function getDisabledPsr4Prefixes(): array
{
return $this->disabledPsr4Prefixes;
}

/**
* @param array $disabledAutoLoaders
*/
public function setDisabledAutoLoaders(array $disabledAutoLoaders): void
{
$this->disabledAutoLoaders = $disabledAutoLoaders;
}

/**
* @param array $disabledPsr4Prefixes
*/
public function setDisabledPsr4Prefixes(array $disabledPsr4Prefixes): void
{
$this->disabledPsr4Prefixes = $disabledPsr4Prefixes;
}

/**
* @param array $disabledProcessors
*/
public function setDisabledProcessors(array $disabledProcessors): void
{
$this->disabledProcessors = $disabledProcessors;
}

/**
* @return bool
*/
public function isStartConsole(): bool
{
return $this->startConsole;
}

/**
* @param bool $startConsole
*/
public function setStartConsole($startConsole): void
{
$this->startConsole = (bool)$startConsole;
}
}
2 changes: 0 additions & 2 deletions src/framework/src/Contract/SwoftInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
*/
interface SwoftInterface
{
public const VERSION = '1.0.0';

/**
* Get env name
*
Expand Down
4 changes: 3 additions & 1 deletion src/framework/src/Processor/ConsoleProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public function handle(): bool
CLog::info('Console command route registered (group %d, command %d)', $router->groupCount(), $router->count());

// Run console application
bean('cliApp')->run();
if ($this->application->isStartConsole()) {
bean('cliApp')->run();
}

return $this->application->afterConsole();
}
Expand Down
2 changes: 1 addition & 1 deletion src/framework/src/Swoft.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class Swoft
/**
* Swoft version
*/
public const VERSION = '2.0.7';
public const VERSION = '2.0.8';

/**
* Swoft terminal logo
Expand Down
61 changes: 2 additions & 59 deletions src/framework/src/SwoftApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,47 +91,14 @@ class SwoftApplication implements SwoftInterface, ApplicationInterface
*/
private $processor;

/**
* Can disable processor class before handle.
* eg.
* [
* Swoft\Processor\ConsoleProcessor::class => 1,
* ]
*
* @var array
*/
private $disabledProcessors = [];

/**
* Can disable AutoLoader class before handle.
* eg.
* [
* Swoft\Console\AutoLoader::class => 1,
* ]
*
* @var array
*/
private $disabledAutoLoaders = [];

/**
* Scans containing these namespace prefixes will be excluded.
*
* @var array
* eg.
* [
* 'PHPUnit\\',
* ]
*/
private $disabledPsr4Prefixes = [];

/**
* Get the application version
*
* @return string
*/
public static function getVersion(): string
public function getVersion(): string
{
return self::VERSION;
return Swoft::VERSION;
}

/**
Expand Down Expand Up @@ -304,30 +271,6 @@ protected function processors(): array
];
}

/**
* @return array
*/
public function getDisabledProcessors(): array
{
return $this->disabledProcessors;
}

/**
* @return array
*/
public function getDisabledAutoLoaders(): array
{
return $this->disabledAutoLoaders;
}

/**
* @return array
*/
public function getDisabledPsr4Prefixes(): array
{
return $this->disabledPsr4Prefixes;
}

/**
* @param string $beanFile
*/
Expand Down
Loading

0 comments on commit 5d35972

Please sign in to comment.