This article introduces the PHP simple complaint page implementation code, share for everyone to reference, the specific content as follows
PHP Code:
<?php/* Design mode Practice * 1. Database connection Class (single case mode) * 2. Call the interface to implement the function of the message (Factory mode) * 3. Implement the Classification report processing function (responsibility chain mode) * 4. Send different combinations of reporting information (bridging mode) * 5. Send different formats Report information (adapter mode) * 6. Automatically append time after complaint content (adorner mode) * 7. According to the member login information to change the display style (Observer mode) * 8. According to the posting length plus experience value (policy mode) * * * interface DB {function con
N ();
/** * Single Case mode */class Mysqlsingle implements DB {protected static $_instance = NULL;
public static function getinstance () {if (!self::$_instance instanceof self) {self::$_instance = new self;
return self::$_instance;
Final protected function __construct () {echo ' MySQL single example create success <br> ';
Final protected function __clone () {return false;
Public Function conn () {echo ' MySQL connection succeeded <br> ';
}/** * Factory mode * * Interface Factory {function createdb ();}
Class Mysqlfactory implements Factory {public Function createdb () {echo ' MySQL factory create success <br> ';
return Mysqlsingle::getinstance (); }/** * Display different styles according to user name * Observer mode/class Observer implements Splsubject {
protected $_observers = NULL;
Public $_style = NULL;
Public function __construct ($style) {$this->_style = $style;
$this->_observers = new Splobjectstorage ();
Public function Show () {$this->notify ();
The Public function attach (Splobserver $observer) {$this->_observers->attach ($observer);
The Public function detach (Splobserver $observer) {$this->_observers->detach ($observer);
Public Function Notify () {$this->_observers->rewind ();
while ($this->_observers->valid ()) {$observer = $this->_observers->current ();
$observer->update ($this);
$this->_observers->next (); }} class Stylea implements Splobserver {public Function update (Splsubject $subject) {echo $subject->_st Yle.
' Module a<br> '; } class Styleb implements Splobserver {public Function update (Splsubject $subject) {echo $subject->_style .
' Module b<br> '; }
}
/**
* According to different ways of complaint * Bridging mode * * Class Bridge {protected $_obj = NULL;
Public function __construct ($obj) {$this->_obj = $obj;
The Public Function, MSG ($type) {} public Function Show () {$this->msg ();
$this->_obj->msg ();
Class Bridgeemail extends Bridge {public Function msg () {echo ' email>> ';
Class Bridgesms extends Bridge {public Function msg () {echo ' sms>> ';
Class Normal {public Function msg () {echo ' normal<br> ';
Class Danger {public Function msg () {echo ' danger<br> ';
}/** * Adapter mode/class Serialize {public $content = NULL;
Public function __construct ($content) {$this->content = serialize ($content);
The Public Function show () {return ' serialization format:<br> '. $this->content;
Class Jsonadapter extends Serialize {public function __construct ($content) {parent::__construct ($content); $tmp = unserialize ($this->content);
$this->content = Json_encode ($tmp, TRUE);
The Public Function show () {return ' JSON format:<br> '. $this->content;
}/** * Automatically append * Adorner mode after complaint content */class Base {protected $_content = NULL;
Public function __construct ($content) {$this->_content = $content;
The Public Function getcontent () {return $this->_content;
} class Decorator {private $_base = NULL;
Public function __construct (Base $base) {$this->_base = $base; The Public Function show () {return $this->_base->getcontent (). ' >> system time: '.
Date (' y-m-d h:i:s ', Time ());
/** * Classification Report Processing function * Responsibility CHAIN mode * * * class Level1 {protected $_level = 1;
protected $_top = ' Level2 ';
Public function Deal ($level) {if ($level <= $this->_level) {echo ' Processing level:1<br> ';
Return
} $top = new $this->_top;
$top->deal ($level);
} class Level2 {protected $_level = 2;
protected $_top = ' Level3 '; PuBlic function Deal ($level) {if ($level <= $this->_level) {echo ' Processing level:2<br> ';
Return
} $top = new $this->_top;
$top->deal ($level);
} class Level3 {protected $_level = 3;
protected $_top = ' Level2 ';
Public function Deal ($level) {echo ' Processing level:3<br> ';
Return
} if (!empty ($_post)) {echo '
HTML code:
<!
DOCTYPE Html> <!--to the change this license header, choose License Headers in Project Properties. To change this template file, choose Tools |
Templates and open the template in the editor. -->
The above is the entire content of this article, I hope to help you learn.