Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Some Laravel 4 PSR-0 issues?

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.

like image 216
Javier Cadiz Avatar asked Feb 11 '13 18:02

Javier Cadiz


People also ask

What is the difference between PSR-0 and PSR 4?

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.

What is PSR 4 Laravel?

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.


1 Answers

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.

like image 139
Javier Cadiz Avatar answered Sep 22 '22 02:09

Javier Cadiz