-
-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Way to get the list of available components in current theme
- Loading branch information
Showing
6 changed files
with
128 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\UX\Toolkit\Command; | ||
|
||
use Symfony\Component\Console\Attribute\AsCommand; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
use Symfony\UX\Toolkit\ComponentRepository\CurrentTheme; | ||
use Symfony\UX\Toolkit\Registry\RegistryFactory; | ||
|
||
/** | ||
* @author Jean-François Lépine | ||
* | ||
* @internal | ||
*/ | ||
#[AsCommand( | ||
name: 'debug:ux:toolkit', | ||
description: 'This command list all components available in the current theme.' | ||
)] | ||
class DebugUxToolkitCommand extends Command | ||
{ | ||
public function __construct( | ||
private readonly CurrentTheme $currentTheme, | ||
private readonly RegistryFactory $registryFactory, | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
protected function configure(): void | ||
{ | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$io = new SymfonyStyle($input, $output); | ||
|
||
$repository = $this->currentTheme->getIdentity(); | ||
$finder = $this->currentTheme->getRepository()->fetch($repository); | ||
$registry = $this->registryFactory->create($finder); | ||
|
||
$io->title('Current theme:'); | ||
$io->note('Update your config/packages/ux_toolkit.yaml to change the current theme.'); | ||
$io->table(['Vendor', 'Package'], [[$repository->getVendor(), $repository->getPackage()]]); | ||
|
||
$io->title('Available components:'); | ||
$table = []; | ||
foreach ($registry->all() as $component) { | ||
$table[] = [$component->name]; | ||
} | ||
|
||
$io->table(['Component'], $table); | ||
|
||
$io->note('Run "symfony console ux:toolkit:install <component>" to install a component.'); | ||
|
||
return Command::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
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
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,40 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\UX\Toolkit\Tests\Command; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
use Zenstruck\Console\Test\InteractsWithConsole; | ||
|
||
/** | ||
* @author Jean-François Lépine | ||
*/ | ||
class UxToolkitDebugCommandTest extends KernelTestCase | ||
{ | ||
use InteractsWithConsole; | ||
|
||
public function testShouldBeAbleToLiseComponents(): void | ||
{ | ||
$destination = sys_get_temp_dir().\DIRECTORY_SEPARATOR.uniqid(); | ||
mkdir($destination); | ||
|
||
$this->bootKernel(); | ||
$this->consoleCommand('debug:ux:toolkit') | ||
->execute() | ||
->assertSuccessful() | ||
->assertOutputContains('Current theme:') | ||
->assertOutputContains('Available components:') | ||
->assertOutputContains('Badge') | ||
->assertOutputContains('Button') | ||
; | ||
} | ||
} |
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