diff --git a/backend/index.php b/backend/index.php index 70cfe7c..e78bc1b 100644 --- a/backend/index.php +++ b/backend/index.php @@ -1,28 +1,46 @@ -* -* 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 -*/ - -/* - * Bootstrap entrypoint, just calls FrontController::run() + * 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 */ +// class autoloading +require 'lib/vendor/doctrine/Common/ClassLoader.php'; + +$doctrineLoader = new \Doctrine\Common\ClassLoader('Doctrine', 'lib/vendor/doctrine'); +$doctrineLoader->register(); // register on SPL autoload stack + +$vzLoader = new \Doctrine\Common\ClassLoader('Volkszaehler', 'lib'); +$vzLoader->register(); // register on SPL autoload stack + +// API version +define('VERSION', '0.2'); + +// enable strict error reporting +error_reporting(E_ALL); + +// load configuration into registry +if (!file_exists(__DIR__ . '/volkszaehler.conf.php')) { + throw new Exception('No configuration available! Use volkszaehler.conf.default.php as an template'); +} + +include __DIR__ . '/volkszaehler.conf.php'; + $fc = new FrontController(); // spawn frontcontroller $fc->run(); // execute controller and sends output diff --git a/backend/lib/Controller/ChannelController.php b/backend/lib/Controller/ChannelController.php index ace99d4..7d10cf6 100644 --- a/backend/lib/Controller/ChannelController.php +++ b/backend/lib/Controller/ChannelController.php @@ -40,14 +40,18 @@ class ChannelController extends Controller { $channel->type = 'Channel'; }*/ + // TODO adapt to doctrine orm $channel->persist(); $channel->save(); + $this->view->addChannel($channel); } // TODO check for valid user identity public function delete() { $channel = Channel::getByUuid($this->view->request->get['ucid']); + + // TODO adapt to doctrine orm $channel->delete(); } diff --git a/backend/lib/Controller/FrontController.php b/backend/lib/Controller/FrontController.php index 6caca2b..8030a19 100644 --- a/backend/lib/Controller/FrontController.php +++ b/backend/lib/Controller/FrontController.php @@ -36,10 +36,11 @@ final class FrontController { } $this->view = new $view; - // create entitymanager - require '/path/to/lib/Doctrine/Common/ClassLoader.php'; - $classLoader = new \Doctrine\Common\ClassLoader('Doctrine', 'lib/doctrine/lib'); - $classLoader->register(); // register on SPL autoload stack + $this->em = self::createEntityManager(); + } + + public static function createEntityManager() { + $config = Registry::get('config'); // Doctrine $doctConfig = new Configuration; @@ -47,15 +48,15 @@ final class FrontController { //$cache = new \Doctrine\Common\Cache\ApcCache; //$config->setMetadataCacheImpl($cache); - $driverImpl = $doctConfig->newDefaultAnnotationDriver('/path/to/lib/MyProject/Entities'); + $driverImpl = $doctConfig->newDefaultAnnotationDriver('lib/Model'); $doctConfig->setMetadataDriverImpl($driverImpl); //$config->setQueryCacheImpl($cache); - $doctConfig->setProxyDir('/path/to/myproject/lib/MyProject/Proxies'); - $doctConfig->setProxyNamespace('MyProject\Proxies'); + $doctConfig->setProxyDir('lib/Model/Proxies'); + $doctConfig->setProxyNamespace('Volkszaehler\Model\Proxies'); - $em = EntityManager::create($config['db'], $doctConfig); + return EntityManager::create($config['db'], $doctConfig); } public function run() { @@ -74,59 +75,6 @@ final class FrontController { public function __destruct() { $this->view->render(); // render view & send http response } - - public static function initialize() { - define('VERSION', '0.2'); - - // enable strict error reporting - error_reporting(E_ALL); - - // load configuration into registry - if (!file_exists(__DIR__ . '/volkszaehler.conf.php')) { - throw new Exception('No configuration available! Use volkszaehler.conf.default.php as an template'); - } - - include __DIR__ . '/volkszaehler.conf.php'; - - spl_autoload_register(array($this, 'loadClass')); - - $this->initializeDoctrine(); - } - - /* - * class autoloading - */ - private function loadClass($className) { - $libs = __DIR__ . '/lib/'; - - // preg_replace pattern class name => inclulde path - $mapping = array( - // util classes - '/^Registry$/' => 'util/registry', - '/^Uuid$/' => 'util/uuid', - - // model classes - '/^(Channel|User|Group|(Nested)?Database(Object)?)$/'=> 'model/$1', - '/^(.+(Meter|Sensor))$/' => 'model/channel/$2/$1', - '/^(Meter|Sensor)$/' => 'model/channel/$1', - - // view classes - '/^(Http.*)$/' => 'view/http/$1', - '/^(.*View)$/' => 'view/$1', - - // controller classes - '/^(.*Controller)$/' => 'controller/$1' - ); - - $include = $libs . strtolower(preg_replace(array_keys($mapping), array_values($mapping), $className)) . '.php'; - - if (!file_exists($include)) { - return false; - } - - require_once $include; - return true; - } } ?> \ No newline at end of file diff --git a/backend/lib/view/http/httphandle.php b/backend/lib/View/Http/HttpHandle.php similarity index 100% rename from backend/lib/view/http/httphandle.php rename to backend/lib/View/Http/HttpHandle.php diff --git a/backend/lib/view/http/httprequest.php b/backend/lib/View/Http/HttpRequest.php similarity index 100% rename from backend/lib/view/http/httprequest.php rename to backend/lib/View/Http/HttpRequest.php diff --git a/backend/lib/view/http/httpresponse.php b/backend/lib/View/Http/HttpResponse.php similarity index 100% rename from backend/lib/view/http/httpresponse.php rename to backend/lib/View/Http/HttpResponse.php diff --git a/backend/lib/view/jsonview.php b/backend/lib/View/JsonView.php similarity index 100% rename from backend/lib/view/jsonview.php rename to backend/lib/View/JsonView.php diff --git a/backend/lib/view/view.php b/backend/lib/View/View.php similarity index 100% rename from backend/lib/view/view.php rename to backend/lib/View/View.php diff --git a/backend/lib/view/xmlview.php b/backend/lib/View/XmlView.php similarity index 100% rename from backend/lib/view/xmlview.php rename to backend/lib/View/XmlView.php