Src versus src directory in packages
Permalink
Hi all,
when we need to use custom classes in package in 5.7, the rule is to add them to a src directory, i.e. a file like:
/packages/my_package/src/Whatever/MyCustomClass.php
Then the namespace for this would be
Concrete\Package\MyPackage\Src\Whatever
This all works fine for me, but on a particular server we use, where I think it has a case sensitive file system, the above combination results in a class not found error.
If I either change the src folder to Src, or the Src in the namespace to src, it then finds it.
In other words, I'm finding that the folder name and the equivalent in the namespace has to have the same capitalisation.
Can anyone advise why this might be the case? Does it sound like I'm doing something wrong?
It sort of seems like the autoloader for class packages is just looking for the Src directory, directly based off the string it finds, and on case insensitive file systems that's fine, but on case sensitive ones it fails. Maybe it needs to forced to look for a lowercase directory?
when we need to use custom classes in package in 5.7, the rule is to add them to a src directory, i.e. a file like:
/packages/my_package/src/Whatever/MyCustomClass.php
Then the namespace for this would be
Concrete\Package\MyPackage\Src\Whatever
This all works fine for me, but on a particular server we use, where I think it has a case sensitive file system, the above combination results in a class not found error.
If I either change the src folder to Src, or the Src in the namespace to src, it then finds it.
In other words, I'm finding that the folder name and the equivalent in the namespace has to have the same capitalisation.
Can anyone advise why this might be the case? Does it sound like I'm doing something wrong?
It sort of seems like the autoloader for class packages is just looking for the Src directory, directly based off the string it finds, and on case insensitive file systems that's fine, but on case sensitive ones it fails. Maybe it needs to forced to look for a lowercase directory?
I've tracked this down.
It came down to the accidental use of
in my package controller. I'm not sure why I put it in there in the first place, but I think the assumption is that when you use this that you don't/can't use the normal Src way of loading in classes, you need to be using your own custom autoloader.
So me turning this boolean off fixed my class not found issue.
It came down to the accidental use of
$pkgAutoloaderMapCoreExtensions = true;
So me turning this boolean off fixed my class not found issue.
That is generally correct. Everything that concrete5 needs to auto-map (e.g. \Concrete\Package\MyPackage\Captcha\MyCaptcha.php) will automatically route into
packages/my_package/src/Concrete/Captcha/MyCaptcha.php
with you free to specify your own autoloader into the src/ directory.
packages/my_package/src/Concrete/Captcha/MyCaptcha.php
with you free to specify your own autoloader into the src/ directory.
This doesn't exactly address your problem directly, but I wonder if it would offer some benefit.
Have you checked out the "Removing \Src from Package and Application Class Files" section on the documentation?
https://www.concrete5.org/documentation/developers/5.7/packages/addi...