本规范由编程原则组成,融合并提炼了开发人员长时间积累下来的成熟经验,意在帮助形成良好一致的编程风格。以达到事半功倍的效果,如果有需要本文档会不定期更新。

  1. 适用范围
    如无特殊说明,以下规则要求完全适用于基于Zero框架框架开发的应用,同时也可大部分适用于部门其他PHP项目。

  2. 标准化作用
    当一个软件项目尝试着遵守公共一致的标准时,可以使参与项目的开发人员更容易了解项目中的代码、弄清程序的状况。使新的参与者可以很快的适应环境,防止部分参与者出于节省时间的需要,自创一套风格并养成终生的习惯,导致其它人在阅读时浪费过多的时间和精力。而且在一致的环境下,也可以减少编码出错的机会。
    缺陷是由于每个人的标准不同,所以需要一段时间来适应和改变自己的编码风格,暂时性的降底了工作效率。从使项目长远健康的发展以及后期更高的团队工作效率来考虑暂时的工作效率降低是值得的,也是必须要经过的一个过程。标准不是项目成功的关键,但可以帮助我们在团队协作中有更高的效率并且更加顺利的完成既定的任务。

    1) 程序员可以了解任何代码,弄清程序的状况
    2) 新人可以很快的适应环境
    3) 防止新接触PHP的开发出于节省时间的需要,自创一套风格并养成终生的习惯
    4) 防止新接触PHP的开发一次次的犯同样的错误
    5) 在一致的环境下,可以减少犯错的机会

This specification is composed of programming principles, which integrates and refines the mature experience accumulated by developers for a long time, and is intended to help form a good and consistent programming style. In order to achieve twice the result with half the effort, this document will be updated from time to time if necessary.

  1. Scope of application
    Unless otherwise specified, the following rule requirements are fully applicable to applications developed based on zero framework framework, and can also be mostly applicable to other PHP projects in the Department.
  2. Standardization
    When a software project attempts to comply with public and consistent standards, it can make it easier for developers involved in the project to understand the code in the project and understand the status of the program. So that the new participants can quickly adapt to the environment, to prevent some participants from creating a set of style and developing a lifelong habit for the sake of saving time, resulting in other people wasting too much time and energy in reading. And in a consistent environment, it can also reduce the chance of coding errors.
    The defect is that because everyone’s standards are different, it takes a period of time to adapt to and change their coding style, temporarily reducing the work efficiency. From the long-term healthy development of the project and the later higher team work efficiency to consider the temporary work efficiency reduction is worth, but also a process that must be passed. Standards are not the key to the success of a project, but they can help us to be more efficient in team work and accomplish the tasks we have set more smoothly.

1) Programmers can understand any code and understand the status of the program
2) New people can quickly adapt to the environment
3) Prevent the development of new PHP to save time, create a set of style and form a lifelong habit
4) Prevent new PHP developers from making the same mistakes over and over again
5) In a consistent environment, you can reduce your chances of making mistakes

命名规范

ShopSuite遵循PSR-2命名规范和PSR-4自动加载规范,并且注意如下规范:

目录和文件

类库、函数文件统一以.php为后缀;
类的文件名以下划线及目录命名方式,则类名路径和类库文件所在路径一致;
类的文件名以命名空间定义,并且命名空间的路径和类库文件所在路径一致;
类(包含接口和Trait)文件采用驼峰法命名(首字母大写),其它文件采用小写+下划线命名;
类名(包括接口和Trait)和文件名保持一致,统一采用驼峰法命名(首字母大写);

函数和类、属性命名

类的命名采用驼峰法(首字母大写),例如 UserUserType
函数的命名使用小写字母和下划线(小写字母开头)的方式,例如 get_client_ip
方法的命名使用驼峰法(首字母小写),例如 getUserName
属性的命名使用驼峰法(首字母小写),例如 tableNameinstance
特例:以双下划线打头的函数或方法作为魔术方法,例如 `call__autoload`;

常量和配置

常量以大写字母和下划线命名,例如 APP_PATH
配置参数以小写字母和下划线命名,例如 url_route_onurl_convert
环境变量定义使用大写字母和下划线命名,例如DB_DEBUG

数据表和字段

数据表和字段采用小写加下划线方式命名,并注意字段名不要以下划线开头,例如 account_user_base 表和 user_account字段,不建议使用驼峰和中文作为数据表及字段命名。
请理解并尽量遵循以上命名规范,可以减少在开发过程中出现不必要的错误。

默认不可以使用变量,请求中,如果三个变量是系统内置变量,不可以使用

perm_id
perm_key
ss_site_id

文档更新时间: 2021-12-20 14:40   作者:随商信息技术(上海)有限公司