I have noticed that Laravel 4 is using some of the PSR standards. I have recently installed the SensioLabs tool php-cs-fixer that detects and fixes most of the issues when we want to follow the PHP Coding Standards.
I have execute the command in my bare Laravel 4 copy and this is the log.
php-cs-fixer fix app/
! Class User in /home/javier/Code/laravel/app/models/User.php should have at least a vendor namespace according to PSR-0 rules
! Class DatabaseSeeder in /home/javier/Code/laravel/app/database/seeds/DatabaseSeeder.php should have at least a vendor namespace according to PSR-0 rules
! Class HomeController in /home/javier/Code/laravel/app/controllers/HomeController.php should have at least a vendor namespace according to PSR-0 rules
! Class BaseController in /home/javier/Code/laravel/app/controllers/BaseController.php should have at least a vendor namespace according to PSR-0 rules
The output shows some issues related to the Autoloading Standard PSR-0.
What's going on here ??
Any help appreciated.
PSR-0, also known as the Autoloading Standard, prescribes that classes and namespaces in PHP should match the directory and file structure, and vice-versa. PSR-4 allows specifying a namespace prefix for a given directory explicitly.
This PSR describes a specification for autoloading classes from file paths. It is fully interoperable, and can be used in addition to any other autoloading specification, including PSR-0. This PSR also describes where to place files that will be autoloaded according to the specification.
After reporting the issue on the github laravel tracker i get a great response courtesy of @javiervd.
Here is the answer
The problem is that the classes inside the "app" folder do not follow PSR-0, that's why the composer autoloader uses classmap instead of PSR-0.
To quote @daylerees
Now you may be asking yourself, why doesn't Laravel set this by default?
Well Laravel doesn't know what your project is called, and what the root namespace would be. It is a zero configuration framework, meaning it should 'just work' out of the box. Class mapping is then the most sensible choice.
It makes a lot of sense.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With