Motivation

The registry autoload module fills a gap between Drupal 7 and Drupal 8.

Drupal 8 has been using namespaced classes, but relies on the composer autoloader. Drupal 7 has the code registry for autoloading, but does not support namespaced files.

While the core registry would be enough to autoload namespaced files in Drupal 7, Drupal 7 does not support the namespace PHP tag as it did not exist when Drupal 7 was created.

The Core registry also lacks any automation in finding new class files and all need to be specified manually via the files[] array.

PSR-0 / PSR-4 automatic file scanning

To your module.info file add:

registry_autoload[] = PSR-0
registry_autoload[] = PSR-4

PSR-0 will search the lib/ subdirectory of the module for .php files, while PSR-4 will search the src/ subdirectory.

Please see README.md for more information.

Note: This will do a file_scan_directory() on every registry_rebuild, which might be something you don't want.

Manual adding of files that support namespaces

Similar to how files[] works, supply filenames relative to your modules directory with:

registry_autoload_files[] = filename

The difference is that registry_autoload_files[] support namespaces, while files[] does not, yet.

Implementation

The registry_autoload module uses a trick to hook into the registry building process:

By ensuring the hash is the same in {registry_file} compared to the actual file and updating {registry} ourselves we can ensure that core does not re-parse the files we add to the files[] array via hook_registry_files_alter() and will continue to use the namespaced classes.

Similar modules

- xautoload - Provides a full PSR-0, PSR-4 and custom namespaces compatible autoloader, which finds files at run time. The main difference is that xautoload is a fully fledged autoloader with _lots_ of features while this only enhances the Drupal 7 core registry to scan files automatically (on demand) and provide namespace support.

The main use case was that xautoload was too heavy to depend on for a project, which wants to use PSR-0 and PSR-4 features.

References

Project application meta data

Project Page: https://www.drupal.org/sandbox/fabianx/2354855

Pareview: http://pareview.sh/pareview/httpgitdrupalorgsandboxfabianx2354855git

Git Clone: git clone --branch 7.x-1.x http://git.drupal.org/sandbox/Fabianx/2354855.git registry_autoload

Reviews of other projects:
@todo

Comments

fabianx’s picture

Issue summary: View changes
PA robot’s picture

We are currently quite busy with all the project applications and we prefer projects with a review bonus. Please help reviewing and put yourself on the high priority list, then we will take a look at your project right away :-)

Also, you should get your friends, colleagues or other community members involved to review this application. Let them go through the review checklist and post a comment that sets this issue to "needs work" (they found some problems with the project) or "reviewed & tested by the community" (they found no major flaws).

I'm a robot and this is an automated message from Project Applications Scraper.

fabianx’s picture

Issue summary: View changes
fabianx’s picture

Status: Active » Needs review

I am putting this to "Needs review" for now. I am unfortunately too busy this week to get the review bonus :-/.

But will try to follow-up on other applications as soon as possible.

fabianx’s picture

I am putting this to "Needs review" for now. I am unfortunately too busy this week to get the review bonus :-/.

But will try to follow-up on other applications as soon as possible.

fabianx’s picture

Issue summary: View changes
klausi’s picture

Assigned: fabianx » chx
Status: Needs review » Reviewed & tested by the community

manual review:
there is tests directory, but there is no *.test file containing an automated test case that would make use of the test module's code files? Am I missing something?

But otherwise looks RTBC to me.

Assigning to chx as he might have time to take a final look at this.

fabianx’s picture

Thanks for the review.

The test module was made for manual testing. This is unfortunately only stated in the header comment of the module file (http://cgit.drupalcode.org/sandbox-Fabianx-2354855/tree/tests/modules/re...). The test case is so simple, that a manual test was better than setting up simpletest extra for that.

chx’s picture

Assigned: chx » Unassigned

Of course it looks OK, I think core subsystem maintainers should be auto-approved, really. I do not have user editing powers but I will try to find someone who does :)

mpdonadio’s picture

Assigned: Unassigned » mpdonadio
klausi’s picture

Oh, chx is not a git admin anymore? That's sad, I removed you from the list of git admins so that we are all aware of it :-(

mpdonadio’s picture

Automated Review

Review of the 7.x-1.x branch (commit 6ed0d1f):

This automated report was generated with PAReview.sh, your friendly project application review script. You can also use the online version to check your project. You have to get a review bonus to get a review from me.

Manual Review

Individual user account
Yes: Follows the guidelines for individual user accounts.
No duplication
Yes: Does not cause module duplication and/or fragmentation. Similar projects adequately addressed.
Master Branch
Yes: Follows the guidelines for master branch.
Licensing
Yes: Follows the licensing requirements.
3rd party code
Yes: Follows the guidelines for 3rd party code.
README.txt/README.md
Yes: Follows the guidelines for in-project documentation and/or the README Template.
Code long/complex enough for review
Yes: Follows the guidelines for project length and complexity.
Secure code
Yes: Meets the security requirements.
Coding style & Drupal API usage

You have a tests directory with that appears to be a test module, but no .test file? Ah, this was mentioned above.

The starred items (*) are fairly big issues and warrant going back to Needs Work. Items marked with a plus sign (+) are important and should be addressed before a stable project release. The rest of the comments in the code walkthrough are recommendations.

Nothing major, nothing minor, either.

If added, please don't remove the security tag, we keep that for statistics and to show examples of security problems.

This review uses the Project Application Review Template.

mpdonadio’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for your contribution, Fabianx!

I updated your account so you can promote this to a full project and also create new projects as either a sandbox or a "full" project.

Here are some recommended readings to help with excellent maintainership:

You can find lots more contributors chatting on IRC in #drupal-contribute. So, come hang out and stay involved!

Thanks, also, for your patience with the review process. Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.

Thanks to the dedicated reviewer(s) as well.

mpdonadio’s picture

Assigned: mpdonadio » Unassigned
chx’s picture

> Oh, chx is not a git admin anymore?

#2172149-30: Disable the Github Sync user account: it's confusing I am not anything any more.

fabianx’s picture

Thanks so much @all!

I added the .test file now that I had a short moment to grok it.

Created the module here and automated testing is enabled:

https://www.drupal.org/project/registry_autoload

Also created a first stable release.

Thanks again for all the feedback and the great review tools!

Status: Fixed » Closed (fixed)

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