Skip to content

Commit 9528dfd

Browse files
committed
Add make state provider and processor
1 parent 403bd4c commit 9528dfd

16 files changed

Lines changed: 380 additions & 2 deletions

src/Bundle/Resources/config/services/maker.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,13 @@
2828
<argument type="service" id="maker.file_manager" />
2929
<tag name="maker.command" />
3030
</service>
31+
32+
<service id="sylius.maker.state_provider" class="Sylius\Component\Resource\Symfony\Maker\MakeStateProvider">
33+
<tag name="maker.command" />
34+
</service>
35+
36+
<service id="sylius.maker.state_processor" class="Sylius\Component\Resource\Symfony\Maker\MakeStateProcessor">
37+
<tag name="maker.command" />
38+
</service>
3139
</services>
3240
</container>

src/Component/Symfony/Maker/Generator/RepositoryClassGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function generateRepositoryClass(ClassNameDetails $repositoryClassDetails
3131
{
3232
return $this->generator->generateClass(
3333
$repositoryClassDetails->getFullName(),
34-
dirname(__DIR__, 2) . '/Bundle/Resources/config/skeleton/Repository.tpl.php',
34+
dirname(__DIR__) . '/Resources/skeleton/Repository.tpl.php',
3535
[
3636
'entity_class_name' => $resourceClassDetails->getShortName(),
3737
'entity_namespace' => Str::getNamespace($resourceClassDetails->getFullName()),

src/Component/Symfony/Maker/Generator/ResourceClassGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function generateResourceClass(
4242

4343
return $this->generator->generateClass(
4444
$resourceClassDetails->getFullName(),
45-
dirname(__DIR__, 2) . '/Bundle/Resources/config/skeleton/' . $skeletonName,
45+
dirname(__DIR__) . '/Resources/skeleton/' . $skeletonName,
4646
[
4747
'class_name_without_suffix' => $shortName,
4848
'show_template_dir' => \strtolower($shortName),

src/Component/Symfony/Maker/MakeResource.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,29 +44,45 @@ public function __construct(
4444
) {
4545
}
4646

47+
/**
48+
* {@inheritdoc}
49+
*/
4750
public static function getCommandName(): string
4851
{
4952
return 'make:resource';
5053
}
5154

55+
/**
56+
* {@inheritdoc}
57+
*/
5258
public static function getCommandDescription(): string
5359
{
5460
return 'Creates a Resource class';
5561
}
5662

63+
/**
64+
* {@inheritdoc}
65+
*/
5766
public function configureCommand(Command $command, InputConfiguration $inputConfig): void
5867
{
5968
$command
6069
->setDescription(self::getCommandDescription())
6170
->addArgument('name', InputArgument::OPTIONAL, 'Class name of the resource to create')
6271
->addOption('is-entity', null, InputOption::VALUE_NONE, 'Do you want to store resource data in the database (via Doctrine)?')
72+
->setHelp(file_get_contents(__DIR__.'/Resources/help/MakeResource.txt'))
6373
;
6474
}
6575

76+
/**
77+
* {@inheritdoc}
78+
*/
6679
public function configureDependencies(DependencyBuilder $dependencies): void
6780
{
6881
}
6982

83+
/**
84+
* {@inheritdoc}
85+
*/
7086
public function interact(InputInterface $input, ConsoleStyle $io, Command $command): void
7187
{
7288
$resourceIsEntity = $io->confirm(
@@ -79,6 +95,9 @@ class_exists(DoctrineBundle::class),
7995
}
8096
}
8197

98+
/**
99+
* {@inheritdoc}
100+
*/
82101
public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator): void
83102
{
84103
/** @var string $name */
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <dunglas@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Sylius\Component\Resource\Symfony\Maker;
15+
16+
use Symfony\Bundle\MakerBundle\ConsoleStyle;
17+
use Symfony\Bundle\MakerBundle\DependencyBuilder;
18+
use Symfony\Bundle\MakerBundle\Generator;
19+
use Symfony\Bundle\MakerBundle\InputConfiguration;
20+
use Symfony\Bundle\MakerBundle\Maker\AbstractMaker;
21+
use Symfony\Component\Console\Command\Command;
22+
use Symfony\Component\Console\Input\InputArgument;
23+
use Symfony\Component\Console\Input\InputInterface;
24+
25+
final class MakeStateProcessor extends AbstractMaker
26+
{
27+
/**
28+
* {@inheritdoc}
29+
*/
30+
public static function getCommandName(): string
31+
{
32+
return 'make:sylius-state-processor';
33+
}
34+
35+
/**
36+
* {@inheritdoc}
37+
*/
38+
public static function getCommandDescription(): string
39+
{
40+
return 'Creates a Sylius state processor';
41+
}
42+
43+
/**
44+
* {@inheritdoc}
45+
*/
46+
public function configureCommand(Command $command, InputConfiguration $inputConfig): void
47+
{
48+
$command
49+
->addArgument('name', InputArgument::REQUIRED, 'Choose a class name for your state processor (e.g. <fg=yellow>AwesomeStateProcessor</>)')
50+
->setHelp(file_get_contents(__DIR__.'/Resources/help/MakeStateProcessor.txt'))
51+
;
52+
}
53+
54+
/**
55+
* {@inheritdoc}
56+
*/
57+
public function configureDependencies(DependencyBuilder $dependencies): void
58+
{
59+
}
60+
61+
/**
62+
* {@inheritdoc}
63+
*/
64+
public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator): void
65+
{
66+
$stateProcessorClassNameDetails = $generator->createClassNameDetails(
67+
$input->getArgument('name'),
68+
'State\\'
69+
);
70+
71+
$generator->generateClass(
72+
$stateProcessorClassNameDetails->getFullName(),
73+
__DIR__.'/Resources/skeleton/StateProcessor.tpl.php'
74+
);
75+
$generator->writeChanges();
76+
77+
$this->writeSuccessMessage($io);
78+
$io->text([
79+
'Next: Open your new state processor class and start customizing it.',
80+
]);
81+
}
82+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <dunglas@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Sylius\Component\Resource\Symfony\Maker;
15+
16+
use Symfony\Bundle\MakerBundle\ConsoleStyle;
17+
use Symfony\Bundle\MakerBundle\DependencyBuilder;
18+
use Symfony\Bundle\MakerBundle\Generator;
19+
use Symfony\Bundle\MakerBundle\InputConfiguration;
20+
use Symfony\Bundle\MakerBundle\Maker\AbstractMaker;
21+
use Symfony\Component\Console\Command\Command;
22+
use Symfony\Component\Console\Input\InputArgument;
23+
use Symfony\Component\Console\Input\InputInterface;
24+
25+
final class MakeStateProvider extends AbstractMaker
26+
{
27+
/**
28+
* {@inheritdoc}
29+
*/
30+
public static function getCommandName(): string
31+
{
32+
return 'make:sylius-state-provider';
33+
}
34+
35+
/**
36+
* {@inheritdoc}
37+
*/
38+
public static function getCommandDescription(): string
39+
{
40+
return 'Creates a Sylius state provider';
41+
}
42+
43+
/**
44+
* {@inheritdoc}
45+
*/
46+
public function configureCommand(Command $command, InputConfiguration $inputConfig): void
47+
{
48+
$command
49+
->addArgument('name', InputArgument::REQUIRED, 'Choose a class name for your state provider (e.g. <fg=yellow>AwesomeStateProvider</>)')
50+
->setHelp(file_get_contents(__DIR__.'/Resources/help/MakeStateProvider.txt'))
51+
;
52+
}
53+
54+
/**
55+
* {@inheritdoc}
56+
*/
57+
public function configureDependencies(DependencyBuilder $dependencies): void
58+
{
59+
}
60+
61+
/**
62+
* {@inheritdoc}
63+
*/
64+
public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator): void
65+
{
66+
$stateProviderClassNameDetails = $generator->createClassNameDetails(
67+
$input->getArgument('name'),
68+
'State\\'
69+
);
70+
71+
$generator->generateClass(
72+
$stateProviderClassNameDetails->getFullName(),
73+
__DIR__.'/Resources/skeleton/StateProvider.tpl.php'
74+
);
75+
$generator->writeChanges();
76+
77+
$this->writeSuccessMessage($io);
78+
$io->text([
79+
'Next: Open your new state provider class and start customizing it.',
80+
]);
81+
}
82+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
The <info>%command.name%</info> command generates a new Sylius resource class.
2+
3+
<info>php %command.full_name% Book</info>
4+
5+
If the argument is missing, the command will ask for the class name interactively.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
The <info>%command.name%</info> command generates a new Sylius state processor class.
2+
3+
<info>php %command.full_name% AwesomeStateProcessor</info>
4+
5+
If the argument is missing, the command will ask for the class name interactively.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
The <info>%command.name%</info> command generates a new Sylius state provider class.
2+
3+
<info>php %command.full_name% AwesomeStateProvider</info>
4+
5+
If the argument is missing, the command will ask for the class name interactively.

src/Component/Symfony/Bundle/Resources/config/skeleton/Entity.tpl.php renamed to src/Component/Symfony/Maker/Resources/skeleton/Entity.tpl.php

File renamed without changes.

0 commit comments

Comments
 (0)