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

make the QB able to automatically handle the attribute translation strategy #353

Merged
merged 1 commit into from Oct 4, 2013

Conversation

lsmith77
Copy link
Member

@lsmith77 lsmith77 commented Oct 3, 2013

@@ -167,7 +167,7 @@ public function getTranslationStrategy($key)
public function getLocaleChooserStrategy()
{
if (!isset($this->localeChooserStrategy)) {
throw new PHPCRInvalidArgumentException("You must configure a language chooser strategy when having documents with the translatable annotation");
throw new PHPCRInvalidArgumentException("A language chooser strategy must be configured when mapping documents documents with a translation strategy");
Copy link
Member

Choose a reason for hiding this comment

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

just fyi: this will collide a bit with #354 where we cleanup the exceptions.

Copy link
Member Author

Choose a reason for hiding this comment

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

so you fixed the wording there already too?

Copy link
Member

Choose a reason for hiding this comment

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

no, only the class names and namespaces.

Copy link
Member Author

Choose a reason for hiding this comment

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

Can you update the exception message there then to something like A language chooser strategy must be configured when mapping documents documents with a translation strategy ?

@dbu
Copy link
Member

dbu commented Oct 4, 2013

but great initiative, i really think this will be a valuable addition for 1.0!

* @return Builder\QueryBuilder
*/
public function createQueryBuilder()
public function createQueryBuilder($locale = 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 would rather that we called added a setLocale method to the QueryBuilder than adding an argument here.

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 would make things quite a lot more complex for example when using this inside sonata admin. with this solution it will automatically just work. otherwise we will have to add explicit code to deal with multilang all over the place.

Copy link
Contributor

Choose a reason for hiding this comment

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

How would it make it more complicated? What is the difference between $dm->createQueryBuilder('fr') and $dm->createQueryBuilder()->setLocale('fr'); ?

Copy link
Member Author

Choose a reason for hiding this comment

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

the difference is being able to do $dm->createQueryBuilder() for one wants to just use the default locale while still being able to do $dm->createQueryBuilder(false) to disable this behavior entirely.

Copy link
Contributor

Choose a reason for hiding this comment

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

I still don't see why this can't be a property of the query builder, why
does it need to spill into the DM? Not calling "setLocale" would be the
same as createQueryBuilder() and equally setLocale(false).

Also, don't forget the createQueryBuilder method of the
DocumentRepository, which, with this change would now require both an
alias and a locale, which might be confusing.

On Fri, Oct 04, 2013 at 01:31:58AM -0700, Lukas Kahwe Smith wrote:

In lib/Doctrine/ODM/PHPCR/DocumentManager.php:

  * @return Builder\QueryBuilder
  */
  • public function createQueryBuilder()
  • public function createQueryBuilder($locale = null)

the difference is being able to do $dm->createQueryBuilder() for one wants
to just use the default locale while still being able to do
``$dm->createQueryBuilder(false) to disable this behavior entirely.


Reply to this email directly or [1]view it on GitHub.

References

Visible links

  1. https://github.com/doctrine/phpcr-odm/pull/353/files#r6762702

Copy link
Member Author

Choose a reason for hiding this comment

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

if we do what you propose then it means, we would set the locale to the default locale by default. which in turn means that for disabling or setting a locale other than the default one will need to make this method call. this is kind of annoying since we would then need to determine the default locale first .. which would then be overwritten. and of course the user will need to learn about the existence of this method.

we could of course delay determining the default locale but this will require a try/catch if we want to fetch the locale chooser outside of the DM.

so imho moving this out to me makes the code more complex and also requires more work from the user. optional parameters should be avoided as much as possible. so i agree its not ideal, but imho still better than the alternatives.

Copy link
Contributor

Choose a reason for hiding this comment

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

But.. from the POV of an ideal interface, I can't see how the property "locale" is more deserving of a plce in the factory method than any other property. I would rather refactor to make the "ideal" work than regret this later.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok .. i have refactored it .. don't really like the result .. but i guess it will solve your concerns

@lsmith77
Copy link
Member Author

lsmith77 commented Oct 4, 2013

so good to merge?

@dbu
Copy link
Member

dbu commented Oct 4, 2013

i am +1 once you added a line about the DocumentRepository::createQueryBuilder to the CHANGELOG.md

@@ -313,7 +313,7 @@ public function createQuery($statement, $language, $options = 0)
*
* @return \Doctrine\ODM\PHPCR\Query\Builder
*/
public function createQueryBuilder($selectorName)
public function createQueryBuilder($selectorName = 'a')
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 is not related to this PR

Copy link
Contributor

Choose a reason for hiding this comment

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

Then why is here? I was under the impression that there was a general consensus that we should force the user to choose an alias the Doctrine ORM does?

Copy link
Member Author

Choose a reason for hiding this comment

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

lets revert this .. saw this while talking to David .. but its of course a bigger topic

lsmith77 added a commit that referenced this pull request Oct 4, 2013
make the QB able to automatically handle the attribute translation strategy
@lsmith77 lsmith77 merged commit df352fc into master Oct 4, 2013
@lsmith77 lsmith77 deleted the qb_attribute_translation_strategy branch October 4, 2013 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants