Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
W
wiki-php
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • Operations
    • Operations
    • Incidents
  • Analytics
    • Analytics
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • 互联网应用开发
  • wiki-php
  • Wiki
  • code standard

Last edited by 互联网应用开发 Oct 29, 2024
Page history

code standard

风格要求


//下划线风格,操作符两边空格,字符串单引号
$user_name = '王小名';    

//双引号使用,中间引用的变量需加大括号
$info = "你的姓名:{$user_name}";
//函数 //大括号  , 参数列表空格
function eat_meat($type, $how_much) {  

}

//数组风格
$some_things = array(
    'name'=>'小小',
    'sex'=>'石头'
);
//单行注释

/*
多行
注释
*/


/**
 * 我是整个函数的说明
 * @param string $a  我是a的说明
 * @param int $b  我是b的说明
 * @return int $c  
 */
function im_func($a, $b){
    return $c;
}
//类名首字母大写
//类采用最新的方式 不再有var 这种东西
class Person {
    public $a = 1;
    private function b() {

    }
}

强制规定

  1. 代码风格强制使用上述规则
  2. 函数必须写注释
  3. 不得循环查询数据库
  4. 全局变量使用需通报所有人
  5. 不得在controller里查询数据库 调用Dao
  6. 不得在view层查询数据库
  7. 变量名不得出现拼音
  8. 变量名的长度超过3;
  9. 所有变量使用前须声明
  10. 前端过来的数据谨慎处理,第一时间考虑 注入和跨站的可能性
  11. bll层的方法 不允许出现 类似dao层的方法,需要有明确的意义
  12. 新建的类统一使用php的namespace

额外推荐

  1. 变量名超过5
  2. 不得对对象使用未声明的属性
  3. 待补充
  4. bll中的方法 尽量避免 get_xxx_by_where这种条件

AJAX返回数据格式

{
    code: 0,1,2,  //返回成功 统一取零
    data: [] | {},  //需要返回的数据
    message:"错误信息说明"
}

Swagger注释文档

swagger php参考地址案例。

Get方法

/**
     * @OA\Get(
     *     path="/mp/fc",
     *     tags={"实地认证小程序"},
     *     summary="确认用户是否有权登录",
     *     @OA\Parameter(
     *         name="openid",
     *         in="query",
     *         description="openid",
     *         example="oKlGX5OlIfu3OaE21MXFxCOodexE",
     *         @OA\Schema(
     *             type="string"
     *         )
     *     ),
     *     @OA\Parameter(
     *         name="encryptedData",
     *         in="query",
     *         description="加密数据",
     *         @OA\Schema(
     *             type="string"
     *         )
     *     ),
     *     @OA\Response(
     *         response=200,
     *         description="OK"
     *     )
     * )
     */

Post方法


    /**
     * @OA\Post(
     *     path="/mp/fc/action-ignore_item",
     *     tags={"实地认证小程序"},
     *     summary="提交实地认证放弃项目,真实地址/mp/fc",
     *     @OA\RequestBody(
     *         @OA\MediaType(
     *             mediaType="application/x-www-form-urlencoded",
     *             @OA\Schema(
     *                 @OA\Property(
     *                     property="action",
     *                     type="string",
     *                     default="submit_certification",
     *                     description="ignore_item"
     *                 ),
     *                 @OA\Property(
     *                     property="appoint_id",
     *                     default="1",
     *                     type="integer",
     *                     description="预约id"
     *                 ),
     *                 @OA\Property(
     *                     property="openid",
     *                     type="string",
     *                     default="oKlGX5OlIfu3OaE21MXFxCOodexE",
     *                     description="微信openid"
     *                 ),
     *                 @OA\Property(
     *                     property="main_type",
     *                     default="1",
     *                     type="string",
     *                     description="1为环境,2为实力"
     *                 ),
     *                 @OA\Property(
     *                     property="item_uuid",
     *                     default="1",
     *                     type="integer",
     *                     description="预约uuid"
     *                 )
     *             )
     *         )
     *     ),
     *     @OA\Response(
     *         response=200,
     *         description="OK"
     *     )
     * )
     */

安全规范

使用强类型(强制数据类型转换)。

避免使用魔术引号(Magic Quotes)。

使用预处理语句(Prepared Statements)进行数据库操作。

使用HTTPS进行敏感数据传输。

使用足够强度的密码散列。

使用防SQL注入和XSS攻击的函数。

限制文件上传类型和大小。

使用防止CSRF攻击的机制。

使用错误和异常处理。

定期更新PHP和第三方库。

Clone repository
  • 360safeguardnativeapi
  • all new classmate
  • bind phone
  • code standard
  • deploy_sys
  • edit common
  • edit master
  • envrioment
  • find psw
  • front new classmate
  • front statck
  • git
  • Home
  • idcard md5
  • ide
View All Pages