1
0
mirror of synced 2024-12-14 07:06:04 +03:00
doctrine2/lib/Doctrine/Resource/Server.php

53 lines
1.4 KiB
PHP
Raw Normal View History

<?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);
}
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 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 22:01:08 +04:00
return Doctrine_Parser::dump($result, $format);
}
2007-09-21 22:01:08 +04:00
public function run($request)
{
echo $this->execute($request);
}
}