# BasePattern.class.php

Go to the documentation of this file.

    00001 <?php
    00002 /***************************************************************************
    00003  *   Copyright (C) 2006-2007 by Konstantin V. Arkhipov                     *
    00004  *                                                                         *
    00005  *   This program is free software; you can redistribute it and/or modify  *
    00006  *   it under the terms of the GNU Lesser General Public License as        *
    00007  *   published by the Free Software Foundation; either version 3 of the    *
    00008  *   License, or (at your option) any later version.                       *
    00009  *                                                                         *
    00010  ***************************************************************************/
    00011
    00015     abstract class BasePattern extends Singleton implements GenerationPattern
    00016     {
    00017         public function tableExists()
    00018         {
    00019             return true;
    00020         }
    00021
    00022         public function daoExists()
    00023         {
    00024             return false;
    00025         }
    00026
    00027         public static function dumpFile($path, $content)
    00028         {
    00029             $content = trim($content);
    00030
    00031             if (is_readable($path)) {
    00032                 $pattern =
    00033                     array(
    00034                         '@\/\*(.*)\*\/@sU',
    00035                         '@[\r\n]@sU'
    00036                     );
    00037
    00038                 // strip only header and svn's Id-keyword, don't skip type hints
    00039                 $old = preg_replace($pattern, null, file_get_contents($path), 2);
    00040                 $new = preg_replace($pattern, null, $content, 2);
    00041             } else {
    00042                 $old = 1; $new = 2;
    00043             }
    00044
    00045             $out = MetaConfiguration::out();
    00046             $className = basename($path, EXT_CLASS);
    00047
    00048             if ($old !== $new) {
    00049                 $out->
    00050                     warning("\t\t".$className.' ');
    00051
    00052                 if (!MetaConfiguration::me()->isDryRun()) {
    00053                     $fp = fopen($path, 'wb');
    00054                     fwrite($fp, $content);
    00055                     fclose($fp);
    00056                 }
    00057
    00058                 $out->
    00059                     log('(')->
    00060                     remark(
    00061                         str_replace(getcwd().DIRECTORY_SEPARATOR, null, $path)
    00062                     )->
    00063                     logLine(')');
    00064             } else {
    00065                 $out->
    00066                     infoLine("\t\t".$className.' ', true);
    00067             }
    00068         }
    00069
    00070         public function build(MetaClass $class)
    00071         {
    00072             return $this->fullBuild($class);
    00073         }
    00074
    00078         protected function fullBuild(MetaClass $class)
    00079         {
    00080             return $this->
    00081                 buildProto($class)->
    00082                 buildBusiness($class)->
    00083                 buildDao($class);
    00084         }
    00085
    00089         protected function buildProto(MetaClass $class)
    00090         {
    00091             $this->dumpFile(
    00092                 ONPHP_META_AUTO_PROTO_DIR.'AutoProto'.$class->getName().EXT_CLASS,
    00093                 Format::indentize(AutoProtoClassBuilder::build($class))
    00094             );
    00095
    00096             $userFile = ONPHP_META_PROTO_DIR.'Proto'.$class->getName().EXT_CLASS;
    00097
    00098             if (
    00099                 MetaConfiguration::me()->isForcedGeneration()
    00100                 || !file_exists($userFile)
    00101             )
    00102                 $this->dumpFile(
    00103                     $userFile,
    00104                     Format::indentize(ProtoClassBuilder::build($class))
    00105                 );
    00106
    00107             return $this;
    00108         }
    00109
    00113         protected function buildBusiness(MetaClass $class)
    00114         {
    00115             $this->dumpFile(
    00116                 ONPHP_META_AUTO_BUSINESS_DIR.'Auto'.$class->getName().EXT_CLASS,
    00117                 Format::indentize(AutoClassBuilder::build($class))
    00118             );
    00119
    00120             $userFile = ONPHP_META_BUSINESS_DIR.$class->getName().EXT_CLASS;
    00121
    00122             if (
    00123                 MetaConfiguration::me()->isForcedGeneration()
    00124                 || !file_exists($userFile)
    00125             )
    00126                 $this->dumpFile(
    00127                     $userFile,
    00128                     Format::indentize(BusinessClassBuilder::build($class))
    00129                 );
    00130
    00131             return $this;
    00132         }
    00133
    00137         protected function buildDao(MetaClass $class)
    00138         {
    00139             $this->dumpFile(
    00140                 ONPHP_META_AUTO_DAO_DIR.'Auto'.$class->getName().'DAO'.EXT_CLASS,
    00141                 Format::indentize(AutoDaoBuilder::build($class))
    00142             );
    00143
    00144             $userFile = ONPHP_META_DAO_DIR.$class->getName().'DAO'.EXT_CLASS;
    00145
    00146             if (
    00147                 MetaConfiguration::me()->isForcedGeneration()
    00148                 || !file_exists($userFile)
    00149             )
    00150                 $this->dumpFile(
    00151                     $userFile,
    00152                     Format::indentize(DaoBuilder::build($class))
    00153                 );
    00154
    00155             return $this;
    00156         }
    00157     }
    00158 ?>