Skip to content

provide a compiler pass for doctrine to register namespace aliases #10853

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

Merged
merged 1 commit into from
Aug 8, 2014
Merged

provide a compiler pass for doctrine to register namespace aliases #10853

merged 1 commit into from
Aug 8, 2014

Conversation

dbu
Copy link
Contributor

@dbu dbu commented May 4, 2014

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? yes
Tests pass? yes
Fixed tickets -
License MIT
Doc PR symfony/symfony-docs#4069

I realized that the compiler pass only allows bundles to register folders to load entities / documents but not namespace alias to make things like CmfRoutingBundle:Route work. This is an attempt to provide a separate compiler pass for this. Maybe we should instead provide a new combined compiler pass and have users switch to the new pass if available.

* 'doctrine.orm.%s_metadata_driver'
* @var string
*/
protected $driverPattern;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is a micro BC break as in the base class i call this serviceNamePattern and its only protected. we could either use a wrong name in the base class or keep this field (but then instead of a php error we would get a semantic error if the value is directly read / assigned.)

as none of the doctrine bundles directly accesses the value, i think the BC break would hit only people that did a custom extension of this pass, which i doubt exists.

@dbu
Copy link
Contributor Author

dbu commented May 4, 2014

i think the test failure is not related to what i did.

@jjsaunier
Copy link

Nope, it's not you, take a look #10826, all test failed from 5.5

@dbu
Copy link
Contributor Author

dbu commented May 11, 2014

ping @beberlei @stof any inputs on this?

@dbu dbu added the Doctrine label Jun 16, 2014
@ClementGautier
Copy link
Contributor

looks good to me

@fabpot
Copy link
Member

fabpot commented Jul 21, 2014

I would indeed deprecate the current one and create just one pass to switch to.

@dbu
Copy link
Contributor Author

dbu commented Jul 25, 2014

had a go at cleaning this up and realized that we can keep BC and just add more constructor arguments. this will be a lot more convenient for consumers - they can just pass additional parameters that are ignored on older symfony versions and don't get namespace alias but do get the rest.

* is used, the others skipped.
*
* The $alias parameter can be used to define bundle namespace shortcuts as the DoctrineBundle
* provides automatically for objects in the default Entity/Document folder.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

i found no explicit documentation to link to, but alias are mentioned in this section of the book http://symfony.com/doc/current/book/doctrine.html#fetching-objects-from-the-database

@dbu
Copy link
Contributor Author

dbu commented Jul 25, 2014

Once we agree on this, i will update https://github.com/symfony/symfony-docs/blob/master/cookbook/doctrine/mapping_model_classes.rst and update the orm and mongo, couch bundles. phpcr-odm is being updated already: doctrine/DoctrinePHPCRBundle#158

$enabledParameter = false,
$configurationPattern = '',
$registerAliasMethodName = '',
array $alias = array()
Copy link
Contributor

Choose a reason for hiding this comment

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

As mentioned in https://github.com/doctrine/DoctrinePHPCRBundle/pull/158/files#r15399221 maybe this should be $aliasMap or $aliases ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed to aliasMap, thanks

@dbu
Copy link
Contributor Author

dbu commented Jul 28, 2014

@fabpot what do you think about this? ok like this? the parameter order in the constructor is not awesome, but is BC compatible, simplifying the live of doctrine bundles that build on top of this a lot.

@fabpot
Copy link
Member

fabpot commented Jul 28, 2014

Looks good to me.

@dbu
Copy link
Contributor Author

dbu commented Jul 29, 2014

did pull requests for the orm and phpcr-odm bundles, and the symfony-docs (links in issue description). how do we proceed? @beberlei can you give some feedback on the doctrine bundle PR?

$chainDriverDefService = $this->getChainDriverServiceName($container);
$chainDriverDef = $container->getDefinition($chainDriverDefService);
foreach ($this->namespaces as $namespace) {
// instance of Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain
Copy link
Contributor

Choose a reason for hiding this comment

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

If you have to commit again you could change that to /** @var \Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain $chainDriverDef */ and move it up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

of course. must have been tired. thanks for spotting, fixed.

@fabpot
Copy link
Member

fabpot commented Jul 30, 2014

@dbu Let me know whenever @beberlei is ready to merge the changes in DoctrineBundle.

* Map of alias to namespace.
* @var array
*/
protected $aliasMap;
Copy link
Member

Choose a reason for hiding this comment

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

should we use private properties instead ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there are a couple of existing properties already, we can't restrict them as it would be a BC break. but can make these private, would have been better.

Copy link
Member

Choose a reason for hiding this comment

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

I know we canot change the existing ones. I'm talking about the new ones here

@stof
Copy link
Member

stof commented Aug 5, 2014

This also needs to be rebased to fix conflicts

@dbu
Copy link
Contributor Author

dbu commented Aug 5, 2014

thanks for the feedback stof, agreeing and updated all points you noted.

no idea where that conflict came from. but i rebased on upstream/master and seems good now.

* @throws ParameterNotFoundException if none of the managerParameters has a
* non-empty value.
*
* @since 2.6
Copy link
Contributor

Choose a reason for hiding this comment

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

It's private so I would say that it can be removed.

@kimhemsoe
Copy link
Contributor

We are ready to merge doctrine/DoctrineBundle#316 whenever you are.

We have a DoctrineBundle 1.3 release, that we are planning to do this week. Do you want us to post prone until this PR gets merged?

@fabpot
Copy link
Member

fabpot commented Aug 6, 2014

@dbu Do you have time to finish this PR so that it can be merged fast?

@dbu
Copy link
Contributor Author

dbu commented Aug 6, 2014

adjusted to the feedback of @stloyd

would be great if this can make it into DoctrineBundle 1.3. @kimhemsoe there is no problem merging the DoctrineBundle PR for older symfony versions, as its just extra parameters to the constructor that php will ignore.

@kimhemsoe
Copy link
Contributor

What is the status of this ?

I know it it will not break anything, but we rather wait on this PR to merge before merging DoctrineBundle one.

@fabpot
Copy link
Member

fabpot commented Aug 8, 2014

👍

@dbu
Copy link
Contributor Author

dbu commented Aug 8, 2014

@kimhemsoe here we wait for input from the doctrine orm maintainers :-)

beberlei said that @kimhemsoe is release manager of the doctrine bundle. so i think the comment above is an approval from doctrine and we can merge this, right?

@stof
Copy link
Member

stof commented Aug 8, 2014

👍

1 similar comment
@kimhemsoe
Copy link
Contributor

👍

@fabpot
Copy link
Member

fabpot commented Aug 8, 2014

Thank you @dbu.

@fabpot fabpot merged commit 9a62ab3 into symfony:master Aug 8, 2014
fabpot added a commit that referenced this pull request Aug 8, 2014
…pace aliases (dbu)

This PR was merged into the 2.6-dev branch.

Discussion
----------

provide a compiler pass for doctrine to register namespace aliases

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | symfony/symfony-docs#4069

I realized that the compiler pass only allows bundles to register folders to load entities / documents but not namespace alias to make things like `CmfRoutingBundle:Route` work. This is an attempt to provide a separate compiler pass for this. Maybe we should instead provide a new combined compiler pass and have users switch to the new pass if available.

* [x] [Doctrine ORM](doctrine/DoctrineBundle#316)
* [x] [DoctrinePHPCRBundle](doctrine/DoctrinePHPCRBundle#158)
* [ ] Doctrine CouchDB
* [ ] Doctrine MongoDB

Commits
-------

9a62ab3 provide a compiler pass for doctrine to register namespace aliases and not only mapping drivers
@dbu dbu deleted the doctrine-bridge-compiler-pass branch August 8, 2014 15:07
weaverryan added a commit to symfony/symfony-docs that referenced this pull request Aug 16, 2014
This PR was merged into the master branch.

Discussion
----------

document the namespace alias feature

| Q             | A
| ------------- | ---
| Doc fix?      | no
| New docs?     | [yes](symfony/symfony#10853)
| Applies to    | 2.6
| Fixed tickets | -

Commits
-------

d753d0e document the namespace alias feature
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants