PHP Classes
elePHPant
Icontem

File: scrubs.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Kevin Burke  >  Scrubs  >  scrubs.php  >  Download  
File: scrubs.php
Role: Configuration script
Content type: text/plain
Description: Generates DAO's
Class: Scrubs
Object-relational mapping / Data persistence tool
Author: By
Last change:
Date: 11 years ago
Size: 2,732 bytes
 

Contents

Class file image Download
<?php

/**
 *
 * @version $Id$
 * @copyright 2003
 */

if ($action == "generate") {
 
$path = $_REQUEST['scrubsPath'];
  include_once(
'lib/Dommer.php');
  include_once(
'lib/ClassWriter.php');
  include_once(
'lib/ConfigWriter.php');
    include_once(
'lib/Configer.php');

 
$dommer = new Dommer($path . 'scrubs-config.xml');
 
$document = $dommer->dominate();

 
$configWriter = new ConfigWriter($document);
 
$configWriter->write();

  foreach (
$document as $class) {
    if (
$class->tagname == "class") {
     
$className = $class->get_attribute("name");
     
$table = $class->get_attribute("table");

     
$classWriter = new ClassWriter($className);

     
$classChildren = $class->children();
      foreach(
$classChildren as $classChild) {
        switch (
$classChild->tagname) {
          case
"primaryKey":
           
$field = $classChild->get_attribute("field");
           
$classWriter->setProperty($field);

            break;
          case
"property":
           
$property = $classChild->get_attribute("name");
           
$classWriter->setProperty($property);

            break;
          case
"relationship":
           
$type = $classChild->get_attribute("type");
           
$name = $classChild->get_attribute("name");
            if (
$type == "oneToMany") {
             
$objectArray = $classChild->get_attribute("objectArray");
             
$classWriter->setInclude($name);
             
$classWriter->setRelationship($name);
             
$classWriter->setObjectArray($objectArray);
            }

            break;
        }
      }
     
$classWriter->write();
    }
  }
   
   
$configer = new Configer(null, true);
   
$configer->setSectionValue("database", "type", "mysql");
   
$configer->setSectionValue("database", "host", $_REQUEST['host']);
   
$configer->setSectionValue("database", "database", $_REQUEST['db']);
   
$configer->setSectionValue("database", "username", $_REQUEST['username']);
   
$configer->setSectionValue("database", "password", $_REQUEST['password']);
   
$configer->save();
} else {

?>
<html>
  <head>
      <title>Scrubs Generator</title>
  </head>
  <body>
   <form action="scrubs.php" method="POST">
       absolute path for Scrubs directory: <input type="text" name="scrubsPath" /> (Eg. c:\apache\Scrubs\ use trailing slash)<br>
    database host: <input type="text" name="host"> <br>
    database name: <input type="text" name="db"> <br>
    database username: <input type="text" name="username"> <br>
    database password: <input type="password" name="password"> <br>
       <input type="hidden" name="action" value="generate">
    <input type="submit" name="submit" value="Generate">
   </form>
  </body>
 </html>
<? }

?>