简体   繁体   English

PSR-4是否仅适用于小包装?

[英]Is PSR-4 just for small package?

After reading the PSR-4 , I think that it'll just fit the small packages which have few directories. 阅读PSR-4之后 ,我认为它只适合目录很少的小型软件包。
If the packages are big, it'll have so many autoload functions to load from the subpackages. 如果软件包很大,它将具有很多自动加载功能可从子软件包加载。 (because we need to tell the function the base directory first) (因为我们需要先告诉函数基本目录)
Consider a CMS or Framework 考虑CMS或框架

  • admin 管理
  • extensions 扩展
  • lib LIB
    • framework 骨架
      • abstract 抽象
      • database 数据库
      • datetime 约会时间
      • functions 职能
      • Interface 接口
    • comment 评论
    • post 岗位
    • user 用户

Is PSR-0 better for this CMS package than PSR-4? 对于此CMS软件包,PSR-0是否比PSR-4更好?
Is my directory structure good ? 我的目录结构好吗?
Should interface and abstract classes have their own directory? 接口和抽象类应该有自己的目录吗?

Is PSR-4 just for small package? PSR-4是否仅适用于小包装?

No, PSR-4 is not just for small packages. 不,PSR-4不仅仅适用于小包装。 Standard frameworks like Zend and Symfony use it, too. Zend和Symfony等标准框架也使用它。

PSR-4 describes a specification for autoloading classes from file paths. PSR-4描述了从文件路径自动加载类的规范。 It makes no assumptions about the size of your project. 它不对项目的大小做任何假设。 It is fully interoperable, and can be used in addition to any other autoloading specification. 它是完全可互操作的,并且除其他任何自动加载规范外,还可以使用。 That means you can also use PSR-0. 这意味着您也可以使用PSR-0。

Is PSR-0 better for this CMS package than PSR-4? 对于此CMS软件包,PSR-0是否比PSR-4更好?

It depends. 这取决于。 If your system uses namespaces to avoid classname clashes with other vendors, then PSR-4 is the right choice. 如果您的系统使用名称空间来避免类名与其他供应商发生冲突,那么PSR-4是正确的选择。 But in general: the Autoloader doesn't care, he just eats PSR-0 and PSR-4 classes for breakfast. 但总的来说:自动装带器并不在乎,他只是吃PSR-0和PSR-4类早餐。

If you really want to know: do an A/B test and compare the autoloading speed. 如果您真的想知道:做A / B测试并比较自动加载速度。

Is my directory structure good ? 我的目录结构好吗?

It depends: if you and the users of your CMS or Framework like the structure, then yes. 这取决于:如果您和CMS或Framework的用户喜欢该结构,则可以。 If you work with Composer for dependency management, then probably lib\\ framework is a dead horse, because all packages live inside the vendor folder. 如果您使用Composer进行依赖项管理,那么lib\\ framework可能是一匹死马,因为所有软件包都位于vendor文件夹中。 If you develop a CMS, then the framework is a vendor dependency. 如果您开发CMS,则框架是供应商依赖项。

Should interface and abstract classes have their own directory? 接口和抽象类应该有自己的目录吗?

I would suggest to keep an interface or abstract base class in the same directory. 我建议将接口或抽象基类保留在同一目录中。

This saves you one folder ,) for only one or two files. 这样只会为一个或两个文件保存一个文件夹,)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM