2007-09-21 06:48:13 +04:00
|
|
|
<?php
|
|
|
|
class Doctrine_Resource_Server extends Doctrine_Resource
|
|
|
|
{
|
2007-09-21 22:01:08 +04:00
|
|
|
public $config = array();
|
2007-09-22 05:32:48 +04:00
|
|
|
public $format = 'xml';
|
2007-09-21 22:01:08 +04:00
|
|
|
|
|
|
|
public function __construct($config)
|
|
|
|
{
|
|
|
|
$this->config = array_merge($config, $this->config);
|
|
|
|
}
|
|
|
|
|
2007-09-22 05:32:48 +04:00
|
|
|
public function executeSave($request)
|
|
|
|
{
|
|
|
|
$model = $request['model'];
|
|
|
|
$data = $request['data'];
|
|
|
|
|
|
|
|
$record = new $model();
|
|
|
|
$record->fromArray($data);
|
|
|
|
$record->save();
|
|
|
|
|
|
|
|
return $record->toArray(true, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function executeQuery($request)
|
|
|
|
{
|
|
|
|
$dql = $request['dql'];
|
|
|
|
$params = isset($request['params']) ? $request['params']:array();
|
|
|
|
|
|
|
|
$conn = Doctrine_Manager::connection();
|
|
|
|
|
|
|
|
return $conn->query($dql, $params)->toArray(true, true);
|
|
|
|
}
|
|
|
|
|
2007-09-21 06:48:13 +04:00
|
|
|
public function execute($request)
|
|
|
|
{
|
2007-09-21 22:01:08 +04:00
|
|
|
if (!isset($request['type'])) {
|
|
|
|
throw new Doctrine_Resource_Exception('You must specify a request type: query or save');
|
2007-09-21 06:48:13 +04:00
|
|
|
}
|
|
|
|
|
2007-09-21 22:01:08 +04:00
|
|
|
$format = isset($request['format']) ? $request['format']:'xml';
|
2007-09-22 05:32:48 +04:00
|
|
|
$type = $request['type'];
|
|
|
|
$funcName = 'execute' . Doctrine::classify($type);
|
2007-09-21 22:01:08 +04:00
|
|
|
|
2007-09-22 05:32:48 +04:00
|
|
|
$result = $this->$funcName($request);
|
2007-09-21 06:48:13 +04:00
|
|
|
|
2007-09-21 22:01:08 +04:00
|
|
|
return Doctrine_Parser::dump($result, $format);
|
2007-09-21 06:48:13 +04:00
|
|
|
}
|
|
|
|
|
2007-09-21 22:01:08 +04:00
|
|
|
public function run($request)
|
2007-09-21 06:48:13 +04:00
|
|
|
{
|
|
|
|
echo $this->execute($request);
|
|
|
|
}
|
|
|
|
}
|