diff --git a/lib/Controller/Controller.php b/lib/Controller/Controller.php index 0306bc7..6e29197 100644 --- a/lib/Controller/Controller.php +++ b/lib/Controller/Controller.php @@ -23,6 +23,8 @@ namespace Volkszaehler\Controller; +use Volkszaehler\View; + /** * Controller superclass for all controllers * @@ -39,7 +41,7 @@ abstract class Controller { * @param View $view * @param EntityManager $em */ - public function __construct(\Volkszaehler\View\View $view, \Doctrine\ORM\EntityManager $em) { + public function __construct(View\View $view, \Doctrine\ORM\EntityManager $em) { $this->view = $view; $this->em = $em; } @@ -49,13 +51,19 @@ abstract class Controller { * * @param string $operation runs the operation if class method is available */ - public function run($operation, array $identifiers = array()) { - if (!is_callable(array($this, $operation))) { - throw new \Exception('Invalid context operation: ' . $operation); + public function run($op, array $arg = array()) { + if (!method_exists($this, $op)) { + throw new \Exception('Invalid context operation: ' . $op); + } + + switch(count($arg)) { // improved performence + case 0: return $this->{$op}(); + case 1: return $this->{$op}($arg[0]); + case 2: return $this->{$op}($arg[0], $arg[1]); + case 3: return $this->{$op}($arg[0], $arg[1], $arg[2]); + default: return call_user_func_array(array($this, $op), $arg); } - - return call_user_func_array(array($this, $operation), $identifiers); } } -?> \ No newline at end of file +?> diff --git a/lib/Router.php b/lib/Router.php index 8071f12..520377d 100644 --- a/lib/Router.php +++ b/lib/Router.php @@ -116,8 +116,6 @@ class Router { $this->pathInfo = self::getPathInfo(); $this->format = pathinfo($this->pathInfo, PATHINFO_EXTENSION); - Util\Debug::log('env vars', $_SERVER); - if (!array_key_exists($this->format, self::$viewMapping)) { $this->view = new View\JSON($request, $response); // fallback view @@ -143,8 +141,7 @@ class Router { */ public function run() { $operation = self::getOperation($this->view->request); - $context = substr($this->pathInfo, 1, strrpos($this->pathInfo, '.') -1); // remove leading slash and format - $context = explode('/', $context); // split into path segments + $context = explode('/', substr($this->pathInfo, 1, strrpos($this->pathInfo, '.')-1)); // parse pathinfo if (!array_key_exists($context[0], self::$controllerMapping)) { if (empty($context[0])) { @@ -158,13 +155,7 @@ class Router { $class = self::$controllerMapping[$context[0]]; $controller = new $class($this->view, $this->em); - if (isset($pathInfo[1])) { - $result = $controller->run($operation, array_slice($context, 1)); - } - else { - $result = $controller->run($operation); - } - + $result = $controller->run($operation, array_slice($context, 1)); $this->view->add($result); } diff --git a/misc/controller/bash/log_onewire.sh b/misc/controller/bash/log_onewire similarity index 77% rename from misc/controller/bash/log_onewire.sh rename to misc/controller/bash/log_onewire index 701322b..de497c6 100755 --- a/misc/controller/bash/log_onewire.sh +++ b/misc/controller/bash/log_onewire @@ -1,30 +1,33 @@ #!/bin/bash # -# Copyright (c) 2010 by Justin Otherguy -# -# This program is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License (either version 2 or -# version 3) as published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# -# For more information on the GPL, please go to: -# http://www.gnu.org/copyleft/gpl.html -# # This is a simple bash script to read Dallas 1-Wire sensors # with digitemp and log their values to the volkszaehler project. # # call it with a cronjob similiar to this one: # -# */5 * * * * ~/bin/log1wire.sh +# */5 * * * * ~/bin/log1wire.sh # +# @copyright Copyright (c) 2010, The volkszaehler.org project +# @package controller +# @license http://www.opensource.org/licenses/gpl-license.php GNU Public License +# @author Steffen Vogel +# +## +# This file is part of volkzaehler.org +# +# volkzaehler.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# any later version. +# +# volkzaehler.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with volkszaehler.org. If not, see . +## # configuration # diff --git a/bin/doctrine b/misc/tools/doctrine similarity index 100% rename from bin/doctrine rename to misc/tools/doctrine diff --git a/bin/doctrine.php b/misc/tools/doctrine.php similarity index 100% rename from bin/doctrine.php rename to misc/tools/doctrine.php diff --git a/misc/tools/install.sh b/misc/tools/install similarity index 72% rename from misc/tools/install.sh rename to misc/tools/install index 9d73bfb..a9ab600 100755 --- a/misc/tools/install.sh +++ b/misc/tools/install @@ -1,9 +1,35 @@ #!/bin/bash -# Jakob Hirsch, 2010-11-20 # +# Installer +# +# For creating/updating the configuration/database +# and downloading of required libraries +# and configuration of of the PHP interpreter/webserver +# +# @copyright Copyright (c) 2010, The volkszaehler.org project +# @package tools +# @license http://www.opensource.org/licenses/gpl-license.php GNU Public License +# @author Jakob Hirsch +# +## +# This file is part of volkzaehler.org +# +# volkzaehler.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# any later version. +# +# volkzaehler.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with volkszaehler.org. If not, see . +## # cannot handle other hosts right now -db_host=localhost +db_host=localhost set -e shopt -s nocasematch @@ -108,9 +134,9 @@ if [ "$REPLY" == "y" ]; then echo creating database $db_name... mysql -h$db_host -u$db_admin_user -p$db_admin_pass -e 'CREATE DATABASE `'$db_name'`' pushd $vzdir - php $dtdir orm:schema-tool:create + php misc/tools/doctrine orm:schema-tool:create popd - + echo "creating db user $db_user with proper rights..." mysql -h$db_host -u$db_admin_user -p$db_admin_pass <<-EOF CREATE USER '$db_user'@'$db_host' IDENTIFIED BY '$db_pass'; @@ -124,7 +150,7 @@ ask "insert demo data in to database?" n if [ "$REPLY" == "y" ]; then get_admin get_db_name - cat $vzdir/misc/sql/demo/entities.sql $vzdir/misc/sql/demo/properties.sql $vzdir/misc/sql/demo/data-demoset1.sql | + cat $vzdir/misc/sql/demo/entities.sql $vzdir/misc/sql/demo/properties.sql $vzdir/share/sql/demo/data-demoset1.sql | mysql -h$db_host -u$db_admin_user -p$db_admin_pass $db_name fi