Beginning with PHP object-oriented programming feels a bit awkward.

Source: Internet
Author: User
Initial use of PHP object-oriented programming feel a bit awkward ...
Because always do the front end with JS
This is generally used
function xx () {
This.init.apply (this,arguments);
}

Xx.prototype = {
Options: {
A few default properties
},
Init:function (options) {
$.extend (this,this.options,options);
It's easy to write a extend without jquery.
//.........
}
}

New XX (AA)//AA is an object that passes some parameters
$.extend (this,this.options,options); This is the example of a new argument with the default parameter, which is easy to implement.

When I wrote PHP today (my colleague told me to have one assignment)
The following code (merge js css things)
Class Mergecompress
{
var $merge _arr;
var $commpress _arr;
var $type;
var $file _dir; Compress the merged directory
var $file _name; Compress the merged file name
var $path _jar; Yui Jar Path
var $is _del = true; Whether the compressed fragmented files are deleted
var $errs = array ();
Public function __construct ($commpress _arr=array (), $merge _arr=array (), $type = "js", $file _dir= "", $file _name= "", $ Path_jar= "") {
$this->type = $type;
$this->commpress_arr = $commpress _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->commpress_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!!!! ");
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.