diff --git a/backend/lib/Controller/Controller.php b/backend/lib/Controller/Controller.php index affdcb8..0306bc7 100644 --- a/backend/lib/Controller/Controller.php +++ b/backend/lib/Controller/Controller.php @@ -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); } } diff --git a/backend/lib/Controller/DataController.php b/backend/lib/Controller/DataController.php index a9e6949..f15c19f 100644 --- a/backend/lib/Controller/DataController.php +++ b/backend/lib/Controller/DataController.php @@ -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); } } diff --git a/backend/lib/Controller/EntityController.php b/backend/lib/Controller/EntityController.php index 6bef8fb..b3c3a50 100644 --- a/backend/lib/Controller/EntityController.php +++ b/backend/lib/Controller/EntityController.php @@ -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); } } diff --git a/backend/lib/Router.php b/backend/lib/Router.php index f6043ad..a30b52c 100644 --- a/backend/lib/Router.php +++ b/backend/lib/Router.php @@ -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);