Skip to content
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

[Maker] Resource, State provider and state processor makers #705

Open
wants to merge 6 commits into
base: 1.11
Choose a base branch
from

Conversation

loic425
Copy link
Member

@loic425 loic425 commented Apr 14, 2023

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Related tickets
License MIT

@loic425 loic425 requested a review from a team as a code owner April 14, 2023 15:10
@loic425 loic425 marked this pull request as draft April 14, 2023 15:10
@loic425 loic425 force-pushed the feature/make-resource branch 2 times, most recently from 40079e6 to 4317a1d Compare April 17, 2023 10:33
@loic425 loic425 changed the title Resource maker [Maker] Resource maker Apr 17, 2023
@loic425 loic425 force-pushed the feature/make-resource branch from 4317a1d to dd3135a Compare April 17, 2023 10:48
@loic425 loic425 marked this pull request as ready for review April 17, 2023 13:46
@loic425 loic425 force-pushed the feature/make-resource branch from 216e72a to 9528dfd Compare April 20, 2023 13:33
@loic425 loic425 changed the title [Maker] Resource maker [Maker] Resource, State provider and state processor maker Apr 20, 2023
@loic425 loic425 changed the title [Maker] Resource, State provider and state processor maker [Maker] Resource, State provider and state processor makers Apr 20, 2023
@loic425 loic425 force-pushed the feature/make-resource branch 3 times, most recently from 1774077 to 5f623ea Compare June 20, 2023 13:11
@loic425 loic425 force-pushed the poc-new-resource-metadata branch 2 times, most recently from b5a7698 to 5ad1d7d Compare June 20, 2023 13:59
@Zales0123
Copy link
Member

I suppose this one should be rebased with 1.11? cc @loic425

@Zales0123 Zales0123 added the Feature New feature proposals. label Jun 22, 2023
@loic425 loic425 changed the base branch from poc-new-resource-metadata to 1.11 June 23, 2023 08:32
@loic425 loic425 force-pushed the feature/make-resource branch from 5f623ea to b414aba Compare June 23, 2023 08:38
@loic425
Copy link
Member Author

loic425 commented Jun 23, 2023

I suppose this one should be rebased with 1.11? cc @loic425

@Zales0123 This is now ready to review :)
But this kind of features are not easy to review.

use Sylius\Component\Resource\Model\ResourceInterface;
use Symfony\Component\Uid\AbstractUid;

#[Resource]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum, I forgot to specify driver option to false.

use Sylius\Component\Resource\Metadata\Operation;
use Sylius\Component\Resource\State\ProviderInterface;

final class BookItemProvider implements ProviderInterface
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should be removed from git.

$shortName = $resourceClassDetails->getShortName();

if (\str_ends_with($shortName, 'Resource')) {
$shortName = \mb_substr($shortName, 0, -\strlen('Resource'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible that $shortName === "" here ?

$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)?')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
->addOption('is-entity', null, InputOption::VALUE_NONE, 'Do you want to store resource data in the database (via Doctrine)?')
->addOption('is-entity', null, InputOption::VALUE_NONE, 'Do you want to store resource data in the database (eg: via Doctrine)?')

public function interact(InputInterface $input, ConsoleStyle $io, Command $command): void
{
$resourceIsEntity = $io->confirm(
'Do you want to store resource data in the database (via Doctrine)?',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'Do you want to store resource data in the database (via Doctrine)?',
'Do you want to store resource data in the database (eg: via Doctrine)?',

/** @var string $name */
$name = $input->getArgument('name');

/** @var bool $resourceIsEntity */
Copy link
Contributor

@Prometee Prometee Sep 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** @var bool $resourceIsEntity */
/** @var bool|null $resourceIsEntity */

Maybe it's better to set a default value for this option to avoid getting null at this point, WDYT ?

Copy link
Member

@lchrusciel lchrusciel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome feature and huge effort. Thanks Loic! However, let's take small step and add just resource generation in the first PR. It would be easier to review. And we have inconsistencies among different makers. Let's build ground rules, decide what should be part of maker and then add more makers

Comment on lines +38 to +45
if (!class_exists(MakerBundle::class)) {
return false;
}

/** @var array $bundles */
$bundles = $container->getParameter('kernel.bundles');

return in_array(MakerBundle::class, $bundles, true);
Copy link
Member

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

return <<<EOF
<?php

namespace App\Tests\Tmp\Sylius\Resource;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have Sylius in the namespace for resources but not for processors? We have the command make:resource that have Sylius in a namespace, but then we have make:sylius-state-processor command, which generates processor without Sylius in namespace.

Comment on lines +98 to +100
#[Index(
// grid: BookGrid::class,
)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[Index(
// grid: BookGrid::class,
)]
#[Index()]

My recommendation would be to remove all the comments from attributes. Or even all the routes in the first iteration


This file is part of the Sylius package.

(c) Paweł Jędrzejewski
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--- (c) Paweł Jędrzejewski
+++ (c) Sylius Sp. z o.o.

)
;

return 0;
Copy link
Member

Choose a reason for hiding this comment

The 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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature proposals.
Projects
Status: 👀 In review
Development

Successfully merging this pull request may close these issues.

5 participants