-
-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Live] override data collector & debug command
- Loading branch information
Showing
12 changed files
with
181 additions
and
23 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
27 changes: 27 additions & 0 deletions
27
src/LiveComponent/src/Command/LiveComponentDebugCommand.php
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,27 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\UX\LiveComponent\Command; | ||
|
||
use Symfony\UX\TwigComponent\Command\TwigComponentDebugCommand; | ||
|
||
/** | ||
* @author Kevin Bond <kevinbond@gmail.com> | ||
*/ | ||
final class LiveComponentDebugCommand extends TwigComponentDebugCommand | ||
{ | ||
protected function configure(): void | ||
{ | ||
parent::configure(); | ||
|
||
$this->setAliases(['debug:live-component']); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/LiveComponent/src/DataCollector/LiveComponentDataCollector.php
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,27 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\UX\LiveComponent\DataCollector; | ||
|
||
use Symfony\UX\TwigComponent\DataCollector\TwigComponentDataCollector; | ||
|
||
/** | ||
* @author Kevin Bond <kevinbond@gmail.com> | ||
* | ||
* @internal | ||
*/ | ||
final class LiveComponentDataCollector extends TwigComponentDataCollector | ||
{ | ||
public function getName(): string | ||
{ | ||
return 'live_component'; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/LiveComponent/src/DependencyInjection/Compiler/DebugLiveComponentPass.php
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,46 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\UX\LiveComponent\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\UX\LiveComponent\Command\LiveComponentDebugCommand; | ||
use Symfony\UX\LiveComponent\DataCollector\LiveComponentDataCollector; | ||
|
||
/** | ||
* @author Kevin Bond <kevinbond@gmail.com> | ||
* | ||
* @internal | ||
*/ | ||
final class DebugLiveComponentPass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container): void | ||
{ | ||
if (!$container->hasDefinition('ux.twig_component.data_collector')) { | ||
return; | ||
} | ||
|
||
$container->getDefinition('ux.twig_component.data_collector') | ||
->setClass(LiveComponentDataCollector::class) | ||
->clearTag('data_collector') | ||
->addTag('data_collector', [ | ||
'template' => '@LiveComponent/Collector/live_component.html.twig', | ||
'id' => 'live_component', | ||
'priority' => 256, | ||
]); | ||
|
||
$container->getDefinition('ux.twig_component.command.debug') | ||
->setClass(LiveComponentDebugCommand::class) | ||
->addTag('console.command', ['command' => 'debug:live-component']) | ||
; | ||
} | ||
} |
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 @@ | ||
{% extends '@TwigComponent/Collector/twig_component.html.twig' %} |
45 changes: 45 additions & 0 deletions
45
src/LiveComponent/tests/Functional/Command/LiveComponentDebugCommandTest.php
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,45 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\UX\LiveComponent\Tests\Functional\Command; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Console\Application; | ||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
|
||
/** | ||
* @author Kevin Bond <kevinbond@gmail.com> | ||
*/ | ||
final class LiveComponentDebugCommandTest extends KernelTestCase | ||
{ | ||
public function testWithNoComponent(): void | ||
{ | ||
$commandTester = $this->createCommandTester(); | ||
$commandTester->execute([]); | ||
|
||
$commandTester->assertCommandIsSuccessful(); | ||
|
||
$display = $commandTester->getDisplay(); | ||
|
||
$this->assertStringContainsString('Component', $display); | ||
$this->assertStringContainsString('Class', $display); | ||
$this->assertStringContainsString('Template', $display); | ||
$this->assertStringContainsString('Type', $display); | ||
} | ||
|
||
private function createCommandTester(): CommandTester | ||
{ | ||
$kernel = self::bootKernel(); | ||
$application = new Application($kernel); | ||
|
||
return new CommandTester($application->find('debug:twig-component')); | ||
} | ||
} |
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
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