From 3dc45da8cd7a1559dc92a525fe9ff26a11409252 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Mon, 27 Dec 2010 23:15:43 +0100 Subject: [PATCH 1/4] adapted install script to new dir structure added copyright notices --- .../bash/{log_onewire.sh => log_onewire} | 41 ++++++++++--------- misc/tools/{install.sh => install} | 38 ++++++++++++++--- 2 files changed, 54 insertions(+), 25 deletions(-) rename misc/controller/bash/{log_onewire.sh => log_onewire} (77%) rename misc/tools/{install.sh => install} (68%) 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/misc/tools/install.sh b/misc/tools/install similarity index 68% rename from misc/tools/install.sh rename to misc/tools/install index d6131c4..3479f5c 100755 --- a/misc/tools/install.sh +++ b/misc/tools/install @@ -1,6 +1,32 @@ #!/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 @@ -72,13 +98,13 @@ if [ "$REPLY" == 'y' ]; then mkdir -p $vzdir git clone $vz_git $vzdir - pushd $vzdir/backend/lib/vendor + pushd $vzdir/lib/vendor ln -s $dtdir/lib/Doctrine/ . ln -s $dtdir/lib/vendor/Symfony/ . popd fi -config=$vzdir/backend/volkszaehler.conf.php +config=$vzdir/etc/volkszaehler.conf.php ############ echo @@ -95,7 +121,7 @@ if [ "$REPLY" == "y" ]; then sed -e "s/^\(\$config\['db'\]\['user'\]\).*/\1 = '$db_user';/" \ -e "s/^\(\$config\['db'\]\['password'\]\).*/\1 = '$db_pass';/" \ -e "s/^\(\$config\['db'\]\['dbname'\]\).*/\1 = '$db_name';/" \ - < $vzdir/backend/volkszaehler.conf.template.php \ + < $vzdir/etc/volkszaehler.conf.template.php \ > $config fi @@ -108,7 +134,7 @@ 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 backend/bin/doctrine orm:schema-tool:create + php misc/tools/doctrine orm:schema-tool:create popd echo "creating db user $db_user with proper rights..." @@ -124,7 +150,7 @@ ask "insert demo data in to database?" n if [ "$REPLY" == "y" ]; then get_admin get_db_name - cat $vzdir/share/sql/demo/entities.sql $vzdir/share/sql/demo/properties.sql $vzdir/share/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 From 8891c62ff5305ab74f84728c3141198fa6c9759c Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Mon, 27 Dec 2010 23:16:48 +0100 Subject: [PATCH 2/4] moved doctrine cli tool --- {bin => misc/tools}/doctrine | 0 {bin => misc/tools}/doctrine.php | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename {bin => misc/tools}/doctrine (100%) rename {bin => misc/tools}/doctrine.php (97%) 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 97% rename from bin/doctrine.php rename to misc/tools/doctrine.php index 4ef6716..1584842 100644 --- a/bin/doctrine.php +++ b/misc/tools/doctrine.php @@ -28,7 +28,7 @@ use Volkszaehler\Util; // TODO replace by state class define('VZ_VERSION', 0.2); -define('VZ_DIR', realpath(__DIR__ . '/../..')); +define('VZ_DIR', realpath(__DIR__ . '/..')); // class autoloading require_once VZ_DIR . '/lib/Util/ClassLoader.php'; From 3fe539d0aa329a0764618dfa93e0fb843aa5ebf1 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Mon, 27 Dec 2010 23:18:30 +0100 Subject: [PATCH 3/4] adapted to new location --- misc/tools/doctrine.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc/tools/doctrine.php b/misc/tools/doctrine.php index 1584842..4ef6716 100644 --- a/misc/tools/doctrine.php +++ b/misc/tools/doctrine.php @@ -28,7 +28,7 @@ use Volkszaehler\Util; // TODO replace by state class define('VZ_VERSION', 0.2); -define('VZ_DIR', realpath(__DIR__ . '/..')); +define('VZ_DIR', realpath(__DIR__ . '/../..')); // class autoloading require_once VZ_DIR . '/lib/Util/ClassLoader.php'; From 6492b080deb785a7e41b350e3c6662e64469e20e Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Mon, 27 Dec 2010 23:46:27 +0100 Subject: [PATCH 4/4] improved performence --- lib/Controller/Controller.php | 22 +++++++++++++++------- lib/Router.php | 13 ++----------- 2 files changed, 17 insertions(+), 18 deletions(-) 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); }