PHP-CLI操作

检查php语法 syntax check

php -l test.php

在git commit前检查php语法,防止提交到生产环境

#!/bin/bash

#loop trough the modified files
for file in $(git diff-index --name-only HEAD); do
    if [[ $file =~ ".php" ]]; then
        echo $file
        message=$(php -l $file)
        if [[ $message == *error* ]]; then
            echo "Commit failed. Please fix errors and recommit."
            exit 1;
        fi
    fi
done;
     

posted on 2021-06-22 15:00  aworkstory  阅读(62)  评论(0编辑  收藏  举报

导航