介绍
本篇文章为大家展示了PHP中面向对象的标识对象是什么,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。
<强>标识对象模式强>
这个模式主要功能就是创建sql语句中的wehre条件字符串的,下面直接看代码和注释:
namespace 吸引\映射器;//字段对象 class Field  { protected 才能;name 美元;=,零,,,,,,//字段名称 protected 才能;operator 美元;=,零,,,,,,//操作符,, protected 才能;comps 美元;=,数组();,,,,,//存放条件的数组,, protected 才能;incomplete 美元;=,假的,,,,//检查条件数组是否有值 ,, 美元function 才能;__construct (名字){ ,,,这个→美元name=,美元名称; ,,} ,,//才能添加where 条件 function 才能addTest(运营商,美元价值){ ,,,这个→美元比较[],=,数组(& # 39;名字# 39;=祝辞;$ this→名称,& # 39;运营商# 39;=祝辞美元运营商& # 39;价值# 39;=祝辞美元值); ,,} ,,//才能获取存放条件的数组 function 才能;getComps () { ,,,return $ this→比较; ,,} ,, function 才能;isIncomplete () { ,,,return 空($ this→比较); ,,} }//标识对象 class IdentityObject  { protected 才能;currentfield 美元;=,零,,,,,//当前操作的字段对象 protected 才能;fields 美元;=,数组();,,,,//字段集合 private 才能;以及美元=,空; private 才能;enforce 美元;=,数组();,,,,,,//限定的合法字段,,,, ,, function 才能;__construct ($ field =, null,, array enforce 美元;=,null) { ,,,如果(! is_null(执行美元)){ ,,,,,这个→美元enforce =,执行美元; ,,,} ,,,如果(! is_null(字段)美元){ ,,,,,这个→美元字段(字段); ,,,} ,,} ,,//才能获取限定的合法字段 function 才能;getObjectFields () { ,,,return $ this→执行; ,,} ,,//主才能要功能为设置当前需要操作的对象 function 才能;字段(字段名美元){ ,,,如果(! $ this→isVoid(),,,这个→美元currentfield→isIncomplete ()) { ,,,,,throw new \异常(“Incomplete field"); ,,,} ,,,这个→美元enforceField($字段名); ,,,如果收取($ this→字段(字段名美元)){ ,,,,,这个→美元currentfield =, $ this→字段(字段名美元); ,,,},{else ,,,,,这个→美元currentfield =, new 字段(字段名美元); ,,,,,这个→美元字段(字段名美元),=,$ this→currentfield; ,,,} ,,,return 美元,,,,,,,,,,,//采用连贯语法 ,,} ,,//字才能段集合是否为空 function 才能;isVoid () { ,,,return 空($ this→字段); ,,} ,,//检才能查字段是否合法 function 才能;enforceField (字段名美元){ ,,,如果(! in_array(字段名,这美元→执行),,,,!空($ this→执行)){ ,,,,,forcelist 美元;=,内爆(& # 39;& # 39;$ this→执行); ,,,,,throw new \异常(“{$ fieldname}, not a legal field {$ forcelist}“); ,,,} ,,} ,, ,,//向才能字段对象添加在条件 function 才能;eq(美元值){ ,,,return $ this→操作符(“=?价值美元); ,,} ,, function 才能lt(美元值){ ,,,return $ this→操作符(“& lt;“美元值); ,,} ,, function 才能;gt(美元值){ ,,,return $ this→操作符(““,美元值); ,,} ,,//向才能字段对象添加在条件 private 才能;function 运营商(象征,美元价值){ ,,,如果($ this→isVoid) { ,,,,,throw new \异常(“no  object field defined"); ,,,} ,,,这个→美元currentfield→addTest(象征,价值美元); ,,,return 美元,,,,,,,,,,,,,,,,,,,,//采用连贯语法 ,,} ,,//才能获取此类中所有字段对象集合的地方条件数组 function 才能;getComps () { ,,,ret 美元;=,数组(); null null null null null null null null null null null null null null null null null null null null null null nullPHP中面向对象的标识对象是什么