|
Revision 14182, 1.2 kB
(checked in by flack, 8 months ago)
|
corrected some sloppyness from the last commit and added a few more fixes
|
| Line | |
|---|
| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
class SchemaReader { |
|---|
| 4 |
|
|---|
| 5 |
protected $dom; |
|---|
| 6 |
|
|---|
| 7 |
protected $type; |
|---|
| 8 |
public function __construct( $file , $type ) |
|---|
| 9 |
{ |
|---|
| 10 |
$this->file = $file; |
|---|
| 11 |
$this->dom = new DomDocument; |
|---|
| 12 |
if ($this->dom->load( $file )) echo "File $file loaded..\n"; |
|---|
| 13 |
$this->xp = new DomXpath( $this->dom ); |
|---|
| 14 |
$this->type = $type; |
|---|
| 15 |
|
|---|
| 16 |
echo $this->dom->saveXML( ); |
|---|
| 17 |
$this->checkType( ); |
|---|
| 18 |
} |
|---|
| 19 |
|
|---|
| 20 |
protected function checkType ( ){ |
|---|
| 21 |
$vars = $this->getProperties( ); |
|---|
| 22 |
var_dump($vars->length); |
|---|
| 23 |
if ( $vars->length == 0 ) { |
|---|
| 24 |
throw new Exception( "Cannot create crud with missing type or empty type!" ); |
|---|
| 25 |
} |
|---|
| 26 |
} |
|---|
| 27 |
|
|---|
| 28 |
* Get the variables for a function |
|---|
| 29 |
* @return object DomList of the properties for the type |
|---|
| 30 |
*/ |
|---|
| 31 |
public function getProperties( ) { |
|---|
| 32 |
$q = sprintf( '/Schema/type[@name="%s"]/property', $this->type ); |
|---|
| 33 |
echo $q ."\n"; |
|---|
| 34 |
$vars = $this->xp->query( $q ) ; |
|---|
| 35 |
return $vars; |
|---|
| 36 |
} |
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
public function getTable( ) { |
|---|
| 40 |
$q = sprintf( '/Schema/type[@name="%s"]', $this->type ); |
|---|
| 41 |
$type = $this->xp->query( $q ); |
|---|
| 42 |
return $type->item( 0 )->getAttribute( 'table' ); |
|---|
| 43 |
} |
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
} |
|---|
| 48 |
|
|---|