vscode 代码片段 php.json

发布时间 2024-01-02 09:51:30作者: 会飞的鹏
{
    // Place your snippets for php here. Each snippet is defined under a snippet name and has a prefix, body and
    // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
    // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
    // same ids are connected.
    // Example:
    // "Print to console": {
    //  "prefix": "log",
    //  "body": [
    //      "console.log('$1');",
    //      "$2"
    //  ],
    //  "description": "Log output to console"
    // }
    "public": {
        "prefix": "public",
        "body": [
       
            "public function $1($2):$3",
            "{",
            "    $4",
            "}"
        ],
        "description": "Log output to console"
    },
    "protected": {
        "prefix": "protected",
        "body": [
       
            "protected function $1($2):$3",
            "{",
            "    $4",
            "}"
        ],
        "description": "Log output to console"
    },
    "private": {
        "prefix": "private",
        "body": [
       
            "private function $1($2):$3",
            "{",
            "    $4",
            "}"
        ],
        "description": "Log output to console"
    },
    "static": {
        "prefix": "static",
        "body": [
       
            "public static function $1($2):$3",
            "{",
            "    $4",
            "}"
        ],
        "description": "Log output to console"
    },
    "foreach": {
        "prefix": "foreach",
        "body": [
            "foreach($1 as \\$key=>\\$item){",
            "    $2",
            "}"
        ],
        "description": "Log output to console"
    },
    "if": {
        "prefix": "if",
        "body": [
            "if($1){",
            "    $2",
            "}"
        ],
        "description": "Log output to console"
    },
    "startTrans": {
        "prefix": "startTrans",
        "body": [
            "Db::startTrans();",
            "try {",
            "    $1",
            "    // 提交事务",
            "    Db::commit();",
            "} catch (\\Exception \\$e) {",
            "    // 回滚事务",
            "    Db::rollback();",
            "    throwError(\\$e->getMessage());",
            "}",
            "return true;",
        ],
        "description": "Log output to console"
    },
    "transaction": {
        "prefix": "transaction",
        "body": [
            "transaction(function () use ($1) {",
            "    $2",
            "});",
        ],
        "description": "Log output to console"
    },
}