It seems awkward to use php object-oriented programming... because the front-end & nbsp; js & nbsp; function & nbsp; xx () {& nbsp; & nbsp; this. init. apply (this, arg is a bit awkward when using php object-oriented programming...
Because I have been working on front-end js
Generally
Function xx (){
This. init. apply (this, arguments );
}
Xx. prototype = {
Options :{
// Several default attributes
},
Init: function (options ){
$. Extend (this, this. options, options );
// It is easy to write an extend without jquery
//.........
}
}
New xx (aa) // aa is an object that transmits some parameters
$. Extend (this, this. options, options); this is to give the new instance the parameters and the default parameters together with the new ones, which is easy to implement.
When I wrote php today (my colleague told me to assign values one by one)
The following code (javascript css merging)
Class mergeCompress
{
Var $ merge_arr;
Var $ comatrix ress_arr;
Var $ type;
Var $ file_dir; // compressed and merged Directory
Var $ file_name; // compressed and merged file name
Var $ path_jar; // path of yui jar
Var $ is_del = true; // whether the compressed scattered files are deleted
Var $ errs = array ();
Public function _ construct ($ comatrix ress_arr = array (), $ merge_arr = array (), $ type = "js", $ file_dir = "", $ file_name = "", $ path_jar = ""){
$ This-> type = $ type;
$ This-> comatrix ress_arr = $ comatrix ress_arr;
$ This-> merge_arr = $ merge_arr;
$ This-> file_dir = $ file_dir;
$ This-> file_name = $ file_name;
$ This-> path_jar = $ path_jar;
}
Public function exec (){
$ New_compress_arr = $ this-> compress ();
$ This-> merge_arr = array_merge ($ this-> merge_arr, $ new_compress_arr );
$ This-> merge ();
If ($ this-> is_del ){
Foreach ($ new_compress_arr as $ I => $ url ){
Unlink ($ url );
}
}
}
Public function compress (){
$ New_compress_arr = array ();
$ Temp = "java-jar {jar_path} -- type {type} -- charset UTF-8 {source}> {compressor_source }";
$ Temp = str_replace ("{jar_path}", $ this-> path_jar, $ temp );
$ Temp = str_replace ("{type}", $ this-> type, $ temp );
$ Type = $ this-> type;
$ File_dir = $ this-> file_dir;
Foreach ($ this-> comatrix ress_arr as $ I => $ val ){
If (! File_exists ($ val )){
Array_push ($ this-> errs, $ val. "Does not exist !!!! ");
Continue;
}
$ Cmd = str_replace ("{source}", $ val, $ temp );
$ New_name = basename ($ val );
$ New_name = substr ($ new_name, 0, strrpos ($ new_name, "."). ". min.". $ type;
$ File_new_name = $ file_dir. "/". $ new_name;
$ Cmd = str_replace ("{compressor_source}", $ file_new_name, $ cmd );
$ Arr = array ();
Exec ($ cmd, $ arr, $ is );
If ($ is! = 0 ){
Array_push ($ errs, $ val. "compress fail !!!! ");
}
Array_push ($ new_compress_arr, $ file_new_name );
}
Return $ new_compress_arr;
}
Public function merge (){
$ Content = "";
$ File_name = $ this-> file_dir. "/". $ this-> file_name;
Foreach ($ this-> merge_arr as $ I => $ url ){
If (! File_exists ($ url )){
Array_push ($ this-> errs, $ url. "Does not exist !!!! ");