简体   繁体   English

哪个版本的PSR有效?

[英]Which version of PSR is valid?

Maybe I don't understand fully. 也许我完全不明白。 I read that PSR is PHP Standard Recommendation, but there are several version of PSR, For Example autoloader use PSR-4 instead Basic Coding Standard use PSR-1 我读到PSR是PHP标准推荐,但有几个版本的PSR,例如自动加载器使用PSR-4而不是基本编码标准使用PSR-1

I have to follow a specific PSR version Or I have to merge the good parts of them ? 我必须遵循特定的PSR版本或者我必须合并它们的好部分?

Symfony follows the standards defined in the PSR-0, PSR-1, PSR-2 and PSR-4 documents,Then each framework uses different PSR ? Symfony遵循PSR-0,PSR-1,PSR-2和PSR-4文档中定义的标准,然后每个框架使用不同的PSR?

You can see the PSRs as one huge coding standard. 您可以将PSR视为一个巨大的编码标准。 They depend on each other but every PSR stands alone for itself. 它们相互依赖,但每个PSR都独立存在。 PSR-2 describes Coding Style Guide while PSR-4 describes the standard for Autoloading . PSR-2描述了编码风格指南,而PSR-4描述了自动加载的标准。

Here is a website about the PHP Standards Recommendations . 这是一个关于PHP标准建议的网站。 You can find there a full list of all existing PSR. 您可以找到所有现有PSR的完整列表。

PSR means PHP Standard RECOMMENDATION - so it is only a recommendation on how to handle/format a specific part of a php-application. PSR意味着PHP标准推荐 - 所以它只是关于如何处理/格式化php应用程序的特定部分的建议。 The index is just a ID to identify what the psr is good for. 索引只是一个ID,用于标识psr的优点。 Do not understand it as a version-number. 不要将其理解为版本号。 PSR-0 and PSR-4 both cover the handling of Autoloader. PSR-0和PSR-4都涵盖了Autoloader的处理。

The PHP Standard Recommendation is about how you should write your code so that it'll be easily readable and usable by others. PHP标准建议书是关于如何编写代码的,以便其他人可以轻松阅读和使用。 It covers topics like coding style, file organization, autoloading and standardizes various interfaces. 它涵盖了编码风格,文件组织,自动加载和标准化各种界面等主题。 The PSR was thought up by the Framework Interoperability Group (FIG), which came into being at the php|tek 2009 conference. PSR由框架互操作性小组(FIG)提出,该小组在2009年的PHP会议上形成。 Its members include the authors of various well-known PHP frameworks. 其成员包括各种着名的PHP框架的作者。 The PSR is in no way “official”; PSR绝不是“官方”的; it's just that the Framework Interoperability Group (FIG) contains a nice cross-section of experienced PHP developers, who vote on whatever the best coding style should be. 只是框架互操作性组(FIG)包含了一个经验丰富的PHP开发人员的优秀横截面,他们对最佳编码风格应该投票。 As such, you can follow all or part of PSR, or none of it. 因此,您可以关注全部或部分PSR,或者不遵循PSR。 It's up to you really, but some projects that you want to contribute to may require that you follow some of the PSR, just so that everyone is on the same page. 这真的取决于你,但是你想要贡献的一些项目可能需要你遵循一些PSR,这样每个人都在同一页面上。 There's nothing wrong with having a standard where there wasn't one before. 拥有一个以前没有标准的标准没有错。

So who's a member? 那么谁是会员呢? There are over 20 members now (from 5 when they started), and they include the authors of CakePHP, Composer, Zend, Lithium, SugarCRM and Symphony. 现在有超过20个成员(从他们开始时的5个成员),他们包括CakePHP,Composer,Zend,Lithium,SugarCRM和Symphony的作者。 People who've been around the PHP block, so to speak. 可以这么说,那些曾经使用PHP块的人。

As for the PSR standards themselves, there are about 17 of them, but only 7 have been accepted by all members. 至于PSR标准本身,其中大约有17个,但只有7个被所有成员接受。 The rest are still being voted on, or have draft status [as of September 2016]. 其余的仍在投票,或具有草案地位[截至2016年9月]。

(I wrote this article which looks at PSR-1 in detail as an example.) (我写这篇文章详细介绍了PSR-1作为一个例子。)

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

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