Commit d4e34979 authored by Jonathan.Wage's avatar Jonathan.Wage

Removed some unwanted functions.

parent 1d3cdd0a
...@@ -35,12 +35,12 @@ class Doctrine_Resource_Client extends Doctrine_Resource ...@@ -35,12 +35,12 @@ class Doctrine_Resource_Client extends Doctrine_Resource
{ {
public $loadDoctrine = false; public $loadDoctrine = false;
static public function getInstance($config = null) static public function getInstance($url = null, $config = null)
{ {
static $instance; static $instance;
if (!$instance) { if (!$instance) {
$instance = new Doctrine_Resource_Client($config); $instance = new Doctrine_Resource_Client($url, $config);
if ($instance->loadDoctrine === true) { if ($instance->loadDoctrine === true) {
$instance->loadDoctrine(); $instance->loadDoctrine();
...@@ -50,6 +50,15 @@ class Doctrine_Resource_Client extends Doctrine_Resource ...@@ -50,6 +50,15 @@ class Doctrine_Resource_Client extends Doctrine_Resource
return $instance; return $instance;
} }
public function __construct($url, $config)
{
if ($url) {
$config['url'] = $url;
}
parent::__construct($config);
}
public function loadDoctrine() public function loadDoctrine()
{ {
$path = '/tmp/' . md5(serialize($this->getConfig())); $path = '/tmp/' . md5(serialize($this->getConfig()));
...@@ -92,19 +101,4 @@ class Doctrine_Resource_Client extends Doctrine_Resource ...@@ -92,19 +101,4 @@ class Doctrine_Resource_Client extends Doctrine_Resource
{ {
return new Doctrine_Resource_Table($table); 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
...@@ -67,7 +67,9 @@ class Doctrine_Resource_Collection extends Doctrine_Resource_Access implements C ...@@ -67,7 +67,9 @@ class Doctrine_Resource_Collection extends Doctrine_Resource_Access implements C
public function add($value = null) public function add($value = null)
{ {
if (!$value) { if (!$value) {
$value = Doctrine_Resource_Client::getInstance()->newRecord($this->_model); $model = $this->_model;
$value = new $model();
} }
$this->_data[] = $value; $this->_data[] = $value;
......
...@@ -71,9 +71,9 @@ class Doctrine_Resource_Record extends Doctrine_Resource_Access implements Count ...@@ -71,9 +71,9 @@ class Doctrine_Resource_Record extends Doctrine_Resource_Access implements Count
foreach ($relations as $relation) { foreach ($relations as $relation) {
if ($relation['type'] === Doctrine_Relation::ONE) { 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 { } else {
$this->_data[$relation['alias']] = Doctrine_Resource_Client::getInstance()->newCollection($relation['class']); $this->_data[$relation['alias']] = new Doctrine_Resource_Collection($relation['class']);
} }
} }
} }
......
...@@ -32,18 +32,27 @@ ...@@ -32,18 +32,27 @@
* @since 1.0 * @since 1.0
*/ */
class Doctrine_Resource_Server extends Doctrine_Resource 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; static $instance;
if (!$instance) { if (!$instance) {
$instance = new Doctrine_Resource_Server($config); $instance = new Doctrine_Resource_Server($name, $config);
} }
return $instance; return $instance;
} }
public function executeSave($request) public function executeSave($request)
{ {
$model = $request->get('model'); $model = $request->get('model');
......
<?php <?php
require_once('playground.php'); require_once('playground.php');
require_once('connection.php');
require_once('models.php'); $action = isset($_REQUEST['action']) ? $_REQUEST['action']:'client';
require_once('data.php');
\ No newline at end of file if ($action == 'server') {
require_once('connection.php');
require_once('models.php');
require_once('data.php');
$name = 'Doctrine_Resource_Playground';
$config = array('models' => $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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment