-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
EntityRepositoryGenerator default repository #1089
EntityRepositoryGenerator default repository #1089
Conversation
Hello, thank you for creating this pull request. I have automatically opened an issue http://www.doctrine-project.org/jira/browse/DDC-3231 We use Jira to track the state of pull requests and the versions they got |
* @param string $repositoryName | ||
* @return \Doctrine\ORM\Tools\EntityRepositoryGenerator | ||
*/ | ||
public function setDefaultRepositoryName($repositoryName) |
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 API is not needed, as the default repository name is already specified in configuration
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.
Nvm, was confusing this one with a different generator
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.
- I set default repository class in configuration to MyApp\Doctrine\DefaultRepository
- I created entity class MyApp\Entity\TestEntity and generated repository class for it
- Actually the repository class "MyApp\Entity\TestEntityRepository" turned out to be a descendant of "Doctrine\ORM\EntityRepository" when I expected "MyApp\Doctrine\DefaultRepository" as default.
{ | ||
$repositoryName = $this->_repositoryName; | ||
|
||
if (substr($repositoryName, 0, 1) != '\\') { |
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.
!== and you can use $repositoryName[0] instead od substr.
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.
Also this should be done only when namespace is set.
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.
You're right, I'll check it
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.
Fixed
…espace() changed to protected
…sitoryNamespace()
@@ -32,20 +32,20 @@ | |||
*/ | |||
class EntityRepositoryGenerator | |||
{ | |||
protected $_repositoryName = 'Doctrine\ORM\EntityRepository'; |
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.
please use a private property and remove the leading underscore (we cannot change other properties because of BC)
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.
Why private? What's wrong with protected?
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.
@v3labs we are very defensive about inheritance, and even disallow it in many cases.
Unless there is an explicit (already existing) use-case for the field to be protected
, all should be declared as private
. Same goes for new methods.
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.
Good to know. I'll keep that in mind for future reference.
Would still need a couple of tests here in order to merge this feature. |
* | ||
* @return string | ||
*/ | ||
protected function generateClassName($fullClassName) |
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.
I would make these private rather than protected (so that we don't need to ensure BC on them)
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.
changed
Writed unit tests |
Writed tests (orm:generate-repositories command) |
* | ||
* @return string $repositoryName | ||
*/ | ||
protected function generateEntityRepositoryName($fullClassName) |
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.
iMO, it should be private
@Ocramius all done |
…ultRepository EntityRepositoryGenerator default repository
@encoder32 thanks, merged! |
Related pull doctrine/DoctrineBundle#315