-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
fix issue where running FileLocator::getClassname() on a directory would cause a PHP error #8216
fix issue where running FileLocator::getClassname() on a directory would cause a PHP error #8216
Conversation
How can we reproduce the error? It seems
|
@@ -119,6 +119,10 @@ public function locateFile(string $file, ?string $folder = null, string $ext = ' | |||
*/ | |||
public function getClassname(string $file): string | |||
{ | |||
if(is_dir($file)) { | |||
return ''; | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this code is okay (if the coding style is fixed), because a directory is never a class.
@kenjis you can reproduce the error by following the exception that is posted with a directory in your Commands folder. a dump of the array Produces:
So there could be a bug with the get_filenames function you've referenced. This is running on PHP 7.4.21 |
Sorry, I had a modification made to the get_filenames so that it follows symlinks as well which wasn't updated with the additional include directories parameter. Its working now, still probably a worthwhile check to be making though. As a sidenote, should get_filenames just follow symlinks by default or as a global config option? |
$ ls -l
total 16
-rw-r--r-- 1 kenji staff 1579 10 27 16:48 BaseController.php
-rw-r--r-- 1 kenji staff 204 11 16 08:59 Home.php
lrwxr-xr-x 1 kenji staff 8 11 16 09:00 Symlink.php -> Home.php <?php
namespace App\Controllers;
class Home extends BaseController
{
public function index(): string
{
helper('filesystem');
dd(get_filenames(APPPATH . 'Controllers/'));
}
} |
It finds symlinks to files that are directly within the structure, but if a folder is symlinked it won't go into the folder due to the configuration of the RecursiveDirectoryIterator it would need to change from:
to
|
fix issue where running getClassName on a directory would cause a PHP
Description
This issue specifically comes up when you put commands in folders for better organization, the previous setup used
findQualifiedNameFromPath
instead ofgetClassname
,getClassname
has no checking to see if what is passed in is a directory, which could easily happen aslistFiles
can return directories as well as files.Potential other solutions to this would be to prevent
listFiles
from returning directories, or filtering the list of files prior to runninggetClassname
indiscoverCommands
Checklist: