/* Identity Object mode The main function of this mode is to create the Wehre condition string in the SQL statement, and see the code and comments directly below: */namespace woo\mapper;//Field object class Field {protected $name = null; Field name protected $operator = NULL; Operator protected $comps = Array (); Array protected $incomplete = False for the storage condition; Checks if the condition array has value function __construct ($name) {$this->name= $name; }//Add Where Condition function addtest ($operator, $value) {$this->comps[] = Array (' name ' = = $this->name, ' operator ' = > $operator, ' value ' = $value); }//Gets the array function getcomps () {return $this->comps; that holds the condition } function Isincomplete () {return empty ($this->comps); }}//Identity Object class Identityobject {protected $currentfield = null; The Field object of the current operation protected $fields = Array (); Field Collection Private $and = null;private $enforce = Array (); Qualified legal field function __construct ($field = null, array $enforce = null) {if (!is_null ($enforce)) {$this->enforce = $en Force }if (!is_null ($field)) {$this->field ($field); }}//Get qualified legal fields FuNction Getobjectfields () {return $this->enforce; }//The main function is to set the Object function field ($fieldname) {if (! $this->isvoid () && $this->currentfield-> Isincomplete ()) {throw new \exception ("incomplete field"); } $this->enforcefield ($fieldname), if (Isset ($this->fields[$fieldname]) {$this->currentfield = $this fields[$fieldname]; } else {$this->currentfield = new Field ($fieldname); $this->fields[$fieldname] = $this->currentfield; }return $this; Use coherent syntax}//field collection is null function isvoid () {return empty ($this->fields); }//Check if the field is legal function Enforcefield ($fieldname) {if (!in_array ($fieldname, $this->enforce) &&!empty ($this- >enforce) {$forcelist = implode (', ', $this->enforce); throw new \exception ("{$fieldname} not a legal field {$ Forcelist} "); }}//Add a Where condition to the Field object function eq ($value) {return $this->operator ("=", $value); } function lt ($value) {return $this->operator ("<", $vAlue); } function gt ($value) {return $this->operator (">", $value); }//Add a Where condition to the Field object private function operator ($symbol, $value) {if ($this->isvoid) {throw new \exception ("no object field defined "); } $this->currentfield->addtest ($symbol, $value); return $this; Use coherent syntax}//Get the Where condition array for all the Field object collections in this class function Getcomps () {$ret = array (); foreach ($this->fields as $key = = $field {$ret = Array_merge ($ret, $field->getcomps ()); }return $ret; }}//client Code $idobj = new Identityobject (), $idobj->field ("name")->eq ("The Good Show")->field ("Start")->gt ( Time ())->lt (Time () + (24*60*60)), $test = $idobj->getcomps (), Var_dump ($test);//output similar to the following/*array{array (' name ' = > ' name ', ' operator ' = ' = ', ' value ' = ' The Good Show '), Array (' name ' = = ' start ', ' operator ' = ' > ', ' Value ' = = ' 123456 '),//123456 represents the time () function output timestamp array (' name ' = ' = ' start ', ' operator ' = ' < ', ' value ' = = ') 123456 ')}*/