diff --git a/src/Bundle/Resources/config/services/maker.xml b/src/Bundle/Resources/config/services/maker.xml
index 33aca83b7..4e0bdf995 100644
--- a/src/Bundle/Resources/config/services/maker.xml
+++ b/src/Bundle/Resources/config/services/maker.xml
@@ -28,5 +28,13 @@
+
+
+
+
+
+
+
+
diff --git a/src/Component/Symfony/Maker/Generator/RepositoryClassGenerator.php b/src/Component/Symfony/Maker/Generator/RepositoryClassGenerator.php
index 7309a1112..97e39be4a 100644
--- a/src/Component/Symfony/Maker/Generator/RepositoryClassGenerator.php
+++ b/src/Component/Symfony/Maker/Generator/RepositoryClassGenerator.php
@@ -31,7 +31,7 @@ public function generateRepositoryClass(ClassNameDetails $repositoryClassDetails
{
return $this->generator->generateClass(
$repositoryClassDetails->getFullName(),
- dirname(__DIR__, 2) . '/Bundle/Resources/config/skeleton/Repository.tpl.php',
+ dirname(__DIR__) . '/Resources/skeleton/Repository.tpl.php',
[
'entity_class_name' => $resourceClassDetails->getShortName(),
'entity_namespace' => Str::getNamespace($resourceClassDetails->getFullName()),
diff --git a/src/Component/Symfony/Maker/Generator/ResourceClassGenerator.php b/src/Component/Symfony/Maker/Generator/ResourceClassGenerator.php
index 885d06216..e931525ea 100644
--- a/src/Component/Symfony/Maker/Generator/ResourceClassGenerator.php
+++ b/src/Component/Symfony/Maker/Generator/ResourceClassGenerator.php
@@ -42,7 +42,7 @@ public function generateResourceClass(
return $this->generator->generateClass(
$resourceClassDetails->getFullName(),
- dirname(__DIR__, 2) . '/Bundle/Resources/config/skeleton/' . $skeletonName,
+ dirname(__DIR__) . '/Resources/skeleton/' . $skeletonName,
[
'class_name_without_suffix' => $shortName,
'show_template_dir' => \strtolower($shortName),
diff --git a/src/Component/Symfony/Maker/MakeResource.php b/src/Component/Symfony/Maker/MakeResource.php
index 875bb54de..6911d3146 100644
--- a/src/Component/Symfony/Maker/MakeResource.php
+++ b/src/Component/Symfony/Maker/MakeResource.php
@@ -44,29 +44,45 @@ public function __construct(
) {
}
+ /**
+ * {@inheritdoc}
+ */
public static function getCommandName(): string
{
return 'make:resource';
}
+ /**
+ * {@inheritdoc}
+ */
public static function getCommandDescription(): string
{
return 'Creates a Resource class';
}
+ /**
+ * {@inheritdoc}
+ */
public function configureCommand(Command $command, InputConfiguration $inputConfig): void
{
$command
->setDescription(self::getCommandDescription())
->addArgument('name', InputArgument::OPTIONAL, 'Class name of the resource to create')
->addOption('is-entity', null, InputOption::VALUE_NONE, 'Do you want to store resource data in the database (via Doctrine)?')
+ ->setHelp(file_get_contents(__DIR__.'/Resources/help/MakeResource.txt'))
;
}
+ /**
+ * {@inheritdoc}
+ */
public function configureDependencies(DependencyBuilder $dependencies): void
{
}
+ /**
+ * {@inheritdoc}
+ */
public function interact(InputInterface $input, ConsoleStyle $io, Command $command): void
{
$resourceIsEntity = $io->confirm(
@@ -79,6 +95,9 @@ class_exists(DoctrineBundle::class),
}
}
+ /**
+ * {@inheritdoc}
+ */
public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator): void
{
/** @var string $name */
diff --git a/src/Component/Symfony/Maker/MakeStateProcessor.php b/src/Component/Symfony/Maker/MakeStateProcessor.php
new file mode 100644
index 000000000..3690bdf91
--- /dev/null
+++ b/src/Component/Symfony/Maker/MakeStateProcessor.php
@@ -0,0 +1,82 @@
+
+ *
+ * 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;
+
+use Symfony\Bundle\MakerBundle\ConsoleStyle;
+use Symfony\Bundle\MakerBundle\DependencyBuilder;
+use Symfony\Bundle\MakerBundle\Generator;
+use Symfony\Bundle\MakerBundle\InputConfiguration;
+use Symfony\Bundle\MakerBundle\Maker\AbstractMaker;
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputInterface;
+
+final class MakeStateProcessor extends AbstractMaker
+{
+ /**
+ * {@inheritdoc}
+ */
+ public static function getCommandName(): string
+ {
+ return 'make:sylius-state-processor';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getCommandDescription(): string
+ {
+ return 'Creates a Sylius state processor';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function configureCommand(Command $command, InputConfiguration $inputConfig): void
+ {
+ $command
+ ->addArgument('name', InputArgument::REQUIRED, 'Choose a class name for your state processor (e.g. AwesomeStateProcessor>)')
+ ->setHelp(file_get_contents(__DIR__.'/Resources/help/MakeStateProcessor.txt'))
+ ;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function configureDependencies(DependencyBuilder $dependencies): void
+ {
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator): void
+ {
+ $stateProcessorClassNameDetails = $generator->createClassNameDetails(
+ $input->getArgument('name'),
+ 'State\\'
+ );
+
+ $generator->generateClass(
+ $stateProcessorClassNameDetails->getFullName(),
+ __DIR__.'/Resources/skeleton/StateProcessor.tpl.php'
+ );
+ $generator->writeChanges();
+
+ $this->writeSuccessMessage($io);
+ $io->text([
+ 'Next: Open your new state processor class and start customizing it.',
+ ]);
+ }
+}
diff --git a/src/Component/Symfony/Maker/MakeStateProvider.php b/src/Component/Symfony/Maker/MakeStateProvider.php
new file mode 100644
index 000000000..4e8ebf1a0
--- /dev/null
+++ b/src/Component/Symfony/Maker/MakeStateProvider.php
@@ -0,0 +1,82 @@
+
+ *
+ * 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;
+
+use Symfony\Bundle\MakerBundle\ConsoleStyle;
+use Symfony\Bundle\MakerBundle\DependencyBuilder;
+use Symfony\Bundle\MakerBundle\Generator;
+use Symfony\Bundle\MakerBundle\InputConfiguration;
+use Symfony\Bundle\MakerBundle\Maker\AbstractMaker;
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputInterface;
+
+final class MakeStateProvider extends AbstractMaker
+{
+ /**
+ * {@inheritdoc}
+ */
+ public static function getCommandName(): string
+ {
+ return 'make:sylius-state-provider';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getCommandDescription(): string
+ {
+ return 'Creates a Sylius state provider';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function configureCommand(Command $command, InputConfiguration $inputConfig): void
+ {
+ $command
+ ->addArgument('name', InputArgument::REQUIRED, 'Choose a class name for your state provider (e.g. AwesomeStateProvider>)')
+ ->setHelp(file_get_contents(__DIR__.'/Resources/help/MakeStateProvider.txt'))
+ ;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function configureDependencies(DependencyBuilder $dependencies): void
+ {
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator): void
+ {
+ $stateProviderClassNameDetails = $generator->createClassNameDetails(
+ $input->getArgument('name'),
+ 'State\\'
+ );
+
+ $generator->generateClass(
+ $stateProviderClassNameDetails->getFullName(),
+ __DIR__.'/Resources/skeleton/StateProvider.tpl.php'
+ );
+ $generator->writeChanges();
+
+ $this->writeSuccessMessage($io);
+ $io->text([
+ 'Next: Open your new state provider class and start customizing it.',
+ ]);
+ }
+}
diff --git a/src/Component/Symfony/Maker/Resources/help/MakeResource.txt b/src/Component/Symfony/Maker/Resources/help/MakeResource.txt
new file mode 100644
index 000000000..116130e71
--- /dev/null
+++ b/src/Component/Symfony/Maker/Resources/help/MakeResource.txt
@@ -0,0 +1,5 @@
+The %command.name% command generates a new Sylius resource class.
+
+php %command.full_name% Book
+
+If the argument is missing, the command will ask for the class name interactively.
diff --git a/src/Component/Symfony/Maker/Resources/help/MakeStateProcessor.txt b/src/Component/Symfony/Maker/Resources/help/MakeStateProcessor.txt
new file mode 100644
index 000000000..21dc2420e
--- /dev/null
+++ b/src/Component/Symfony/Maker/Resources/help/MakeStateProcessor.txt
@@ -0,0 +1,5 @@
+The %command.name% command generates a new Sylius state processor class.
+
+php %command.full_name% AwesomeStateProcessor
+
+If the argument is missing, the command will ask for the class name interactively.
diff --git a/src/Component/Symfony/Maker/Resources/help/MakeStateProvider.txt b/src/Component/Symfony/Maker/Resources/help/MakeStateProvider.txt
new file mode 100644
index 000000000..0f538557a
--- /dev/null
+++ b/src/Component/Symfony/Maker/Resources/help/MakeStateProvider.txt
@@ -0,0 +1,5 @@
+The %command.name% command generates a new Sylius state provider class.
+
+php %command.full_name% AwesomeStateProvider
+
+If the argument is missing, the command will ask for the class name interactively.
diff --git a/src/Component/Symfony/Bundle/Resources/config/skeleton/Entity.tpl.php b/src/Component/Symfony/Maker/Resources/skeleton/Entity.tpl.php
similarity index 100%
rename from src/Component/Symfony/Bundle/Resources/config/skeleton/Entity.tpl.php
rename to src/Component/Symfony/Maker/Resources/skeleton/Entity.tpl.php
diff --git a/src/Component/Symfony/Bundle/Resources/config/skeleton/Repository.tpl.php b/src/Component/Symfony/Maker/Resources/skeleton/Repository.tpl.php
similarity index 100%
rename from src/Component/Symfony/Bundle/Resources/config/skeleton/Repository.tpl.php
rename to src/Component/Symfony/Maker/Resources/skeleton/Repository.tpl.php
diff --git a/src/Component/Symfony/Bundle/Resources/config/skeleton/Resource.tpl.php b/src/Component/Symfony/Maker/Resources/skeleton/Resource.tpl.php
similarity index 100%
rename from src/Component/Symfony/Bundle/Resources/config/skeleton/Resource.tpl.php
rename to src/Component/Symfony/Maker/Resources/skeleton/Resource.tpl.php
diff --git a/src/Component/Symfony/Maker/Resources/skeleton/StateProcessor.tpl.php b/src/Component/Symfony/Maker/Resources/skeleton/StateProcessor.tpl.php
new file mode 100644
index 000000000..a4d93fed3
--- /dev/null
+++ b/src/Component/Symfony/Maker/Resources/skeleton/StateProcessor.tpl.php
@@ -0,0 +1,18 @@
+
+
+namespace ;
+
+use Sylius\Component\Resource\Context\Context;
+use Sylius\Component\Resource\Metadata\Operation;
+use Sylius\Component\Resource\State\ProcessorInterface;
+
+final class implements ProcessorInterface
+{
+ public function process(mixed $data, Operation $operation, Context $context): mixed
+ {
+ // Handle the state
+
+ return null;
+ }
+}
diff --git a/src/Component/Symfony/Maker/Resources/skeleton/StateProvider.tpl.php b/src/Component/Symfony/Maker/Resources/skeleton/StateProvider.tpl.php
new file mode 100644
index 000000000..2f1e46570
--- /dev/null
+++ b/src/Component/Symfony/Maker/Resources/skeleton/StateProvider.tpl.php
@@ -0,0 +1,18 @@
+
+
+namespace ;
+
+use Sylius\Component\Resource\Context\Context;
+use Sylius\Component\Resource\Metadata\Operation;
+use Sylius\Component\Resource\State\ProviderInterface;
+
+final class implements ProviderInterface
+{
+ public function provide(Operation $operation, Context $context): object|iterable|null
+ {
+ // Retrieve the state from somewhere
+
+ return null;
+ }
+}
diff --git a/src/Component/Tests/Symfony/Maker/MakeStateProcessorTest.php b/src/Component/Tests/Symfony/Maker/MakeStateProcessorTest.php
new file mode 100644
index 000000000..9fdc044eb
--- /dev/null
+++ b/src/Component/Tests/Symfony/Maker/MakeStateProcessorTest.php
@@ -0,0 +1,68 @@
+find('make:sylius-state-processor'));
+
+ $this->assertFileDoesNotExist(self::file(self::CREATE_BOOK_PROCESSOR_PATH));
+
+ $tester->execute(['name' => '\\App\\Tests\\Tmp\\Sylius\\State\\CreateBookProcessor']);
+
+ $this->assertFileExists(self::file(self::CREATE_BOOK_PROCESSOR_PATH));
+ $this->assertSame(self::getCreateBookProcessorExpectedContent(), \file_get_contents(self::file(self::CREATE_BOOK_PROCESSOR_PATH)));
+ }
+
+ private static function getCreateBookProcessorExpectedContent(): string
+ {
+ return <<removeFile(self::file(self::CREATE_BOOK_PROCESSOR_PATH));
+ }
+}
diff --git a/src/Component/Tests/Symfony/Maker/MakeStateProviderTest.php b/src/Component/Tests/Symfony/Maker/MakeStateProviderTest.php
new file mode 100644
index 000000000..fa4b971d1
--- /dev/null
+++ b/src/Component/Tests/Symfony/Maker/MakeStateProviderTest.php
@@ -0,0 +1,68 @@
+find('make:sylius-state-provider'));
+
+ $this->assertFileDoesNotExist(self::file(self::BOOK_ITEM_PROVIDER_PATH));
+
+ $tester->execute(['name' => '\\App\\Tests\\Tmp\\Sylius\\State\\BookItemProvider']);
+
+ $this->assertFileExists(self::file(self::BOOK_ITEM_PROVIDER_PATH));
+ $this->assertSame(self::getBookItemProviderExpectedContent(), \file_get_contents(self::file(self::BOOK_ITEM_PROVIDER_PATH)));
+ }
+
+ private static function getBookItemProviderExpectedContent(): string
+ {
+ return <<removeFile(self::file(self::BOOK_ITEM_PROVIDER_PATH));
+ }
+}