-
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
5 changed files
with
184 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?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\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
use function in_array; | ||
use function glob; | ||
use function basename; | ||
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') | ||
->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; | ||
$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(); | ||
|
||
return $profileObject->run($input, $output, $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; | ||
} | ||
} |
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,35 @@ | ||
<?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\Profiles; | ||
|
||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Interface InitProfileInterface | ||
* | ||
* @package Slim\Console\Command\Initializer\Profiles | ||
* @author Temuri Takalandze <me@abgeo.dev> | ||
*/ | ||
interface InitProfileInterface | ||
{ | ||
/** | ||
* Run new project initialization with profile. | ||
* | ||
* @param InputInterface $input | ||
* @param OutputInterface $output | ||
* @param bool $useDefaultSetup If true, use the default settings for the profile, | ||
* otherwise configure the project interactively. | ||
* | ||
* @return int 0 if everything went fine, or an exit code. | ||
*/ | ||
public function run(InputInterface $input, OutputInterface $output, bool $useDefaultSetup = false): int; | ||
} |
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,34 @@ | ||
<?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\Profiles\blank; | ||
|
||
use Slim\Console\Command\Initializer\Profiles\InitProfileInterface; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Init class implementation for profile Blank. | ||
* | ||
* @package Slim\Console\Command\Initializer\Profiles\blank | ||
* @author Temuri Takalandze <me@abgeo.dev> | ||
*/ | ||
class Init implements InitProfileInterface | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function run(InputInterface $input, OutputInterface $output, bool $useDefaultSetup = false): int | ||
{ | ||
$output->writeln('Work In Progress!'); | ||
|
||
return 0; | ||
} | ||
} |
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,7 @@ | ||
# Profile Blank | ||
|
||
Profile doc goes here... | ||
|
||
## Authors | ||
|
||
- [**Temuri Takalandze**](https://abgeo.dev) |