-
-
Notifications
You must be signed in to change notification settings - Fork 169
[Maker] Resource, State provider and state processor makers #705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
loic425
wants to merge
6
commits into
Sylius:1.11
Choose a base branch
from
loic425:feature/make-resource
base: 1.11
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c85aa8b
[Maker] Resource, State provider and state processor makers
loic425 2c3d162
Move tmp directory to fix the Doctrine configuration
loic425 80550f8
Fix testing makers
loic425 0478696
Fix coding standard
loic425 638cc70
Fix PHPUnit tests
loic425 b414aba
Fix coding standard
loic425 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
47 changes: 47 additions & 0 deletions
47
src/Bundle/DependencyInjection/Compiler/RegisterStubCommandsPass.php
This file contains hidden or 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,47 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of the Sylius package. | ||
| * | ||
| * (c) Sylius Sp. z o.o. | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler; | ||
|
|
||
| use Sylius\Component\Resource\Symfony\Command\StubMakeResource; | ||
| use Sylius\Component\Resource\Symfony\Maker\MakeResource; | ||
| use Symfony\Bundle\MakerBundle\MakerBundle; | ||
| use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
| use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
|
||
| final class RegisterStubCommandsPass implements CompilerPassInterface | ||
| { | ||
| /** | ||
| * @inheritdoc | ||
| */ | ||
| public function process(ContainerBuilder $container): void | ||
| { | ||
| if (!$this->isMakerEnabled($container)) { | ||
| $container->register(StubMakeResource::class)->setClass(StubMakeResource::class)->addTag('console.command'); | ||
| $container->removeDefinition('sylius.maker.resource'); | ||
| $container->removeAlias(MakeResource::class); | ||
| } | ||
| } | ||
|
|
||
| private function isMakerEnabled(ContainerBuilder $container): bool | ||
| { | ||
| if (!class_exists(MakerBundle::class)) { | ||
| return false; | ||
| } | ||
|
|
||
| /** @var array $bundles */ | ||
| $bundles = $container->getParameter('kernel.bundles'); | ||
|
|
||
| return in_array(MakerBundle::class, $bundles, true); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
|
|
||
| <!-- | ||
|
|
||
| This file is part of the Sylius package. | ||
|
|
||
| (c) Paweł Jędrzejewski | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. --- (c) Paweł Jędrzejewski
+++ (c) Sylius Sp. z o.o. |
||
|
|
||
| For the full copyright and license information, please view the LICENSE | ||
| file that was distributed with this source code. | ||
|
|
||
| --> | ||
|
|
||
| <container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
| <services> | ||
| <service id="sylius.maker.generator.resource" class="Sylius\Component\Resource\Symfony\Maker\Generator\ResourceClassGenerator"> | ||
| <argument type="service" id="maker.generator" /> | ||
| </service> | ||
|
|
||
| <service id="sylius.maker.generator.repository" class="Sylius\Component\Resource\Symfony\Maker\Generator\RepositoryClassGenerator"> | ||
| <argument type="service" id="maker.generator" /> | ||
| </service> | ||
|
|
||
| <service id="sylius.maker.resource" class="Sylius\Component\Resource\Symfony\Maker\MakeResource"> | ||
| <argument type="service" id="maker.generator" /> | ||
| <argument type="service" id="sylius.maker.generator.resource" /> | ||
| <argument type="service" id="sylius.maker.generator.repository" /> | ||
| <argument type="service" id="maker.file_manager" /> | ||
| <tag name="maker.command" /> | ||
| </service> | ||
|
|
||
| <service id="sylius.maker.state_provider" class="Sylius\Component\Resource\Symfony\Maker\MakeStateProvider"> | ||
| <tag name="maker.command" /> | ||
| </service> | ||
|
|
||
| <service id="sylius.maker.state_processor" class="Sylius\Component\Resource\Symfony\Maker\MakeStateProcessor"> | ||
| <tag name="maker.command" /> | ||
| </service> | ||
| </services> | ||
| </container> | ||
This file contains hidden or 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
70 changes: 70 additions & 0 deletions
70
src/Bundle/Tests/DependencyInjection/Compiler/RegisterStubCommandsPassTest.php
This file contains hidden or 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,70 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of the Sylius package. | ||
| * | ||
| * (c) Sylius Sp. z o.o. | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace DependencyInjection\Compiler; | ||
|
|
||
| use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; | ||
| use Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\RegisterStubCommandsPass; | ||
| use Sylius\Component\Resource\Symfony\Command\StubMakeResource; | ||
| use Sylius\Component\Resource\Symfony\Maker\MakeResource; | ||
| use Symfony\Bundle\MakerBundle\MakerBundle; | ||
| use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
|
||
| final class RegisterStubCommandsPassTest extends AbstractCompilerPassTestCase | ||
| { | ||
| /** @test */ | ||
| public function it_registers_stub_commands_when_maker_is_not_registered(): void | ||
| { | ||
| $this->compile(); | ||
|
|
||
| $this->assertContainerBuilderHasService(StubMakeResource::class, StubMakeResource::class); | ||
| } | ||
|
|
||
| /** @test */ | ||
| public function it_does_not_register_stub_commands_when_maker_is_registered(): void | ||
| { | ||
| $this->setParameter('kernel.bundles', [MakerBundle::class]); | ||
|
|
||
| $this->compile(); | ||
|
|
||
| $this->assertContainerBuilderNotHasService(StubMakeResource::class); | ||
| } | ||
|
|
||
| /** @test */ | ||
| public function it_unregisters_definition_for_grid_maker_when_maker_is_not_registered(): void | ||
| { | ||
| $this->registerService('sylius.maker.resource', MakeResource::class); | ||
|
|
||
| $this->compile(); | ||
|
|
||
| $this->assertContainerBuilderNotHasService(MakeResource::class); | ||
| } | ||
|
|
||
| /** @test */ | ||
| public function it_does_not_unregister_definition_for_grid_maker_when_maker_is_registered(): void | ||
| { | ||
| $this->setParameter('kernel.bundles', [MakerBundle::class]); | ||
| $this->registerService('sylius.maker.resource', MakeResource::class); | ||
|
|
||
| $this->compile(); | ||
|
|
||
| $this->assertContainerBuilderHasService('sylius.maker.resource', MakeResource::class); | ||
| } | ||
|
|
||
| protected function registerCompilerPass(ContainerBuilder $container): void | ||
| { | ||
| $this->setParameter('kernel.bundles', []); | ||
|
|
||
| $container->addCompilerPass(new RegisterStubCommandsPass()); | ||
| } | ||
| } |
This file contains hidden or 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,33 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of the Sylius package. | ||
| * | ||
| * (c) Sylius Sp. z o.o. | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Sylius\Component\Resource\Symfony\Command; | ||
|
|
||
| use Symfony\Component\Console\Command\Command; | ||
| use Symfony\Component\Console\Input\InputInterface; | ||
| use Symfony\Component\Console\Output\OutputInterface; | ||
| use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
|
||
| abstract class StubCommand extends Command | ||
| { | ||
| protected function execute(InputInterface $input, OutputInterface $output) | ||
| { | ||
| (new SymfonyStyle($input, $output)) | ||
| ->error( | ||
| \sprintf("To run \"%s\" you need the \"%s\" which is currently not installed.\n\nTry running \"composer require %s\".", static::$defaultName ?? '', 'MakerBundle', 'symfony/maker-bundle --dev'), | ||
| ) | ||
| ; | ||
|
|
||
| return 0; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exit codes consts are available since Symfony 5.4, so it could/should be used over here, but I'm unsure if it's within scope of this PR. public const SUCCESS = 0;
public const FAILURE = 1;
public const INVALID = 2;--- return 0;
+++ return Command::SUCCESS; |
||
| } | ||
| } | ||
This file contains hidden or 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,19 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of the Sylius package. | ||
| * | ||
| * (c) Sylius Sp. z o.o. | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Sylius\Component\Resource\Symfony\Command; | ||
|
|
||
| final class StubMakeResource extends StubCommand | ||
| { | ||
| protected static $defaultName = 'make:resource'; | ||
| } |
41 changes: 41 additions & 0 deletions
41
src/Component/Symfony/Maker/Generator/RepositoryClassGenerator.php
This file contains hidden or 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,41 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of the Sylius package. | ||
| * | ||
| * (c) Sylius Sp. z o.o. | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Sylius\Component\Resource\Symfony\Maker\Generator; | ||
|
|
||
| use Symfony\Bundle\MakerBundle\Generator; | ||
| use Symfony\Bundle\MakerBundle\Str; | ||
| use Symfony\Bundle\MakerBundle\Util\ClassNameDetails; | ||
|
|
||
| /** | ||
| * @internal | ||
| */ | ||
| final class RepositoryClassGenerator | ||
| { | ||
| public function __construct( | ||
| private Generator $generator, | ||
| ) { | ||
| } | ||
|
|
||
| public function generateRepositoryClass(ClassNameDetails $repositoryClassDetails, ClassNameDetails $resourceClassDetails): string | ||
| { | ||
| return $this->generator->generateClass( | ||
| $repositoryClassDetails->getFullName(), | ||
| dirname(__DIR__) . '/Resources/skeleton/Repository.tpl.php', | ||
| [ | ||
| 'entity_class_name' => $resourceClassDetails->getShortName(), | ||
| 'entity_namespace' => Str::getNamespace($resourceClassDetails->getFullName()), | ||
| ], | ||
| ); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic skips case when the maker bundle is installed, but it turned off in the given env