码迷,mamicode.com
首页 > 其他好文 > 详细

psr-0 和 psr-4

时间:2017-09-02 16:58:57      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:between   tps   scribe   autoload   new   not   director   efi   als   

PSR-4 is something like ‘relative path‘, PSR-0, ‘absolute path‘.

e.g.

config:

‘App\Controller‘ => ‘dir/‘

PSR-0 autoload:

App\Controller\IndexController --> dir/App/Controller/IndexController.php

PSR-4 autoload:

App\Controller\IndexController --> dir/IndexController.php

And there are some more difference in details between PSR-0 and PSR-4, see here: http://www.php-fig.org/psr/psr-4/

 

=======

They are very similar so it is not surprising that it‘s a bit confusing. The summary is that PSR-0 had some backwards compatibility features for PEAR-style classnames that PSR-4 dropped, as such it only supports namespaced code. On top of that PSR-4 does not force you to have the whole namespace as a directory structure, but only the part following the anchor point.

For example if you define that the Acme\Foo\ namespace is anchored in src/, with PSR-0 it means it will look for Acme\Foo\Bar in src/Acme/Foo/Bar.php while in PSR-4 it will look for it in src/Bar.php, allowing for shorter directory structures. On the other hand some prefer to have the full directory structure to clearly see what is in which namespace, so you can also say that Acme\Foo\ is in src/Acme/Foo with PSR-4 which will gives you the equivalent of the PSR-0 behavior described above.

Long story short for new projects and for most intents and purposes, you can use PSR-4 and forget all about PSR-0.

=======

 

https://stackoverflow.com/questions/24868586/what-is-the-difference-between-psr-0-and-psr-4

 

psr-0 和 psr-4

标签:between   tps   scribe   autoload   new   not   director   efi   als   

原文地址:http://www.cnblogs.com/qinqiu/p/7466824.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!