我注意到Laravel 4正在使用一些PSR标准.我最近安装了SensioLabs工具php-cs-fixer,当我们想要遵循PHP编码标准时,它会检测并修复大多数问题.
我在我的裸Laravel 4副本中执行命令,这是日志.
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
输出显示了与自动加载标准PSR-0相关的一些问题.
这里发生了什么 ??
任何帮助赞赏.
解决方法:
在github laravel tracker上报告了这个问题之后,我得到了很好的响应,由@javiervd提供.
这是答案
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.
这很有道理.
标签:php,laravel,composer-php
来源: https://codeday.me/bug/20190520/1143377.html