Created
March 10, 2014 17:30
-
-
Save charlycoste/9469809 to your computer and use it in GitHub Desktop.
Persistent Manager avec prise en charge de XML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ezcPersistentXmlManager extends ezcPersistentDefinitionManager | |
{ | |
private $file; | |
public function __construct( $file ) | |
{ | |
if( file_exists($file) ) | |
$this->file = $file; | |
} | |
public function fetchDefinition( $class ) | |
{ | |
$dom = new DOMDocument(); | |
$dom->load( $this->file ); | |
$xpath = new DOMXpath($dom); | |
$elements = $xpath->query("//definition[@class_name='$class']"); | |
$def = new ezcPersistentObjectDefinition(); | |
$def->table = "comptes"; | |
$def->class = $class; | |
$def->idProperty = new ezcPersistentObjectIdProperty; | |
$def->idProperty->columnName = 'code'; | |
$def->idProperty->propertyName = 'code'; | |
$def->idProperty->generator = new ezcPersistentGeneratorDefinition( 'ezcPersistentSequenceGenerator' ); | |
$definition = null; | |
$path = $this->dir . strtolower( $class ) . '.php'; | |
if ( file_exists( $path ) ) | |
{ | |
$definition = require $path; | |
} | |
if ( !( $definition instanceof ezcPersistentObjectDefinition ) ) | |
{ | |
throw new ezcPersistentDefinitionNotFoundException( $class, | |
"Searched for '" . realpath( dirname( $path ) ) . "/" . basename( $path ) . "'." ); | |
} | |
if ( $definition->idProperty === null ) | |
{ | |
throw new ezcPersistentDefinitionMissingIdPropertyException( $class ); | |
} | |
$definition = $this->setupReversePropertyDefinition( $definition ); | |
return $definition; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment