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

Add a simple way to use the new service entity repository #330

Merged

Conversation

loic425
Copy link
Member

@loic425 loic425 commented Oct 13, 2021

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

When using bin/console make:entity command, a repository is automatically generated extending ServiceEntityRepository.
I propose with this PR a simple way to keep using this generated repository with two simple changes:

  • implements SyliusRepositoryInterface
  • use ResourceRepositoryTrait.

@loic425 loic425 requested a review from a team as a code owner October 13, 2021 22:46
@loic425 loic425 force-pushed the feature/allow-using-service-entity-repository branch 2 times, most recently from b52eb7b to 9d5df06 Compare October 13, 2021 23:20
@lchrusciel
Copy link
Contributor

  • would be awesome, to add note about it to our docs

@loic425 loic425 force-pushed the feature/allow-using-service-entity-repository branch from 8f1046c to 4f8f809 Compare December 20, 2021 11:42
@loic425
Copy link
Member Author

loic425 commented Dec 20, 2021

  • would be awesome, to add note about it to our docs

I think it has to be here too
https://docs.sylius.com/en/latest/cookbook/entities/custom-model.html#change-repository-to-extend-entityrepository

@Zales0123 Zales0123 added the Feature New feature proposals. label Dec 20, 2021
@@ -70,3 +70,5 @@ services:
-
name: doctrine.event_subscriber
connection: default

App\Repository\ComicBookRepository: null
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't App\Repository\ComicBookRepository: ~ work as well? It looks better, definitely 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but Symfony best practice is to set "null" instead of "~"
https://github.com/symfony/recipes/#validation

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

* @method QueryBuilder createQueryBuilder(string $alias, string $indexBy = null)
* @method ?object find($id, $lockMode = null, $lockVersion = null)
*/
trait ResourceRepositoryTrait
Copy link
Contributor

Choose a reason for hiding this comment

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

What would be awesome, is to create php unit test for this trait with usage of anonymous class. But I can live with the current solution. Also, it appears that it may be cumbersome to do such a test

* @property ClassMetadata $_class
*
* @method QueryBuilder createQueryBuilder(string $alias, string $indexBy = null)
* @method ?object find($id, $lockMode = null, $lockVersion = null)
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we shouldn't declare these methods as abstract, to force contract

@@ -0,0 +1,106 @@
<?php

declare(strict_types=1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing license block

@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing license block

@lchrusciel lchrusciel merged commit fe0daaf into Sylius:master Dec 20, 2021
@lchrusciel
Copy link
Contributor

Thank you, Loïc! 🎉

@loic425 loic425 deleted the feature/allow-using-service-entity-repository branch December 20, 2021 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature proposals.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants