-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from OpenForgeProject/list-themes
add ListThemesCommand
- Loading branch information
Showing
4 changed files
with
101 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,66 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenForgeProject\MageForge\Console\Command; | ||
|
||
use OpenForgeProject\MageForge\Model\ThemeList; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Magento\Framework\Console\Cli; | ||
|
||
class ListThemesCommand extends Command | ||
{ | ||
/** | ||
* Constructor | ||
* | ||
* @param ThemeList $themeList | ||
*/ | ||
public function __construct( | ||
private readonly ThemeList $themeList, | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Configure the command | ||
*/ | ||
protected function configure(): void | ||
{ | ||
$this->setName('mageforge:themes:list'); | ||
$this->setDescription('Lists all available themes'); | ||
} | ||
|
||
/** | ||
* Execute the command | ||
* | ||
* @param InputInterface $input | ||
* @param OutputInterface $output | ||
* @return int | ||
*/ | ||
protected function execute( | ||
InputInterface $input, | ||
OutputInterface $output, | ||
): int { | ||
$themes = $this->themeList->getAllThemes(); | ||
|
||
if (empty($themes)) { | ||
$output->writeln('<info>No themes found.</info>'); | ||
return Cli::RETURN_SUCCESS; | ||
} | ||
|
||
$output->writeln('<info>Available Themes:</info>'); | ||
foreach ($themes as $path => $theme) { | ||
$output->writeln( | ||
sprintf( | ||
'<comment>%s</comment> - %s', | ||
$path, | ||
$theme->getThemeTitle(), | ||
), | ||
); | ||
} | ||
|
||
return Cli::RETURN_SUCCESS; | ||
} | ||
} |
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,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenForgeProject\MageForge\Model; | ||
|
||
use Magento\Framework\View\Design\Theme\ThemeList as MagentoThemeList; | ||
|
||
class ThemeList | ||
{ | ||
/** | ||
* Constructor | ||
* | ||
* @param MagentoThemeList $magentoThemeList | ||
*/ | ||
public function __construct( | ||
private readonly MagentoThemeList $magentoThemeList | ||
) { | ||
} | ||
|
||
/** | ||
* Get all themes | ||
* | ||
* @return array | ||
*/ | ||
public function getAllThemes(): array | ||
{ | ||
return $this->magentoThemeList->getItems(); | ||
} | ||
} |
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