PHP責任鏈設計模式

來源:互聯網
上載者:User

標籤:

<?php       //責任鏈設計模式      /**      * 每個對象,儲存著對自己上級的引用,      * 如果自己處理不了,交給上一級。      */  class board{           protected $power=1;           protected $top=‘admin‘;           public function process($lev){                if($lev<=$this->power){                 echo "版主刪帖";                }else{                $top=new $this->top;                $top->process($lev);                }           }      }      class admin{          protected $power=2;          protected $top=‘police‘;          public function process($lev){              if($lev<=$this->power){               echo "管理員封號";              }else{               $top=new $this->top;               $top->process($lev);              }          }  }  class police{         protected $power=3;         protected $top=null;         public  function process($lev){           echo ‘抓起來‘;         }  } // 責任鏈模式來處理舉報問題   $lev=$_POST[‘jubao‘]+0;   $judge=new board();   $judge->process($lev);
<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>責任鏈模式處理舉報問題</title></head><body>        <form  action="2.php" method="post">              <select  name="jubao">                        <option value="1">粗口</option>                        <option value="2">黃賭毒</option>                        <option value="3">分裂國家</option>               </select>             <button type="submit">舉報</button>        </form></body></html>

 

PHP責任鏈設計模式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.