前回説明が不足していたshema.xmlをsymfony用に成形するスクリプトxmlfilterについて説明します。
xmlfilterはパイプ渡しで以下のようにして利用します。
db2xml mysql://root@localhost/askeet |symfony-setup-xmlfilter > config/schema.xml
symfony-setup-xmlfilterは以下のようなPHPで書かれたコマンドラインツールです。
#!/usr/bin/env php < ?php /** * @version $Id$ */ require_once("creole/Creole.php"); class xmlfilter{ private $doc; public function filter_string($string){ if(!$this->doc = DOMDocument::loadXML($string)){ return; } return $this->filter(); } public function filter_file($file){ if(!$this->doc = DOMDocument::load($file)){ return; } return $this->filter(); } protected function filter(){ $this->fix_database_name(); $this->remove_vendor_tag(); $this->remove_dbdtalbe(); echo $this->doc->saveXML(); } // symfony protected function fix_database_name(){ $databases = $this->doc->getElementsByTagName("database"); foreach($databases as $database){ $database->setAttribute("name","symfony"); } } // vendor protected function remove_vendor_tag(){ while($vendor = $this->doc->getElementsByTagName("vendor")->item(0)){ $vendor->parentNode->removeChild($vendor); } } // dbdesigner4 protected function remove_dbdtalbe(){ $tables=$this->doc->getElementsByTagName("table"); foreach($tables as $table){ if($table->getAttribute("name") == "dbdesigner4"){ $table->parentNode->removeChild($table); break; } } } } $filter = new xmlfilter; while(!feof(STDIN)){ $contents.= fread(STDIN,8192); } $filter->filter_string($contents); ?>
POSTED BY tumf ON 12 月 22nd, 2005. PERMALINK

