I see an issue with your PSR-4 declaration.
You shouldn't place "Core" classes inside a folder that has subfolders for other namespaces.
PSR-4 autoloading in Composer works like this: If the fully qualified class name of the class to load matches a prefix declared in any of the PSR-4 definitions, then the prefix mentioned in the prefix is removed from the class name, and the remaining class name is mapped to a filename and being searched.
If you have classes named Application\
in the folder application/modules
, and you have classes named Core\
in the folder application
, then technically Composer might find files that match a class name like Core\modules\Whatever
, although these file will contain a class Application\Whatever
instead.
I recommend moving all the Core
classes into their own folder and point to this in the PSR-4 declaration.
The problem with your original question is that you omit an important information: What is the class and file structure for your modules?
Composer's autoloader will happily resolve any class that starts with the namespace prefix Application
, remove that prefix from the classname, convert the remainders into a path name and search for that file in application/modules/
. Given that you have a module class Application\MyModule\Foobar
, it will be searched in application/modules/MyModule/Foobar.php
. Why? Because the prefix Application
will be removed to allow for shorter path names in PSR-4. (Using PSR-0 would mean you have to have a folder for every level of namespace in the classname.)
Note that it is recommended for optimum performance to make the prefix for namespaces as long as possible, because Composer allows to have more than one directory for any given prefix, but then has to search for the correct file in more than one directory. Searching for files is time consuming!
Application\foo\Bar
will look atapplication/modules/foo/Bar.php
. I get tripped up so often by this I decided I'd finally commit it to memory by writing it down! – bishop