. */ /** * Doctrine_Resource_Client * * @author Konsta Vesterinen * @author Jonathan H. Wage * @package Doctrine * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @version $Revision$ * @category Object Relational Mapping * @link www.phpdoctrine.com * @since 1.0 */ class Doctrine_Resource_Client extends Doctrine_Resource { public $loadDoctrine = false; static public function getInstance($url = null, $config = null) { static $instance; if (!$instance) { $instance = new Doctrine_Resource_Client($url, $config); if ($instance->loadDoctrine === true) { $instance->loadDoctrine(); } } return $instance; } public function __construct($url, $config) { if ($url) { $config['url'] = $url; } parent::__construct($config); } public function loadDoctrine() { $path = '/tmp/' . md5(serialize($this->getConfig())); $classesPath = $path.'.classes.php'; if (file_exists($path)) { $schema = file_get_contents($path); } else { $request = new Doctrine_Resource_Request(); $request->set('action', 'load'); $schema = $request->execute(); if ($schema) { file_put_contents($path, Doctrine_Parser::dump($schema, 'xml')); } } if (file_exists($path) && $schema) { $import = new Doctrine_Import_Schema(); $schema = $import->buildSchema($path, 'xml'); if (!file_exists($classesPath)) { $build = " $details) { $build .= "class " . $className . " extends Doctrine_Resource_Record { protected \$_model = '".$className."'; public function __construct() { parent::__construct(\$this->_model); } }\n"; $schema['schema'][$className]['relations'] = isset($schema['relations'][$className]) ? $schema['relations'][$className]:array(); } file_put_contents($classesPath, $build); } require_once($classesPath); $this->getConfig()->set('schema', $schema); } } public function getTable($table) { static $instance; if(!isset($instance[$table])) { $instance[$table] = new Doctrine_Resource_Table($table); } return $instance[$table]; } public function printSchema() { $schema = $this->getConfig('schema'); echo '

Schema

'; echo ''; exit; } }