renamed class files
prepared for namespaces
This commit is contained in:
parent
e205925b19
commit
636c15bb1f
9 changed files with 52 additions and 82 deletions
|
@ -1,28 +1,46 @@
|
|||
<?php
|
||||
/*
|
||||
* Copyright (c) 2010 by Justin Otherguy <justin@justinotherguy.org>
|
||||
*
|
||||
* 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 <justin@justinotherguy.org>
|
||||
*
|
||||
* 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
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
Add table
Reference in a new issue