<?PHP/** * Public Resources class * * **/classCommon {/** * General JSON return data * $code int returns an error code * $MSG string returns an error message * $data array returned by*/ Public Staticfunction Echoresult ($code =0, $msg ="', $data =Array ()) {$result=Array ('Code'=$code,'msg'=$msg,'Data'=$data); Echo Json_encode ($result, Json_unescaped_unicode); Exit } /** * processing parameter filter For form submission * $string string or array to be processed by string * @return string returns the string or array after processing*/ Public StaticFunction Dtrim ($string){ if(Is_array ($string) {$keys= Array_keys ($string); foreach($keys as$key) {$val= $string[$key]; Unset ($string[$key]); $string[Trim ($key)] =Self ::D trim ($val); } } Else { $string= Trim ($string); } return$string; } /** * Processing the parameter filter for form submission * $string string or array to be processed $force Boolean forced to process * @return string returned after processing String or array*/ Public StaticFunction Daddslashes ($string, $force =1) { if(Is_array ($string) {$keys= Array_keys ($string); foreach($keys as$key) {$val= $string[$key]; Unset ($string[$key]); $string[Addslashes ($key)] =Self ::d addslashes ($val, $force); } } Else { $string= Addslashes ($string); } return$string; } //please refer to PHP built-in methods Htmlspecialchars Public StaticFunction Dhtmlspecialchars ($string, $flags =Ent_compat) { if(Is_array ($string)) { foreach($string as$key =$val) { $string[$key] =Self ::d htmlspecialchars ($val, $flags); } } Else { if($flags = = =NULL) { $string= Str_replace (Array ('&','"','<','>'), Array ('&','"','<','>'), $string); if(Strpos ($string,'&#') !==false) { $string= Preg_replace ('/& ((# (\d{3,5}|x[a-fa-f0-9]{4}));)/','&\\1', $string); } } Else { if(Php_version <'5.4.0') { $string= Htmlspecialchars ($string, $flags); } Else{$charset='UTF-8'; $string= Htmlspecialchars ($string, $flags, $charset); } } } return$string; } //please refer to PHP built-in methods Stripslashes Public StaticFunction Dstripslashes ($string) { if(Empty ($string))return$string; if(Is_array ($string)) { foreach($string as$key =$val) { $string[$key] =Self ::d stripslashes ($val); } } Else { $string= Stripslashes ($string); } return$string; } /** Function Name: Verifyid () * Function: Verify the Submitted ID class value is valid * parameter: $id: The ID value of the submitted * return value: Returns the processed ID **/ Public Staticfunction Verifyid ($id =NULL) { if(!$id) { return 0; } //is null-judgedElseIf (Self::inject_check ($id)) {return 0; } //Injection JudgmentElseIf (!is_numeric ($id)) { return 0 ; } //Digital Judgment$id = Intval ($id);//The whole type of return$id; } /** Detection of submitted values is not a character that contains SQL injections, prevents injections, protects server security * Parameters: $sql _STR: Committed variable * return value: Return test result, ture or false*/ Public Staticfunction Injectcheck ($sql _str) {return@eregi ('select|insert|and|or|update|delete|\ ' |\/\*|\*|\.\.\/|\.\/|union|into|load_file|outfile', $sql _str);//to filter } /** * Import files and instantiate, the default import is business this folder under the file * $filename string $layer model layer Name * Return Object*/ Public Staticfunction importbusiness ($name =NULL) {$layer=" Business"; $class=$name. Ucfirst ($layer); Static$_obj=Array (); if(Isset ($_obj[$name])) {return$_obj[$name]; } if(!file_exists (App_path."/application/{$layer}/{$class}.php") ) {exit ("file {$class}.php is not exists"); } yaf_loader::import (App_path."/application/business/{$class}.php");//Import the class library (Business logic class library, etc.)$_obj[$name] =New$class(); return$_obj[$name]; } /** * Import files and instantiate, the default import is business this folder under the file * $filename string $layer model layer Name * Return Object*/ Public Staticfunction importmodulesbusiness ($name =NULL, $modules =NULL) {$layer=" Business"; $class=$name. Ucfirst ($layer); Static$_obj=Array (); if(Isset ($_obj[$name])) {return$_obj[$name]; } if(!file_exists (App_path."/application/modules/{$modules}/{$layer}/{$class}.php") ) {exit ("file {$class}.php is not exists"); } yaf_loader::import (App_path."/application/modules/{$modules}/business/{$class}.php");//Import the class library (Business logic class library, etc.)$_obj[$name] =New$class(); return$_obj[$name]; } }
Encapsulation of public resource classes