Jloader prefix #1760

Closed
wants to merge 4 commits into from

3 participants

@garyamort

Codefix

Fixes loadByPrefix autoloader[_load] so that it doesn't give up on the first match.

Ex

Prefix: Tree, Path stubs/tree
Prefix: TreeLeaf, Path stubs/tree/leaf
class_exists(TreeLeafLeaf)

Current behavior

Will try to load either file stubs/tree/leaf/leaf.php or stubs/tree/leaf/leaf/leaf,php - but not both. Which file is attempted depends on which Prefix was loaded last(?). Even if the first file does not exist, it will still be the only file attempted.

New behavior

Check to class_exists is made after loading and only if true will the autoloader return.

Unit Tests

Implemented testRegisterPrefix in order to add test for this codefix
Included regression test to ensure that for multiple matching prefixes, multiple files are included if required. This test should fail for older platform code and succeed on this code.

    // Regression check that multiple matching prefixes can load multiple files
    $this->assertTrue($fileTreeLeafLeafLoaded, 'Tests that included files not defining class do not abort load.');

All other tests should succeed regardless of Platform version.

garyamort added some commits Dec 16, 2012
@garyamort garyamort Fix for JLoader to handle multiple Prefix matches. IE:
prefix: DemoControllers, components/com_demo/controllers
prefix: Demo, components/com_demo

The first match will be tried, the rest of the mathces will be skipped even if it fails to find a file

Wheras:
prefix: DemoControllers, components/com_demo/controllers
prefix: DemoControllers, components/com_demo

Both will be tried.   Same prefix, multiple paths, all paths tried.  Different prefixes but related, only one works.
d087066
@garyamort garyamort Amended fix to include a check on class_exists before returning so mu…
…ltiple matching files where one does not include the class definition will be used.
f1c3a66
@garyamort garyamort Added love for testRegisterPrefix in JLoader.
Includes regression test for changes made to the loader
34f871f
@garyamort garyamort Correcting class name for stubs/tree/leaf/leaf.php so it will be loaded. 3eb30a4
@eddieajau

@garyamort is this something you think CMS 3.1 will need/want?

@dongilbert

I proposed something similar to the PHP-FIG to modify PSR-0 so that it only returns true once the class is loaded. I think this is a good patch, and would help the CMS. If @elinw or @dextercowley could confirm that they would like this in the CMS, then I think it's good to merge.

@eddieajau

Since there has been no response I'm going to close this one.

@eddieajau eddieajau closed this Apr 5, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment