00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00016 abstract class BasePattern extends Singleton implements GenerationPattern
00017 {
00018 public function tableExists()
00019 {
00020 return true;
00021 }
00022
00023 public function daoExists()
00024 {
00025 return false;
00026 }
00027
00028 public static function dumpFile($path, $content)
00029 {
00030 $content = trim($content);
00031
00032 if (is_readable($path)) {
00033 $pattern =
00034 array(
00035 '@\/\*(.*)\*\/@sU',
00036 '@[\r\n]@sU'
00037 );
00038
00039
00040 $old = preg_replace($pattern, null, file_get_contents($path), 2);
00041 $new = preg_replace($pattern, null, $content, 2);
00042 } else {
00043 $old = 1; $new = 2;
00044 }
00045
00046 $out = MetaConfiguration::out();
00047 $className = basename($path, EXT_CLASS);
00048
00049 if ($old !== $new) {
00050 $out->
00051 warning("\t\t".$className.' ');
00052
00053 if (!MetaConfiguration::me()->isDryRun()) {
00054 $fp = fopen($path, 'wb');
00055 fwrite($fp, $content);
00056 fclose($fp);
00057 }
00058
00059 $out->
00060 log('(')->
00061 remark(
00062 str_replace(getcwd().DIRECTORY_SEPARATOR, null, $path)
00063 )->
00064 logLine(')');
00065 } else {
00066 $out->
00067 infoLine("\t\t".$className.' ', true);
00068 }
00069 }
00070
00071 public function build(MetaClass $class)
00072 {
00073 return $this->fullBuild($class);
00074 }
00075
00079 protected function fullBuild(MetaClass $class)
00080 {
00081 return $this->
00082 buildProto($class)->
00083 buildBusiness($class)->
00084 buildDao($class);
00085 }
00086
00090 protected function buildProto(MetaClass $class)
00091 {
00092 $this->dumpFile(
00093 ONPHP_META_AUTO_PROTO_DIR.'AutoProto'.$class->getName().EXT_CLASS,
00094 Format::indentize(AutoProtoClassBuilder::build($class))
00095 );
00096
00097 $userFile = ONPHP_META_PROTO_DIR.'Proto'.$class->getName().EXT_CLASS;
00098
00099 if (
00100 MetaConfiguration::me()->isForcedGeneration()
00101 || !file_exists($userFile)
00102 )
00103 $this->dumpFile(
00104 $userFile,
00105 Format::indentize(ProtoClassBuilder::build($class))
00106 );
00107
00108 return $this;
00109 }
00110
00114 protected function buildBusiness(MetaClass $class)
00115 {
00116 $this->dumpFile(
00117 ONPHP_META_AUTO_BUSINESS_DIR.'Auto'.$class->getName().EXT_CLASS,
00118 Format::indentize(AutoClassBuilder::build($class))
00119 );
00120
00121 $userFile = ONPHP_META_BUSINESS_DIR.$class->getName().EXT_CLASS;
00122
00123 if (
00124 MetaConfiguration::me()->isForcedGeneration()
00125 || !file_exists($userFile)
00126 )
00127 $this->dumpFile(
00128 $userFile,
00129 Format::indentize(BusinessClassBuilder::build($class))
00130 );
00131
00132 return $this;
00133 }
00134
00138 protected function buildDao(MetaClass $class)
00139 {
00140 $this->dumpFile(
00141 ONPHP_META_AUTO_DAO_DIR.'Auto'.$class->getName().'DAO'.EXT_CLASS,
00142 Format::indentize(AutoDaoBuilder::build($class))
00143 );
00144
00145 $userFile = ONPHP_META_DAO_DIR.$class->getName().'DAO'.EXT_CLASS;
00146
00147 if (
00148 MetaConfiguration::me()->isForcedGeneration()
00149 || !file_exists($userFile)
00150 )
00151 $this->dumpFile(
00152 $userFile,
00153 Format::indentize(DaoBuilder::build($class))
00154 );
00155
00156 return $this;
00157 }
00158 }
00159 ?>