Problem/Motivation

#2083547: PSR-4: Putting it all together includes a change record for the 8.x-to-8.x change of adding PSR-4 support, but does not make the many other updates needed to existing change records and/or documentation.

See the Documentation page for PSR-4 in Drupal 8.

#2247287: Drop automatic PSR-0 support for modules PSR-0 support will also be removed.

Proposed resolution

Update existing change records about PSR-0 to also mention PSR-4 and include a reference to the relevant issue.

Check these:
https://drupal.org/list-changes/published/drupal?keywords_description=ps...

Updated Issue Summaries

CommentFileSizeAuthor
#30 one_replace_php.txt1.26 KBchx
#29 one_replace_php.txt1.25 KBchx
#28 updates.txt8.61 KBchx
#27 updates.txt8.25 KBchx
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

webchick’s picture

We probably want to wait on this until we move all of the files around, because otherwise we're going to introduce docs changes which don't actually line up with what the code is doing.

Also unpublished a comment that was completely unconstructive.

webchick’s picture

Title: Update all existing change records for PSR-4 support » Move all module code to PSR-4 and update all existing change records for PSR-4 support

Actually, I didn't seem to find a dedicated issue for moving the code, so re-using this one.

As discussed in #2083547: PSR-4: Putting it all together among the core maintainers, this will be one of the last, if not the last, beta blocker to get committed in order to minimize disruption to the rest of the queue, so postponed is still the proper status IMO.

larowlan’s picture

Sorry for the unconstructive comment - it was 'puke' for those wondering.
What I should have said/meant was 'I really feel sorry for the poor soul who has to go back and update the change records cause thats a thankless painful job'.

tstoeckler’s picture

Assigned: tstoeckler » Unassigned

In that case unassigning.

BTW, I went through and didn't find any shortcut change notices that reference classes.

xjm’s picture

Title: Move all module code to PSR-4 and update all existing change records for PSR-4 support » Update all existing change records for PSR-4 support
Assigned: Unassigned » tstoeckler
Status: Postponed » Active

@tstoeckler already volunteered to do the change record task, and we need to do it now. Let's split the other off into a separate issue if we are postponing it.

xjm’s picture

Issue summary: View changes

Updated the summary. There seems to be some misunderstanding here. While the filepaths do not need to be updated until we actually change them, we do need to go back and update all the change records that refer to PSR-0 and all the documentation that refers to PSR-0 and update it for this addition and policy change. And we need to do that now.

tstoeckler’s picture

Issue summary: View changes

Went throught the list in the OP:
https://drupal.org/node/1320394/revisions/view/6942253/7175509
https://drupal.org/node/1400186/revisions/view/6860673/7175519
https://drupal.org/node/1477046/revisions/view/2189324/7175527
https://drupal.org/node/1479568/revisions/view/2189348/7175531
https://drupal.org/node/1525776/revisions/view/2008636/7175533
https://drupal.org/node/1532250/revisions/view/2518172/7175535
https://drupal.org/node/1543796/revisions/view/2544968/7175549
https://drupal.org/node/1691614/revisions/view/2229376/7175551
https://drupal.org/node/1703490/revisions/view/2250070/7175563
https://drupal.org/node/1848268/revisions/view/2455818/7175565
https://drupal.org/node/1918778/revisions/view/2566058/7175569
https://drupal.org/node/1935708/revisions/view/2883887/7175573

Also searched for "lib/Drupal":
https://drupal.org/node/1796000/revisions/view/7072485/7175577
https://drupal.org/node/1805846/revisions/view/7072467/7175593
https://drupal.org/node/1806650/revisions/view/7030497/7175599
https://drupal.org/node/1818734/revisions/view/2891497/7175603
https://drupal.org/node/1909596/revisions/view/6673109/7175615
https://drupal.org/node/1911646/revisions/view/7019347/7175619
https://drupal.org/node/1853148/revisions/view/7168383/7175609
https://drupal.org/node/1957310/revisions/view/7056991/7175627
https://drupal.org/node/1961370/revisions/view/7019431/7175629
https://drupal.org/node/1969794/revisions/view/2883449/7175633
https://drupal.org/node/1993056/revisions/view/7019429/7175637
https://drupal.org/node/2003376/revisions/view/7019377/7175639
https://drupal.org/node/2012184/revisions/view/7011697/7175641
https://drupal.org/node/2015901/revisions/view/7019507/7175643
https://drupal.org/node/2020549/revisions/view/7161927/7175645
https://drupal.org/node/2026025/revisions/view/6791911/7175649
https://drupal.org/node/2064123/revisions/view/7072447/7175651
https://drupal.org/node/2072699/revisions/view/2814651/7175653
https://drupal.org/node/2119699/revisions/view/6892933/7175655
https://drupal.org/node/2186931/revisions/view/7019601/7175663

Searching for "tests/Drupal" didn't yield any results.

Also put a list of TBD change notices (after the big change) in the issue summary based on the later search.

So marking "needs review" for now. Maybe someone can find some search that I forgot, otherwise I think we should be done here, until the final move.

tstoeckler’s picture

Status: Active » Needs review
xjm’s picture

Fantastic work. A few questions/comments.

https://drupal.org/node/1320394/revisions/view/6942253/7175509
We'll probably want to completely rewrite or replace this change record once we complete all this, but this is likely good enough for now.

https://drupal.org/node/1400186/revisions/view/6860673/7175519
This still has Plugin in the entity namespace; some other change record update missed that. :P

https://drupal.org/node/1477046/revisions/view/2189324/7175527
https://drupal.org/node/1479568/revisions/view/2189348/7175531
https://drupal.org/node/1525776/revisions/view/2008636/7175533
https://drupal.org/node/1703490/revisions/view/2250070/7175563
https://drupal.org/node/1848268/revisions/view/2455818/7175565
I think the above changes aren't correct because they refer to things in \Drupal\Core or \Drupal\Component.

https://drupal.org/node/1532250/revisions/view/2518172/7175535
Maybe this should say "class autoloading and the configuration system".

https://drupal.org/node/1918778/revisions/view/2566058/7175569
I have no idea about this one. Someone ask @Crell?

https://drupal.org/node/1691614/revisions/view/2229376/7175551
We can revert this one... in fact maybe if we'd been using PSR-4 (or if it had existed) we wouldn't have had to rename list.module to begin with? ;) Oh well.

xjm’s picture

Status: Needs review » Needs work

For #10.

tstoeckler’s picture

Status: Needs work » Needs review

OK, in the order you posted them:

https://drupal.org/node/1400186/revisions/view/7175519/7177537
Thanks overlooked that!

Regarding Core/Component:
Classes there are now, too using a PSR-4 compatible, class-loader. They are just not registered to a subnamespace - like /core/modules/node/src is registered to \Drupal\node - instead /core/lib is registered to the top-level namespace directly*. This distinction is important - i.e. it is important to state that we are using PSR-4 everywhere - because of the difference when it comes to underscores. I.e. class names with underscores will not get picked up as namespaces changes, where they would have been before the PSR-4 patch.

So leaving those as is.

* This is not technically true, in fact /core/lib/Drupal/Component and /core/lib/Drupal/Core are registered to \Drupal\Component and \Drupal\Core respectively, but that's only due to performance. They *could* both be reigstered by simply registering /core/lib to the top-level namespace.

https://drupal.org/node/1691614/revisions/view/2229376/7175551
We can revert this one... in fact maybe if we'd been using PSR-4 (or if it had existed) we wouldn't have had to rename list.module to begin with? ;) Oh well.

That's not true. The problem with the reserved words and list module is regarding the namespace and not the filename. The namespace would still have been list. Kept that one as is.

xjm’s picture

Regarding Core/Component:
Classes there are now, too using a PSR-4 compatible, class-loader. They are just not registered to a subnamespace - like /core/modules/node/src is registered to \Drupal\node - instead /core/lib is registered to the top-level namespace directly*. This distinction is important - i.e. it is important to state that we are using PSR-4 everywhere - because of the difference when it comes to underscores. I.e. class names with underscores will not get picked up as namespaces changes, where they would have been before the PSR-4 patch.

...Wow, glad I asked rather than just changing them myself. ...So PSR-4 means mymodule/src/Namespace/ but also core/lib/Drupal/Core/Namespace/? That's not confusing AT ALL. ;) And why is the Drupal/ subdirectory still there then? Wouldn't it be core/src/Core/ and core/src/Component? How is it not interpreted as belonging to \Drupal\Drupal\Core etc.?

And why did we keep lib for that if it's not PSR-0? How do I know to look in core/lib/Drupal/ instead of core/src/ other than having to read some obscure documentation?

What does this mean for hypothetically sharing our components with other projects, if those use PSR-4? And what about core modules supposedly pulling in components from other projects?

In any case, can we instead update the new PSR-4 change record under the \Drupal\Core and \Drupal\Component section to clarify this?

Thanks @tstoeckler.

donquixote’s picture

So PSR-4 means mymodule/src/Namespace/ but also core/lib/Drupal/Core/Namespace/?

Hi.
This was on the table for months, and noone really complained. I would have liked to get more feedback, but that was it.
I made this decision mostly for technical reasons, because PSR-4 is given priority in the class loader (this was Jordi's idea), and because now if we ever want to do any discovery in core folders (for tests or plugins or other), we can use the same logic as for modules.

why is the Drupal/ subdirectory still there then?

I'd say there is simply no big enough benefit to move this stuff around. The deep directories are a productivity issue for modules, but not so much for core. Besides, we have class Drupal, which is at the top level and would not have a place otherwise. I think if everything was in Drupal\\Core\\, whereas Component would be in vendor, then it would start to make sense to shorten this path. But in the current situation, no.

How do I know to look in core/lib/Drupal/ instead of core/src/ other than having to read some obscure documentation?

I think most people, before turning to documentation, will simply look in the existing file structure and accept it as is. Maybe also a look into composer.json. This does not tell you much about the why, but it does tell you all you need to start writing patches or custom modules.

What does this mean for hypothetically sharing our components with other projects, if those use PSR-4?

Why would this be a problem?
If we really want to share components, we would first have to put them into separate directories. And once we are at that, we can turn around the folder structure so it becomes component/Xyz/src/Foo.php for class Drupal\Component\Xyz\Foo. But this is all hypothetical, and would require a separate discussion.

And what about core modules supposedly pulling in components from other projects?

This is something we really want to have, but has nothing to do with PSR-0 or PSR-4 for modules. These external dependencies could use PSR-0 or PSR-4 themselves, we don't care.
And even if modules would still use PSR-0, I don't think that the (module dir)/lib/ folder would be an appropriate place for 3rd party code.

xjm’s picture

Title: Update all existing change records for PSR-4 support » [PP-1] Update all existing change records for PSR-4 support
Issue summary: View changes

Thanks @donquixote and @tstoeckler. I filed #2252761: Core components are loaded with PSR-4 but in core/lib/Drupal/ for this discussion, because the actual change is rather different from what I understood it to be after hours and hours and hours discussing the PSR-4 change.

Meanwhile, postponing on #2247991: [May 27] Move all module code from …/lib/Drupal/… to …/src/… for PSR-4 for the remaining tasks @tstoeckler listed.

xjm’s picture

Status: Needs review » Postponed
xjm’s picture

Issue summary: View changes
donquixote’s picture

Do we have an issue for documentation changes regarding PSR-4?

I want to suggest to make this the new central doc page for PSR-4:
https://drupal.org/node/2156625
This page has existed for a while, and I think it is quite useful.

Or do we have an alternative?

xjm’s picture

Thanks for the pointer @donquixote. I've updated the page (with @donquixote's help) and deprecated the old pages in favor of it.

xjm’s picture

catch’s picture

Status: Postponed » Active
catch’s picture

Title: [PP-1] Update all existing change records for PSR-4 support » Update all existing change records for PSR-4 support
jhr’s picture

Title: Update all existing change records for PSR-4 support » Update all existing change records and documents for PSR-4 support
Issue summary: View changes

I'm at DrupalCon Austin's sprints and working on moving this forward (irc: #drupal-contribute -- Yancy).

@tstoeckler: Can you comment on:

Probably needs some rewriting, as the part on route subscriber is way outdated

. We need to determine if the rewriting needs be on this issue or another.

jhr’s picture

Issue summary: View changes

PSR-0 support will be dropped, which will affect some rewriting.

https://drupal.org/node/2247287

jhr’s picture

Issue summary: View changes

I ran the faceted search for documents and am adding those documentation links. The ones that I commented just have a small section.

FYI:

I scraped the links from the search by using the FireFox's Dev Console ( JavaSript console). That way I get links and titles.

jQuery('.search-result .title')
  .each( function(idx,ele) { 
    console.log(ele.innerHTML) 
  })

This finds all the links in the search results and echoes it to the console as plain text.

After that I did some RegEx search/replaces to remove extra spaces and characters in PHPStorm.

jhodgdon’s picture

Issue summary: View changes

Thanks! That is very useful!

One note: lib/Drupal still exists in core/lib/Drupal -- what doesn't exist any more is core/modules/foo/lib/Drupal/foo -- so I am not sure about your list in the issue summary? But at least those would be pages to check and see if they need updates. Added this note to the summary.

chx’s picture

FileSize
8.25 KB

I believe someone should spin up a drupal.org devsite and test the attached UPDATE commands on the drupal.org DB -- better than manual edit. Courtesy of

find core/modules -maxdepth 1 -type d | sed 's#core/modules/\(.*$\)#UPDATE node_revision SET body = REPLACE("/lib/Drupal/\1/", "/src/") WHERE vid IN (SELECT vid FROM node WHERE type = "changenotice");#' > /tmp/updates.txt|tail -n +2

There are only 1151 change notices on drupal.org so that UPDATE won't be horrible.

chx’s picture

FileSize
8.61 KB

Sorry; left out a body.

Edit: also, someone could write a script that generates in an embedded-chained REPLACE and then one command to rule them all:

UPDATE node_revision SET body = REPLACE(REPLACE(body, "/lib/Drupal/editor/", "/src/"), "/lib/Drupal/syslog/", "/src/") WHERE vid IN (SELECT vid FROM node WHERE type = "changenotice");

chx’s picture

FileSize
1.25 KB

I attached the PHP that generates two semantically correct SQL UPDATE statements; they run on a D7 database (unlike the previous ones) but I can't vouch whether the REPLACE command is correct. That should be trivial to fix, tho.

chx’s picture

FileSize
1.26 KB

One more.

mtift’s picture

Issue summary: View changes
mtift’s picture

Issue summary: View changes
mtift’s picture

Issue summary: View changes

There doesn't appear to be anything PSR-0 related in https://drupal.org/node/2084727

mtift’s picture

Issue summary: View changes
mtift’s picture

Issue summary: View changes
mtift’s picture

Issue summary: View changes
mtift’s picture

Title: Update all existing change records and documents for PSR-4 support » Update all existing change records for PSR-4 support
Issue summary: View changes
mtift’s picture

Issue summary: View changes
mtift’s picture

Status: Active » Needs review

Discussed with @xjm and decided that documentation updates should not be beta-blocking critical issues. All change records should be updated for PSR-4.

Opened #2281687: Update documentation for PSR-4 support

mtift’s picture

Assigned: tstoeckler » xjm

Assigning to @xjm for review

xjm’s picture

Status: Needs review » Fixed

I've reviewed all the updates, and everything looks correct. The followup issue also looks great. Awesome work everyone!

donquixote’s picture

Issue summary: View changes

I am adding links to the main documentation page for PSR-4 in Drupal 8 to a few issues and change notices where it seems relevant and has yet been missing.

People who google for "Drupal PSR-4" should either directly get the doc page, or if they land elsewhere, they should get to the doc page easily. So far this was not the case.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.