-
-
src/Lunr/Core/Autoloader.php (Diff revision 1) I don't think this works correctly. It only checks for a full match of the namespace, but not for partial matches. Here is an example data provider for a unit test (which is also missing, btw):
public function psr4Provider() { $classes = []; $classes[] = [ 'L1\L2', 'src/Level/', 'L1\L2\L3\L4\File', 'src/Level/L3/L4/File.php' ]; $classes[] = [ 'L1\L2', 'src/Level/', 'L1\L2\L4\File', 'src/Level/L4/File.php' ]; $classes[] = [ 'L1\L2', 'src/Level/', 'L1\L2\File', 'src/Level/File.php' ]; $classes[] = [ 'L1\L2', 'src/Level/', 'L1\File', 'L1/File.php' ]; return $classes; }
based on this I came up with the following implementation:
public function get_psr4_class_filepath($class) { $namespace = substr($class, 0, strrpos($class, '\\')); $classname = str_replace('\\', DIRECTORY_SEPARATOR, $class); $class = substr($class, strrpos($class, '\\') + 1); do { if (isset($this->prefixes[$namespace]) === TRUE) { $base_path = $this->prefixes[$namespace]; $class = str_replace('\\', DIRECTORY_SEPARATOR, $class); return $base_path . $class . '.php'; } else { $class = substr($namespace, strrpos($namespace, '\\') + 1) . '\\' . $class; $namespace = substr($namespace, 0, strrpos($namespace, '\\')); } } while (strrpos($namespace, '\\') > 1); return $classname . '.php'; }
-
src/Lunr/Core/Autoloader.php (Diff revision 1) we're not setting a namespace, we're setting the path for a namespace prefix, so IMHO "set_prefix" would be a better name.
-
src/Lunr/Core/Autoloader.php (Diff revision 1) adding an include path should never happen automagically. This can cause all kinds of really hard to debug problems.
Change Summary:
Attempt #3 I Guess?
Commit: |
|
||||
---|---|---|---|---|---|
Diff: |
Revision 2 (+209 -37) |
-
I think the unique AutoloaderTest.php file deserves to be split now :/
I think we miss some testing with multiple prefixes set (to test the order mainly)
Let say for example we have as prefixes
- Foo\Bar => /libs/yoyo
- Foo\Bar\Baz => /libs/hehe
and as files
- /libs/yoyo/Baz/Qux.php
- /libs/hehe/Qux.php
then I think
\Foo\Bar\Baz\Qux
should resolve to
the hehe libs file -
src/Lunr/Core/Autoloader.php (Diff revision 2) I think psr4 should be looked at first
since this is the "official" one nowin case we have 2 files:
- libs/Foo/Bar_Baz.php
- libs/Foo/Bar/Baz.php\Foo\Bar_Baz should resolve to the first file
while I think it will resolve to second one with the current codeThis order thing should be unit tested as well then
-
src/Lunr/Core/Tests/AutoloaderTest.php (Diff revision 2) I think we should have more than these
- use of underscore in namespace
- use of underscore in class name
- multiple levels of partial class
- multiple levels of partial path
-... -
src/Lunr/Core/Tests/AutoloaderTest.php (Diff revision 2) you never use $fullClass or $fullPath in here
You should use a different provider for this function if needed or none at all -
src/Lunr/Core/Tests/AutoloaderTest.php (Diff revision 2) I have a bit of trouble seeing what this test more than the previous function
Either remove or make the description more precise
Change Summary:
Commit: |
|
||||
---|---|---|---|---|---|
Diff: |
Revision 3 (+442 -188) |
Change Summary:
Can we now please be done with psr-4?
Commit: |
|
||||
---|---|---|---|---|---|
Diff: |
Revision 4 (+474 -209) |