refactoring und validation of identifiers

This commit is contained in:
Steffen Vogel 2010-09-22 23:18:08 +02:00
parent c4ed1acef8
commit 4195e8b993
4 changed files with 16 additions and 18 deletions

View file

@ -49,12 +49,12 @@ abstract class Controller {
*
* @param string $operation runs the operation if class method is available
*/
public function run($operation, array $params = array()) {
public function run($operation, array $identifiers = array()) {
if (!is_callable(array($this, $operation))) {
throw new \Exception('Invalid context operation: ' . $operation);
}
return call_user_func_array(array($this, $operation), $params);
return call_user_func_array(array($this, $operation), $identifiers);
}
}

View file

@ -68,11 +68,11 @@ class DataController extends Controller {
$this->em->flush();
}
public function run($operation, array $params = array()) {
public function run($operation, array $identifiers = array()) {
$ec = new EntityController($this->view, $this->em);
$params[0] = $ec->get($params[0]);
$identifiers[0] = $ec->get($identifiers[0]);
return parent::run($operation, $params);
return parent::run($operation, $identifiers);
}
}

View file

@ -38,19 +38,23 @@ class EntityController extends Controller {
*
* @param string $identifier
*/
public function get($identifier) {
public function get($uuid) {
if (!Util\UUID::validate($uuid)) {
throw new \Exception('Invalid UUID: ' . $uuid);
}
$dql = 'SELECT a, p
FROM Volkszaehler\Model\Entity a
LEFT JOIN a.properties p
WHERE a.uuid = ?1';
$q = $this->em->createQuery($dql);
$q->setParameter(1, $identifier);
$q->setParameter(1, $uuid);
try {
return $q->getSingleResult();
} catch (\Doctrine\ORM\NoResultException $e) {
throw new \Exception('No entity found with uuid: ' . $identifier);
throw new \Exception('No entity found with UUID: ' . $uuid);
}
}

View file

@ -74,10 +74,9 @@ class Router {
protected static $controllerMapping = array(
'channel' => 'Volkszaehler\Controller\ChannelController',
'group' => 'Volkszaehler\Controller\AggregatorController',
'token' => 'Volkszaehler\Controller\TokenController',
'capabilities' => 'Volkszaehler\Controller\CapabilitiesController',
'data' => 'Volkszaehler\Controller\DataController',
'entity' => 'Volkszaehler\Controller\EntityController'
'group' => 'Volkszaehler\Controller\AggregatorController',
'entity' => 'Volkszaehler\Controller\EntityController',
'data' => 'Volkszaehler\Controller\DataController'
);
/**
@ -151,12 +150,7 @@ class Router {
$controller = new $class($this->view, $this->em);
if (isset($pathInfo[1])) {
if (Util\UUID::validate($pathInfo[1], TRUE)) { // TODO make universal
$result = $controller->run($this->operation, explode('/', $pathInfo[1]));
}
else {
throw new \Exception('Invalid parameter: ' . $pathInfo[1]);
}
$result = $controller->run($this->operation, array_slice($pathInfo, 1));
}
else {
$result = $controller->run($this->operation);