Removed some unwanted functions.
This commit is contained in:
parent
1d3cdd0ab6
commit
d4e34979d1
@ -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);
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -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']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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');
|
||||
|
@ -1,5 +1,124 @@
|
||||
<?php
|
||||
require_once('playground.php');
|
||||
require_once('connection.php');
|
||||
require_once('models.php');
|
||||
require_once('data.php');
|
||||
|
||||
$action = isset($_REQUEST['action']) ? $_REQUEST['action']:'client';
|
||||
|
||||
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] =>
|
||||
)
|
||||
*/
|
||||
}
|
Loading…
Reference in New Issue
Block a user