-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
1,196 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,62 @@ | ||
{ | ||
"name": "slim/console", | ||
"type": "library", | ||
"description": "Slim Console", | ||
"keywords": ["framework","php","slim"], | ||
"homepage": "https://www.slimframework.com", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Pierre Berube", | ||
"email": "pierre@lgse.com", | ||
"homepage": "http://www.lgse.com" | ||
} | ||
], | ||
"require": { | ||
"ext-json": "*", | ||
"php": "^7.2", | ||
"symfony/console": "^5.0" | ||
}, | ||
"require-dev": { | ||
"adriansuter/php-autoload-override": "^1.1", | ||
"phpspec/prophecy": "^1.10", | ||
"phpstan/phpstan": "^0.12.25", | ||
"phpunit/phpunit": "^8.5", | ||
"squizlabs/php_codesniffer": "^3.5" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Slim\\Console\\": "src" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Slim\\Tests\\Console\\": "tests" | ||
} | ||
"name": "slim/console", | ||
"type": "library", | ||
"description": "Slim Console", | ||
"keywords": [ | ||
"framework", | ||
"php", | ||
"slim" | ||
], | ||
"homepage": "https://www.slimframework.com", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Pierre Berube", | ||
"email": "pierre@lgse.com", | ||
"homepage": "http://www.lgse.com" | ||
}, | ||
"scripts": { | ||
"test": [ | ||
"@phpunit", | ||
"@phpcs", | ||
"@phpstan" | ||
], | ||
"phpunit": "phpunit", | ||
"phpcs": "phpcs", | ||
"phpstan": "phpstan analyse src --memory-limit=-1" | ||
}, | ||
"config": { | ||
"sort-packages": true | ||
}, | ||
"bin": ["bin/slim"] | ||
{ | ||
"name": "Temuri Takalandze", | ||
"email": "me@abgeo.dev", | ||
"homepage": "https://abgeo.dev" | ||
} | ||
], | ||
"require": { | ||
"ext-json": "*", | ||
"php": "^7.2", | ||
"symfony/console": "^5.0" | ||
}, | ||
"require-dev": { | ||
"adriansuter/php-autoload-override": "^1.1", | ||
"phpspec/prophecy": "^1.10", | ||
"phpstan/phpstan": "^0.12.25", | ||
"phpunit/phpunit": "^8.5", | ||
"squizlabs/php_codesniffer": "^3.5" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Slim\\Console\\": "src" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Slim\\Tests\\Console\\": "tests" | ||
} | ||
}, | ||
"scripts": { | ||
"test": [ | ||
"@phpunit", | ||
"@phpcs", | ||
"@phpstan" | ||
], | ||
"phpunit": "phpunit", | ||
"phpcs": "phpcs", | ||
"phpstan": "phpstan analyse src --memory-limit=-1" | ||
}, | ||
"config": { | ||
"sort-packages": true | ||
}, | ||
"bin": [ | ||
"bin/slim" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
|
||
/** | ||
* Slim Framework (https://slimframework.com) | ||
* | ||
* @license https://github.com/slimphp/Slim-Console/blob/0.x/LICENSE.md (MIT License) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Slim\Console\Command\Initializer; | ||
|
||
use Slim\Console\Command\AbstractCommand; | ||
use Slim\Console\Command\Initializer\Profiles\InitProfileInterface; | ||
use Symfony\Component\Console\Exception\InvalidOptionException; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
use function basename; | ||
use function glob; | ||
use function in_array; | ||
use function is_array; | ||
use function is_string; | ||
|
||
/** | ||
* Class InitCommand. | ||
* | ||
* @package Slim\Console\Command\Initializer | ||
* @author Temuri Takalandze <me@abgeo.dev> | ||
*/ | ||
class InitCommand extends AbstractCommand | ||
{ | ||
protected const PROFILE_NAMESPACE_PREFIX = "Slim\Console\Command\Initializer\Profiles"; | ||
protected const PROFILE_INIT_CLASS = "Init"; | ||
|
||
protected static $defaultName = 'init'; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected function configure(): void | ||
{ | ||
$this | ||
->setDescription('Initialize a new Slim project') | ||
->addArgument( | ||
'directory', | ||
InputArgument::REQUIRED, | ||
'Directory of the project to create' | ||
) | ||
->addOption( | ||
'profile', | ||
'p', | ||
InputOption::VALUE_REQUIRED, | ||
'New Slim project skeleton profile', | ||
'blank' | ||
) | ||
->addOption( | ||
'default', | ||
null, | ||
InputOption::VALUE_NONE, | ||
'Use default setup' | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$profileObject = null; | ||
$directory = $input->getArgument('directory'); | ||
$directory = is_string($directory) ? $directory : 'new-slim-project'; | ||
$profile = $input->getOption('profile'); | ||
$profile = is_string($profile) ? $profile : 'blank'; | ||
$useDefaultSetup = (bool)$input->getOption('default'); | ||
|
||
if (!in_array($profile, $this->getAvailableProfiles())) { | ||
throw new InvalidOptionException("Profile `{$profile}` not found!"); | ||
} | ||
|
||
$profile = self::PROFILE_NAMESPACE_PREFIX . "\\{$profile}\\" . self::PROFILE_INIT_CLASS; | ||
/** @var InitProfileInterface $profileObject */ | ||
$profileObject = new $profile($input, $output, $this->getConfig()); | ||
|
||
return $profileObject->run($directory, $useDefaultSetup); | ||
} | ||
|
||
/** | ||
* Get available initialization profiles. | ||
* | ||
* @return array<string> | ||
*/ | ||
private function getAvailableProfiles(): array | ||
{ | ||
$profiles = []; | ||
$glob = glob(__DIR__ . DIRECTORY_SEPARATOR . 'Profiles' . DIRECTORY_SEPARATOR . '*', GLOB_ONLYDIR); | ||
|
||
if (is_array($glob)) { | ||
foreach ($glob as $profile) { | ||
$profiles[] = basename($profile); | ||
} | ||
} | ||
|
||
return $profiles; | ||
} | ||
} |
Oops, something went wrong.