1
0
mirror of synced 2025-01-18 22:41:43 +03:00

Changes to make export schema yml closer to working :)

This commit is contained in:
Jonathan.Wage 2007-09-20 15:02:07 +00:00
parent 8402633bcc
commit 0e964840b7
7 changed files with 113 additions and 46 deletions

View File

@ -477,6 +477,7 @@ final class Doctrine
}
$parent = new ReflectionClass('Doctrine_Record');
$loadedModels = array();
// we iterate trhough the diff of previously declared classes

View File

@ -31,47 +31,73 @@
*/
abstract class Doctrine_Parser
{
/**
* loadData
*
* Override in the parser driver
*
* @param string $array
* @return void
* @author Jonathan H. Wage
*/
abstract public function loadData($array);
/**
* dumpData
*
* Override in the praser driver
*
* @param string $array
* @param string $path
* @return void
* @author Jonathan H. Wage
*/
abstract public function dumpData($array, $path = null);
/**
* getParser
*
* Get instance of the specified parser
*
* @param string $type
* @return void
* @author Jonathan H. Wage
*/
static public function getParser($type)
{
$class = 'Doctrine_Parser_'.ucfirst($type);
return new $class;
}
/**
* load
*
* Interface for loading and parsing data from a file
*
* @param string $path
* @param string $type
* @return void
* @author Jonathan H. Wage
*/
static public function load($path, $type = 'xml')
{
$parser = self::getParser($type);
return $parser->loadData($path);
}
/**
* dump
*
* Interface for pulling and dumping data to a file
*
* @param string $array
* @param string $path
* @param string $type
* @return void
* @author Jonathan H. Wage
*/
static public function dump($array, $path = null, $type = 'xml')
{
$parser = self::getParser($type);
return $parser->dumpData($array, $path);
}
static public function loadXml($path)
{
return self::load($path, 'xml');
}
static public function dumpXml($array, $path = null)
{
return self::dump($array, $path, 'xml');
}
static public function loadYml($path)
{
return self::load($path, 'yml');
}
static public function dumpYml($array, $path = null)
{
return self::dump($array, $path, 'yml');
}
}

View File

@ -33,6 +33,16 @@ require_once('spyc.php');
*/
class Doctrine_Parser_Yml extends Doctrine_Parser
{
/**
* dumpData
*
* Dump an array of data to a specified path to yml file
*
* @param string $array
* @param string $path
* @return void
* @author Jonathan H. Wage
*/
public function dumpData($array, $path = null)
{
$spyc = new Spyc();
@ -45,7 +55,15 @@ class Doctrine_Parser_Yml extends Doctrine_Parser
return $yml;
}
}
/**
* loadData
*
* Load and parse data from a yml file
*
* @param string $path
* @return void
* @author Jonathan H. Wage
*/
public function loadData($path)
{
$spyc = new Spyc();

View File

@ -7,4 +7,10 @@ class Groupuser extends Doctrine_Record
$this->hasColumn('group_id', 'integer');
$this->hasColumn('user_id', 'integer');
}
public function setUp()
{
$this->hasOne('Group', array('local' => 'group_id', 'foreign' => 'id'));
$this->hasOne('User', array('local' => 'user_id', 'foreign' => 'id'));
}
}

View File

@ -11,5 +11,13 @@ class Phonenumber extends Doctrine_Record
$this->hasOne('Entity', array('local' => 'entity_id',
'foreign' => 'id',
'onDelete' => 'CASCADE'));
$this->hasOne('Group', array('local' => 'entity_id',
'foreign' => 'id',
'onDelete' => 'CASCADE'));
$this->hasOne('User', array('local' => 'entity_id',
'foreign' => 'id',
'onDelete' => 'CASCADE'));
}
}

View File

@ -1,4 +1,11 @@
<?php
require_once('playground.php');
require_once('connection.php');
require_once('models.php');
require_once('models.php');
require_once('data.php');
Doctrine_Data::exportData('data/data.yml', 'yml', $tables);
//Doctrine_Data::importData('data/data.yml', 'yml', $tables);
//Doctrine_Data::exportData('data/test.yml', 'yml', $tables);

View File

@ -1,26 +1,27 @@
<?php
Doctrine::loadModels('models');
$models = Doctrine::loadModels('models');
$manager->setAttribute(Doctrine::ATTR_EXPORT, Doctrine::EXPORT_ALL);
$tables = array('entity',
'entityReference',
'email',
'phonenumber',
'groupuser',
'album',
'song',
'element',
'error',
'description',
'address',
'account',
'task',
'resource',
'assignment',
'resourceType',
'resourceReference');
$tables = array('Entity',
'EntityReference',
'EntityAddress',
'Email',
'Phonenumber',
'Groupuser',
'Group',
'User',
'Album',
'Song',
'Element',
'Error',
'Description',
'Address',
'Account',
'Task',
'Resource',
'Assignment',
'ResourceType',
'ResourceReference');
$conn->export->exportClasses($tables);
require_once('data.php');
$conn->export->exportClasses($tables);