From d4e34979d191476a81e4be7403ae23769af0fd57 Mon Sep 17 00:00:00 2001 From: "Jonathan.Wage" Date: Tue, 25 Sep 2007 14:09:05 +0000 Subject: [PATCH] Removed some unwanted functions. --- lib/Doctrine/Resource/Client.php | 28 +++--- lib/Doctrine/Resource/Collection.php | 4 +- lib/Doctrine/Resource/Record.php | 4 +- lib/Doctrine/Resource/Server.php | 17 +++- playground/index.php | 125 ++++++++++++++++++++++++++- 5 files changed, 151 insertions(+), 27 deletions(-) diff --git a/lib/Doctrine/Resource/Client.php b/lib/Doctrine/Resource/Client.php index 730339b23..2592dacaf 100644 --- a/lib/Doctrine/Resource/Client.php +++ b/lib/Doctrine/Resource/Client.php @@ -35,12 +35,12 @@ class Doctrine_Resource_Client extends Doctrine_Resource { public $loadDoctrine = false; - static public function getInstance($config = null) + static public function getInstance($url = null, $config = null) { static $instance; if (!$instance) { - $instance = new Doctrine_Resource_Client($config); + $instance = new Doctrine_Resource_Client($url, $config); if ($instance->loadDoctrine === true) { $instance->loadDoctrine(); @@ -50,6 +50,15 @@ class Doctrine_Resource_Client extends Doctrine_Resource return $instance; } + public function __construct($url, $config) + { + if ($url) { + $config['url'] = $url; + } + + parent::__construct($config); + } + public function loadDoctrine() { $path = '/tmp/' . md5(serialize($this->getConfig())); @@ -92,19 +101,4 @@ class Doctrine_Resource_Client extends Doctrine_Resource { return new Doctrine_Resource_Table($table); } - - public function newQuery() - { - return new Doctrine_Resource_Query(); - } - - public function newRecord($model, $loadRelations = true) - { - return new Doctrine_Resource_Record($model, $loadRelations); - } - - public function newCollection($model) - { - return new Doctrine_Resource_Collection($model); - } } \ No newline at end of file diff --git a/lib/Doctrine/Resource/Collection.php b/lib/Doctrine/Resource/Collection.php index 7db93016e..6d84c8cf8 100644 --- a/lib/Doctrine/Resource/Collection.php +++ b/lib/Doctrine/Resource/Collection.php @@ -67,7 +67,9 @@ class Doctrine_Resource_Collection extends Doctrine_Resource_Access implements C public function add($value = null) { if (!$value) { - $value = Doctrine_Resource_Client::getInstance()->newRecord($this->_model); + $model = $this->_model; + + $value = new $model(); } $this->_data[] = $value; diff --git a/lib/Doctrine/Resource/Record.php b/lib/Doctrine/Resource/Record.php index 5ae2e0e69..940b7dae2 100644 --- a/lib/Doctrine/Resource/Record.php +++ b/lib/Doctrine/Resource/Record.php @@ -71,9 +71,9 @@ class Doctrine_Resource_Record extends Doctrine_Resource_Access implements Count foreach ($relations as $relation) { if ($relation['type'] === Doctrine_Relation::ONE) { - $this->_data[$relation['alias']] = Doctrine_Resource_Client::getInstance()->newRecord($relation['class'], false); + $this->_data[$relation['alias']] = new $relation['class'](false); } else { - $this->_data[$relation['alias']] = Doctrine_Resource_Client::getInstance()->newCollection($relation['class']); + $this->_data[$relation['alias']] = new Doctrine_Resource_Collection($relation['class']); } } } diff --git a/lib/Doctrine/Resource/Server.php b/lib/Doctrine/Resource/Server.php index 999b8d881..16bbd9701 100644 --- a/lib/Doctrine/Resource/Server.php +++ b/lib/Doctrine/Resource/Server.php @@ -32,18 +32,27 @@ * @since 1.0 */ class Doctrine_Resource_Server extends Doctrine_Resource -{ - static public function getInstance($config = null) +{ + public function __construct($name = null, $config = null) + { + if ($name) { + $config['name'] = $name; + } + + parent::__construct($config); + } + + static public function getInstance($name, $config = null) { static $instance; if (!$instance) { - $instance = new Doctrine_Resource_Server($config); + $instance = new Doctrine_Resource_Server($name, $config); } return $instance; } - + public function executeSave($request) { $model = $request->get('model'); diff --git a/playground/index.php b/playground/index.php index 764990286..44ac6415a 100644 --- a/playground/index.php +++ b/playground/index.php @@ -1,5 +1,124 @@ $tables); + + $server = Doctrine_Resource_Server::getInstance($name, $config); + $server->run($_REQUEST); + +} else { + $url = 'http://localhost/~jwage/doctrine_trunk/playground/index.php?action=server'; + $config = array(); + + // Instantiate a new client + $client = Doctrine_Resource_Client::getInstance($url, $config); + + // Retrieve a models table object + $table = $client->getTable('User'); + + // Find record by identifier + $user = $table->find(4); + + // 2 ways to create queries + $query = new Doctrine_Resource_Query(); + $query->from('User u, u.Phonenumber p')->limit(2); + + // returns users + $users = $query->execute(); + + print_r($users->toArray()); + + /* + Array + ( + [User_0] => Array + ( + [id] => 4 + [name] => zYne + [loginname] => + [password] => + [type] => 0 + [created] => + [updated] => + [email_id] => 1 + [Phonenumber] => Array + ( + [Phonenumber_0] => Array + ( + [id] => 2 + [phonenumber] => 123 123 + [entity_id] => 4 + ) + + ) + + ) + + [User_1] => Array + ( + [id] => 5 + [name] => Arnold Schwarzenegger + [loginname] => + [password] => + [type] => 0 + [created] => + [updated] => + [email_id] => 2 + [Phonenumber] => Array + ( + [Phonenumber_0] => Array + ( + [id] => 3 + [phonenumber] => 123 123 + [entity_id] => 5 + ) + + [Phonenumber_1] => Array + ( + [id] => 4 + [phonenumber] => 456 456 + [entity_id] => 5 + ) + + [Phonenumber_2] => Array + ( + [id] => 5 + [phonenumber] => 789 789 + [entity_id] => 5 + ) + + ) + + ) + + ) + */ + + $user = new User(); + $user->name = 'Jonathan H. Wage'; + $user->save(); + + print_r($user->toArray()); + + /* + Array + ( + [id] => 12 + [name] => Jonathan H. Wage + [loginname] => + [password] => + [type] => 0 + [created] => + [updated] => + [email_id] => + ) + */ +} \ No newline at end of file