php设计模式之面向过程实现举报功能实例代码

html

<html>
<head>
    <meta charset="UTF-8">
    <title>责任链模式</title>
</head>
<body>

<h1>责任链模式举报</h1>
    <form action="09.php" method="post">
        <select name="lev" id="">
            <option value="">全部类型</option>
            <option value="1">粗口</option>
            <option value="2">黄赌毒</option>
            <option value="3">国家分裂</option>
        </select>
        <button type="submit">举报</button>
    </form>
</body>
</html>

php

<?php 
header("Content-type:text/html;charset=utf-8");
$lev = $_POST['lev'];

if ($lev == 1) {
    $process = new Broad();
    $process->process();
}elseif ($lev == 2) {
    $process = new Admin();
    $process->process();
}elseif ($lev == 3) {
    $process = new Police();
    $process->process();
}else{
    echo "一切正常";
}
/**
* 版主
*/
class Broad
{
    public function process()
    {
        echo "版主删帖";
    }
}

/**
* 管理员
*/
class Admin
{
    public function process()
    {
        echo "封号处理";
    }
}

/**
* 公安
*/
class Police
{
    public function process()
    {
        echo "被公安抓了";
    }
}
posted @ 2020-01-12 11:56  A毛毛  阅读(274)  评论(0编辑  收藏  举报