# HG changeset patch # User Markus Broeker # Date 1455458865 -3600 # Node ID 8b4f9c6136f4d2a9183ef1238aed858276f2ce4f # Parent 41078fd1e80dec0cc648055bd02c33f79668440e Umstellung auf LF diff --git a/classes/bfw/Configuration.php b/classes/bfw/Configuration.php --- a/classes/bfw/Configuration.php +++ b/classes/bfw/Configuration.php @@ -1,82 +1,82 @@ - - * - */ - -namespace bfw; - -use PDO; - -/** - * Class Configuration - */ -class Configuration { - - /** - * Standard-Autoloader für die Basis-Klassen des Projekts - * - * @param $class - * @return bool - */ - public static function bfw_autoLoader($class) { - $nsClass = str_replace('\\', '/', $class); - $filename = sprintf('%s/classes/%s.php', BFW_PATH, $nsClass); - $classPath = sprintf('classes/%s.php', $nsClass); - - if (file_exists($filename)) { - require_once BFW_PATH . "/$classPath"; - - return true; - } - - return false; - } - - /** - * Standard Konfiguration für den Logger - * - * @return array - */ - public static function bfw_loggerConfiguration() { - return array( - 'rootLogger' => array('appenders' => array('default')), - 'appenders' => array( - 'default' => array( - 'class' => 'LoggerAppenderFile', - 'layout' => array('class' => 'LoggerLayoutSimple'), - 'params' => array( - 'file' => BFW_PATH . '/logs/bfw.log', - 'append' => true - ) - ) - ) - ); - } - - /** - * Standard Konfiguration für den PDO-Treiber - * - * @return array - */ - public static function getDataSourceProperties() { - $dataSources = array( - 'psql' => array( - 'dsn' => 'pgsql:host=localhost;dbname=bfw', - 'config' => array(), - 'username' => 'bfw', - 'password' => 'bfw', - ), - 'mysql' => array( - 'dsn' => 'mysql:host=localhost;dbname=bfw', - 'config' => array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'), - 'username' => 'bfw', - 'password' => 'bfw', - ) - ); - - return $dataSources['mysql']; - } - -} + + * + */ + +namespace bfw; + +use PDO; + +/** + * Class Configuration + */ +class Configuration { + + /** + * Standard-Autoloader für die Basis-Klassen des Projekts + * + * @param $class + * @return bool + */ + public static function bfw_autoLoader($class) { + $nsClass = str_replace('\\', '/', $class); + $filename = sprintf('%s/classes/%s.php', BFW_PATH, $nsClass); + $classPath = sprintf('classes/%s.php', $nsClass); + + if (file_exists($filename)) { + require_once BFW_PATH . "/$classPath"; + + return true; + } + + return false; + } + + /** + * Standard Konfiguration für den Logger + * + * @return array + */ + public static function bfw_loggerConfiguration() { + return array( + 'rootLogger' => array('appenders' => array('default')), + 'appenders' => array( + 'default' => array( + 'class' => 'LoggerAppenderFile', + 'layout' => array('class' => 'LoggerLayoutSimple'), + 'params' => array( + 'file' => BFW_PATH . '/logs/bfw.log', + 'append' => true + ) + ) + ) + ); + } + + /** + * Standard Konfiguration für den PDO-Treiber + * + * @return array + */ + public static function getDataSourceProperties() { + $dataSources = array( + 'psql' => array( + 'dsn' => 'pgsql:host=localhost;dbname=bfw', + 'config' => array(), + 'username' => 'bfw', + 'password' => 'bfw', + ), + 'mysql' => array( + 'dsn' => 'mysql:host=localhost;dbname=bfw', + 'config' => array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'), + 'username' => 'bfw', + 'password' => 'bfw', + ) + ); + + return $dataSources['mysql']; + } + +} diff --git a/classes/bfw/Dispatcher.php b/classes/bfw/Dispatcher.php --- a/classes/bfw/Dispatcher.php +++ b/classes/bfw/Dispatcher.php @@ -1,75 +1,75 @@ - - * - */ - -namespace bfw; - -use bfw\core\Controller; -use ReflectionClass; -use ReflectionException; - -/** - * Class Dispatcher - */ -class Dispatcher { - - private $request; - - public function __construct() { - $this->request = new Request(); - } - - /** - * @param $url - */ - public static function route($url) { - header(sprintf("Location: %s", $url)); - exit(0); - } - - /** - * Standard Request Handler für das Projekt - * - * Diese Instanz kümmert sich selbständig um die GET- und POST Werte und - * speichert diese in der Session. - * - * Einfach zu nutzende Methoden(Schnittstelle zur Session) komplettieren diesen Handler - * - * @return Request - */ - public function getRequest() { - return $this->request; - } - - /** - * Führt den jeweiligen Controller aus - * - */ - public function delegate() { - $this->request->keepRequestData(); - - $controllerName = $this->request->get('controller', 'home'); - $action = $this->request->get('action', 'index'); - - $class = Controller::findControllerInNameSpace($controllerName); - - try { - $reflection = new ReflectionClass($class); - $controller = $reflection->newInstance(); - - // Mapping vom GET-Parameter 'action' auf Controller::$action() - if (!$reflection->hasMethod($action)) { - $action = 'index'; - } - } catch (ReflectionException $re) { - $controller = new mvc\controller\ErrorController(); - $action = 'index'; - } - - return $controller->$action(); - } - -} + + * + */ + +namespace bfw; + +use bfw\core\Controller; +use ReflectionClass; +use ReflectionException; + +/** + * Class Dispatcher + */ +class Dispatcher { + + private $request; + + public function __construct() { + $this->request = new Request(); + } + + /** + * @param $url + */ + public static function route($url) { + header(sprintf("Location: %s", $url)); + exit(0); + } + + /** + * Standard Request Handler für das Projekt + * + * Diese Instanz kümmert sich selbständig um die GET- und POST Werte und + * speichert diese in der Session. + * + * Einfach zu nutzende Methoden(Schnittstelle zur Session) komplettieren diesen Handler + * + * @return Request + */ + public function getRequest() { + return $this->request; + } + + /** + * Führt den jeweiligen Controller aus + * + */ + public function delegate() { + $this->request->keepRequestData(); + + $controllerName = $this->request->get('controller', 'home'); + $action = $this->request->get('action', 'index'); + + $class = Controller::findControllerInNameSpace($controllerName); + + try { + $reflection = new ReflectionClass($class); + $controller = $reflection->newInstance(); + + // Mapping vom GET-Parameter 'action' auf Controller::$action() + if (!$reflection->hasMethod($action)) { + $action = 'index'; + } + } catch (ReflectionException $re) { + $controller = new mvc\controller\ErrorController(); + $action = 'index'; + } + + return $controller->$action(); + } + +} diff --git a/classes/bfw/Request.php b/classes/bfw/Request.php --- a/classes/bfw/Request.php +++ b/classes/bfw/Request.php @@ -1,277 +1,277 @@ - - * - */ - -namespace bfw; - -use Logger; - -/** - * Class Request - */ -class Request { - - /** - * - * @var Logger - */ - protected $logger = null; - - /** - * Default Constructor - */ - public function __construct() { - $this->logger = Logger::getLogger('__CLASS__'); - - $this->initSession(); - } - - /** - * Initialisiert die Session für das jeweilige Projekt - * - */ - public function initSession() { - if (!isset($_SESSION['prefix'])) { - $_SESSION['prefix'] = array( - 'get' => array(), - 'session' => array(), - 'isLoggedIn' => false, - 'user_id' => 1, - 'group_id' => 1, - 'error' => '', - 'msg' => '', - 'lastpage' => 'home', - ); - } - } - - /** - * Liefert die komplette URL des jeweiligen Requests - * - * @return string - */ - public static function getUrl() { - return sprintf("%s%s", self::getBaseUrl(), $_SERVER['REQUEST_URI']); - } - - /** - * Liefert die Basis-URL des jeweiligen Projekts - * - * @return string - */ - public static function getBaseUrl() { - return sprintf("%s://%s", isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http', $_SERVER['SERVER_NAME']); - } - - /** - * Liefert einen gefilterten 'session' Wert - * - * Hierbei handelt es sich um einen zuvor gespeicherten POST-Wert, - * der in ['prefix']['session'] gelandet ist... - * - * @param $param - * @param string $default - * - * @return string - */ - public static function session($param, $default = '') { - if (isset($_SESSION['prefix']['session'][$param])) { - return $_SESSION['prefix']['session'][$param]; - } - - return $default; - } - - /** - * Liefert einen gefilterten 'get' Wert - * - * Hierbei handelt es sich um einen zuvor gespeicherten POST-Wert, - * der in ['prefix']['session'] geladet ist... - * - * @param $param - * @param string $default - * - * @return string - */ - public static function getParameter($param, $default = '') { - if (isset($_SESSION['prefix']['get'][$param])) { - return $_SESSION['prefix']['get'][$param]; - } - - return $default; - } - - /** - * Holt einen Session Wert aus dem jeweiligen Prefix - * - * @param $key - * @param string $default - * @param null $storage - * @return string - */ - public static function getKey($key, $default = '', $storage = null) { - if ($storage != null) { - return $_SESSION['prefix'][$storage][$key]; - } - - if (isset($_SESSION['prefix'][$key])) { - return $_SESSION['prefix'][$key]; - } - - return $default; - } - - /** - * Löscht einen Get-Wert aus dem jeweiligen Prefix - * - * @param $key - */ - public static function deleteParameterKey($key) { - unset($_SESSION['prefix']['get'][$key]); - } - - /** - * Löscht einen Session Wert aus dem jeweiligen Prefix - * - * @param $key - */ - public static function deleteKey($key) { - unset($_SESSION['prefix'][$key]); - } - - /** - * Prüft, ob der aktuelle Request einen POST enthält - * - * @return bool - */ - public static function hasPost() { - return (count($_POST) != 0); - } - - /** - * Keine Warnung, keine Gnade - */ - public function destroySession() { - unset($_SESSION['prefix']); - @session_destroy(); - - $this->initSession(); - } - - /** - * Bei jedem Seitenaufruf werden die GET/Post Anfragen in der Session separiert gespeichert - * - * Struktur: - * GET Sachen ins 'get' array - * POST Sachen ins 'session' array - */ - public function keepRequestData() { - foreach ($_GET as $key => $value) { - $filteredKey = $this->filter($key); - $filteredValue = $this->filter($value); - - $_SESSION['prefix']['get'][$filteredKey] = $filteredValue; - } - - foreach ($_POST as $key => $value) { - $filteredKey = $this->filter($key); - $filteredValue = $this->filter($value); - - $_SESSION['prefix']['session'][$filteredKey] = $filteredValue; - } - } - - /** - * Statische Filtermethode für beliebige Strings/Array of Strings - * - * filter_input kann nur mit GET/POST umgehen, diese Methode mit Allem. - * - * @param string $param - * - * @return string|array - */ - public static function filter($param) { - if (is_array($param)) { - $filtered = array(); - foreach ($param as $key => $value) { - $filtered[self::filter($key)] = self::filter($value); - } - - return $filtered; - } - - return htmlspecialchars($param, ENT_QUOTES, 'utf-8'); - } - - /** - * Setzt einen neuen Session Wert ins jeweilige Prefix - * - * @param $key - * @param $value - * @param $storage - */ - public function setKey($key, $value, $storage = null) { - if ($storage != null) { - $_SESSION['prefix'][$storage][self::filter($key)] = self::filter($value); - } else { - $_SESSION['prefix'][self::filter($key)] = self::filter($value); - } - } - - /** - * Interne Debug-Funktion zum Anzeigen der Session Struktur - * - * Beliebige URL mit ?debug=1 aufrufen und der Debug Mechanismus ist aktiviert. - * - * @return string - */ - public function printSession() { - $this->logger->info(sprintf('SESSION: %s', print_r($_SESSION['prefix'], true))); - - if ($this->get('debug') == '') { - return ''; - } - - return "
" . print_r($_SESSION['prefix'], true) . "
"; - } - - /** - * Liefert einen gefilterten GET-Wert - * - * @param $param - * @param $default - * - * @return string - */ - public function get($param, $default = '') { - $value = filter_input(INPUT_GET, $param); - - if ($value == '') { - return $default; - } - - return $value; - } - - /** - * Liefert einen gefilterten POST-Wert - * - * @param $param - * @param $default - * - * @return string - */ - public function post($param, $default = '') { - $value = filter_input(INPUT_POST, $param); - - if ($value == '') { - return $default; - } - - return $value; - } - -} + + * + */ + +namespace bfw; + +use Logger; + +/** + * Class Request + */ +class Request { + + /** + * + * @var Logger + */ + protected $logger = null; + + /** + * Default Constructor + */ + public function __construct() { + $this->logger = Logger::getLogger('__CLASS__'); + + $this->initSession(); + } + + /** + * Initialisiert die Session für das jeweilige Projekt + * + */ + public function initSession() { + if (!isset($_SESSION['prefix'])) { + $_SESSION['prefix'] = array( + 'get' => array(), + 'session' => array(), + 'isLoggedIn' => false, + 'user_id' => 1, + 'group_id' => 1, + 'error' => '', + 'msg' => '', + 'lastpage' => 'home', + ); + } + } + + /** + * Liefert die komplette URL des jeweiligen Requests + * + * @return string + */ + public static function getUrl() { + return sprintf("%s%s", self::getBaseUrl(), $_SERVER['REQUEST_URI']); + } + + /** + * Liefert die Basis-URL des jeweiligen Projekts + * + * @return string + */ + public static function getBaseUrl() { + return sprintf("%s://%s", isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http', $_SERVER['SERVER_NAME']); + } + + /** + * Liefert einen gefilterten 'session' Wert + * + * Hierbei handelt es sich um einen zuvor gespeicherten POST-Wert, + * der in ['prefix']['session'] gelandet ist... + * + * @param $param + * @param string $default + * + * @return string + */ + public static function session($param, $default = '') { + if (isset($_SESSION['prefix']['session'][$param])) { + return $_SESSION['prefix']['session'][$param]; + } + + return $default; + } + + /** + * Liefert einen gefilterten 'get' Wert + * + * Hierbei handelt es sich um einen zuvor gespeicherten POST-Wert, + * der in ['prefix']['session'] geladet ist... + * + * @param $param + * @param string $default + * + * @return string + */ + public static function getParameter($param, $default = '') { + if (isset($_SESSION['prefix']['get'][$param])) { + return $_SESSION['prefix']['get'][$param]; + } + + return $default; + } + + /** + * Holt einen Session Wert aus dem jeweiligen Prefix + * + * @param $key + * @param string $default + * @param null $storage + * @return string + */ + public static function getKey($key, $default = '', $storage = null) { + if ($storage != null) { + return $_SESSION['prefix'][$storage][$key]; + } + + if (isset($_SESSION['prefix'][$key])) { + return $_SESSION['prefix'][$key]; + } + + return $default; + } + + /** + * Löscht einen Get-Wert aus dem jeweiligen Prefix + * + * @param $key + */ + public static function deleteParameterKey($key) { + unset($_SESSION['prefix']['get'][$key]); + } + + /** + * Löscht einen Session Wert aus dem jeweiligen Prefix + * + * @param $key + */ + public static function deleteKey($key) { + unset($_SESSION['prefix'][$key]); + } + + /** + * Prüft, ob der aktuelle Request einen POST enthält + * + * @return bool + */ + public static function hasPost() { + return (count($_POST) != 0); + } + + /** + * Keine Warnung, keine Gnade + */ + public function destroySession() { + unset($_SESSION['prefix']); + @session_destroy(); + + $this->initSession(); + } + + /** + * Bei jedem Seitenaufruf werden die GET/Post Anfragen in der Session separiert gespeichert + * + * Struktur: + * GET Sachen ins 'get' array + * POST Sachen ins 'session' array + */ + public function keepRequestData() { + foreach ($_GET as $key => $value) { + $filteredKey = $this->filter($key); + $filteredValue = $this->filter($value); + + $_SESSION['prefix']['get'][$filteredKey] = $filteredValue; + } + + foreach ($_POST as $key => $value) { + $filteredKey = $this->filter($key); + $filteredValue = $this->filter($value); + + $_SESSION['prefix']['session'][$filteredKey] = $filteredValue; + } + } + + /** + * Statische Filtermethode für beliebige Strings/Array of Strings + * + * filter_input kann nur mit GET/POST umgehen, diese Methode mit Allem. + * + * @param string $param + * + * @return string|array + */ + public static function filter($param) { + if (is_array($param)) { + $filtered = array(); + foreach ($param as $key => $value) { + $filtered[self::filter($key)] = self::filter($value); + } + + return $filtered; + } + + return htmlspecialchars($param, ENT_QUOTES, 'utf-8'); + } + + /** + * Setzt einen neuen Session Wert ins jeweilige Prefix + * + * @param $key + * @param $value + * @param $storage + */ + public function setKey($key, $value, $storage = null) { + if ($storage != null) { + $_SESSION['prefix'][$storage][self::filter($key)] = self::filter($value); + } else { + $_SESSION['prefix'][self::filter($key)] = self::filter($value); + } + } + + /** + * Interne Debug-Funktion zum Anzeigen der Session Struktur + * + * Beliebige URL mit ?debug=1 aufrufen und der Debug Mechanismus ist aktiviert. + * + * @return string + */ + public function printSession() { + $this->logger->info(sprintf('SESSION: %s', print_r($_SESSION['prefix'], true))); + + if ($this->get('debug') == '') { + return ''; + } + + return "
" . print_r($_SESSION['prefix'], true) . "
"; + } + + /** + * Liefert einen gefilterten GET-Wert + * + * @param $param + * @param $default + * + * @return string + */ + public function get($param, $default = '') { + $value = filter_input(INPUT_GET, $param); + + if ($value == '') { + return $default; + } + + return $value; + } + + /** + * Liefert einen gefilterten POST-Wert + * + * @param $param + * @param $default + * + * @return string + */ + public function post($param, $default = '') { + $value = filter_input(INPUT_POST, $param); + + if ($value == '') { + return $default; + } + + return $value; + } + +} diff --git a/classes/bfw/Response.php b/classes/bfw/Response.php --- a/classes/bfw/Response.php +++ b/classes/bfw/Response.php @@ -1,76 +1,76 @@ - - * - */ - -namespace bfw; - -/** - * Class Response - */ -class Response { - - /** - * - * @var array - */ - private $headers; - - /** - * - * @var int - */ - private $statusCode; - - /** - * - */ - public function __construct() { - $this->headers = headers_list(); - $this->statusCode = http_response_code(); - } - - /** - * - * @return array - */ - public function getHeaders() { - return $this->headers; - } - - /** - * - * @return int - */ - public function getStatusCode() { - return $this->statusCode; - } - - /** - * - * @param int $statusCode - * - * @return \bfw\Response - */ - public function setStatusCode($statusCode) { - $this->statusCode = $statusCode; - - return $this; - } - - /** - * @param $key - * - * @return string - */ - public function get($key) { - if (array_key_exists($key, $this->headers)) { - return $this->headers[$key]; - } - - return ''; - } - -} + + * + */ + +namespace bfw; + +/** + * Class Response + */ +class Response { + + /** + * + * @var array + */ + private $headers; + + /** + * + * @var int + */ + private $statusCode; + + /** + * + */ + public function __construct() { + $this->headers = headers_list(); + $this->statusCode = http_response_code(); + } + + /** + * + * @return array + */ + public function getHeaders() { + return $this->headers; + } + + /** + * + * @return int + */ + public function getStatusCode() { + return $this->statusCode; + } + + /** + * + * @param int $statusCode + * + * @return \bfw\Response + */ + public function setStatusCode($statusCode) { + $this->statusCode = $statusCode; + + return $this; + } + + /** + * @param $key + * + * @return string + */ + public function get($key) { + if (array_key_exists($key, $this->headers)) { + return $this->headers[$key]; + } + + return ''; + } + +} diff --git a/classes/bfw/core/Controller.php b/classes/bfw/core/Controller.php --- a/classes/bfw/core/Controller.php +++ b/classes/bfw/core/Controller.php @@ -1,138 +1,138 @@ - - * - */ - -namespace bfw\core; - -use bfw\Request; -use bfw\Response; -use Logger; - -/** - * Class Controller - */ -abstract class Controller { - - protected $logger; - - /** - * @var Model - */ - private $model; - - /** - * @var Request - */ - private $request; - - /** - * @var Response - */ - private $response; - - /** - * @var View - */ - private $view; - - /** - * Controller constructor. - * - */ - public function __construct() { - $this->request = new Request(); - $this->response = new Response(); - - $this->model = $this->getDataModelInstance(); - $this->view = new View($this, $this->model); - - $this->logger = Logger::getLogger(get_class($this)); - } - - private function getDataModelInstance() { - $modelName = $this->getModelName(); - - return new $modelName(); - } - - private function getModelName() { - $modelName = str_replace('controller', 'model', get_class($this)); - $modelName = strtolower($modelName); - - return str_replace('controller', '\DataModel', $modelName); - } - - /** - * @param $controller - * @return string - */ - public static function findControllerInNameSpace($controller) { - return sprintf('bfw\mvc\controller\%sController', ucfirst($controller)); - } - - /** - * @return View - */ - public function getView() { - return $this->view; - } - - /** - * @param $view - * @return $this - */ - public function setView($view) { - $this->view = $view; - - return $this; - } - - /** - * @return Response - */ - public function getResponse() { - return $this->response; - } - - /** - * @param $response - * @return $this - */ - public function setResponse($response) { - $this->response = $response; - - return $this; - } - - /** - * @return Model - */ - public function getModel() { - return $this->model; - } - - /** - * @param $model - * @return $this - */ - public function setModel($model) { - $this->model = $model; - - return $this; - } - - /** - * @return Request - */ - public function getRequest() { - return $this->request; - } - - /** - * @return mixed - */ - abstract public function index(); -} + + * + */ + +namespace bfw\core; + +use bfw\Request; +use bfw\Response; +use Logger; + +/** + * Class Controller + */ +abstract class Controller { + + protected $logger; + + /** + * @var Model + */ + private $model; + + /** + * @var Request + */ + private $request; + + /** + * @var Response + */ + private $response; + + /** + * @var View + */ + private $view; + + /** + * Controller constructor. + * + */ + public function __construct() { + $this->request = new Request(); + $this->response = new Response(); + + $this->model = $this->getDataModelInstance(); + $this->view = new View($this, $this->model); + + $this->logger = Logger::getLogger(get_class($this)); + } + + private function getDataModelInstance() { + $modelName = $this->getModelName(); + + return new $modelName(); + } + + private function getModelName() { + $modelName = str_replace('controller', 'model', get_class($this)); + $modelName = strtolower($modelName); + + return str_replace('controller', '\DataModel', $modelName); + } + + /** + * @param $controller + * @return string + */ + public static function findControllerInNameSpace($controller) { + return sprintf('bfw\mvc\controller\%sController', ucfirst($controller)); + } + + /** + * @return View + */ + public function getView() { + return $this->view; + } + + /** + * @param $view + * @return $this + */ + public function setView($view) { + $this->view = $view; + + return $this; + } + + /** + * @return Response + */ + public function getResponse() { + return $this->response; + } + + /** + * @param $response + * @return $this + */ + public function setResponse($response) { + $this->response = $response; + + return $this; + } + + /** + * @return Model + */ + public function getModel() { + return $this->model; + } + + /** + * @param $model + * @return $this + */ + public function setModel($model) { + $this->model = $model; + + return $this; + } + + /** + * @return Request + */ + public function getRequest() { + return $this->request; + } + + /** + * @return mixed + */ + abstract public function index(); +} diff --git a/classes/bfw/core/Model.php b/classes/bfw/core/Model.php --- a/classes/bfw/core/Model.php +++ b/classes/bfw/core/Model.php @@ -1,67 +1,67 @@ - - * - */ - -namespace bfw\core; - -use bfw\entities\TGroup; -use bfw\entities\TUser; -use Logger; - -/** - * Class Model - * - */ -class Model { - - protected $logger; - - /** - * @var TUser - */ - private $user; - - /** - * @var TGroup - */ - private $group; - - public function __construct() { - $this->logger = Logger::getLogger(get_class($this)); - - $this->user = new TUser(); - $this->group = new TGroup(); - } - - /** - * @return TUser - */ - public function getUser() { - return $this->user; - } - - /** - * @return TGroup - */ - public function getGroup() { - return $this->group; - } - - /** - * @return Entity[] - */ - public function getUsers() { - return $this->user->findAll(); - } - - /** - * @return Entity[] - */ - public function getGroups() { - return $this->group->findAll(); - } - -} + + * + */ + +namespace bfw\core; + +use bfw\entities\TGroup; +use bfw\entities\TUser; +use Logger; + +/** + * Class Model + * + */ +class Model { + + protected $logger; + + /** + * @var TUser + */ + private $user; + + /** + * @var TGroup + */ + private $group; + + public function __construct() { + $this->logger = Logger::getLogger(get_class($this)); + + $this->user = new TUser(); + $this->group = new TGroup(); + } + + /** + * @return TUser + */ + public function getUser() { + return $this->user; + } + + /** + * @return TGroup + */ + public function getGroup() { + return $this->group; + } + + /** + * @return Entity[] + */ + public function getUsers() { + return $this->user->findAll(); + } + + /** + * @return Entity[] + */ + public function getGroups() { + return $this->group->findAll(); + } + +} diff --git a/classes/bfw/core/ReadonlyEntity.php b/classes/bfw/core/ReadonlyEntity.php --- a/classes/bfw/core/ReadonlyEntity.php +++ b/classes/bfw/core/ReadonlyEntity.php @@ -1,60 +1,60 @@ - - * - */ - -namespace bfw\core; - -/** - * Class ReadonlyEntity - * - * @method string getId() - */ -class ReadonlyEntity extends Entity { - - /** - * Nur Get-Methoden in dieser Entity - * - * @param $methodName - * @param null $params - * @return mixed - */ - public function __call($methodName, $params = null) { - $prefix = substr($methodName, 0, 3); - - $key = lcfirst(substr($methodName, 3)); - $key = strtolower(preg_replace('/([A-Z])/', "_$1", $key)); - - if ($prefix == 'get') { - if (array_key_exists($key, $this->data)) { - return $this->data[$key]; - } - } - - exit(sprintf('Unbekannte Methode %s(%s, %s) wurde aufgerufen.', $methodName, $key, $prefix)); - } - - /** - * @return bool - */ - public function store() { - return false; - } - - /** - * @return bool - */ - public function delete() { - return false; - } - - /** - * @return bool - */ - public function persist() { - return false; - } - -} + + * + */ + +namespace bfw\core; + +/** + * Class ReadonlyEntity + * + * @method string getId() + */ +class ReadonlyEntity extends Entity { + + /** + * Nur Get-Methoden in dieser Entity + * + * @param $methodName + * @param null $params + * @return mixed + */ + public function __call($methodName, $params = null) { + $prefix = substr($methodName, 0, 3); + + $key = lcfirst(substr($methodName, 3)); + $key = strtolower(preg_replace('/([A-Z])/', "_$1", $key)); + + if ($prefix == 'get') { + if (array_key_exists($key, $this->data)) { + return $this->data[$key]; + } + } + + exit(sprintf('Unbekannte Methode %s(%s, %s) wurde aufgerufen.', $methodName, $key, $prefix)); + } + + /** + * @return bool + */ + public function store() { + return false; + } + + /** + * @return bool + */ + public function delete() { + return false; + } + + /** + * @return bool + */ + public function persist() { + return false; + } + +} diff --git a/classes/bfw/core/View.php b/classes/bfw/core/View.php --- a/classes/bfw/core/View.php +++ b/classes/bfw/core/View.php @@ -1,139 +1,139 @@ - - * - */ - -namespace bfw\core; - -use Smarty; - -require_once 'library/smarty/libs/Smarty.class.php'; - -/** - * Class View - */ -class View { - - /** - * Statische Referenz auf die reale Template Engine, hier Smarty - * - * @var Smarty - */ - private static $tpl = null; - - /** - * @var Model - */ - private $model; - - /** - * @var Controller - */ - private $controller; - - /** - * View constructor. - * - * @param Controller $controller - * @param Model $model - */ - public function __construct(Controller $controller, Model $model) { - $this->controller = $controller; - $this->model = $model; - - self::$tpl = self::getTemplateEngine(); - - $request = $controller->getRequest(); - $this->assign('controller', $request->get('controller', 'home')); - $this->assign('action', $request->get('action', 'index')); - } - - /** - * Liefert ein statisches Handle auf die aktuelle Template Engine zurück - * - * Das Singleton Pattern garantiert genau eine Instanz der Template Engine im Speicher. - * - * Verschiedene Skripte können so nacheinander Variablen zuweisen und diese bei Bedarf auslesen - * - * @return Smarty - */ - private static function getTemplateEngine() { - if (self::$tpl == null) { - self::$tpl = new Smarty(); - - $tpl = self::$tpl; - - $tpl->setCompileDir('./data/templates_c/'); - $tpl->setTemplateDir('./classes/bfw/mvc/view/'); - } - - return self::$tpl; - } - - /** - * @param $template - * @return string - */ - public function fetch($template) { - return self::$tpl->fetch($template); - } - - /** - * Anzeige der komplett gerenderten Seite mit dem Layout $layout - * - * @param string $layout - * @return int - */ - public function display($layout = 'layout.tpl') { - $request = $this->controller->getRequest(); - - $controller = $this->controller; - - $response = $controller->getResponse(); - $this->assign('response', $response); - - $this->assign('request', $request); - - $model = $controller->getModel(); - $user = $model->getUser(); - $group = $model->getGroup(); - - if ($request->getKey('isLoggedIn')) { - $user->find($request->getKey('user_id')); - } - - $this->assign('user', $user); - $this->assign('group', $group); - - try { - self::$tpl->display($layout); - } catch (SmartyException $se) { - $response->setStatusCode(404); - - self::$tpl->display('layout.tpl'); - } - - // Msg wieder auf Null setzen... - $request->setKey('msg', ''); - - // Fehler wieder auf Null setzen... - $request->setKey('error', ''); - - return http_response_code(); - } - - public function assign($key, $value) { - self::$tpl->assign($key, $value); - } - - /** - * @param string $key - * @return string - */ - public function get($key) { - return self::$tpl->getTemplateVars($key); - } - -} + + * + */ + +namespace bfw\core; + +use Smarty; + +require_once 'library/smarty/libs/Smarty.class.php'; + +/** + * Class View + */ +class View { + + /** + * Statische Referenz auf die reale Template Engine, hier Smarty + * + * @var Smarty + */ + private static $tpl = null; + + /** + * @var Model + */ + private $model; + + /** + * @var Controller + */ + private $controller; + + /** + * View constructor. + * + * @param Controller $controller + * @param Model $model + */ + public function __construct(Controller $controller, Model $model) { + $this->controller = $controller; + $this->model = $model; + + self::$tpl = self::getTemplateEngine(); + + $request = $controller->getRequest(); + $this->assign('controller', $request->get('controller', 'home')); + $this->assign('action', $request->get('action', 'index')); + } + + /** + * Liefert ein statisches Handle auf die aktuelle Template Engine zurück + * + * Das Singleton Pattern garantiert genau eine Instanz der Template Engine im Speicher. + * + * Verschiedene Skripte können so nacheinander Variablen zuweisen und diese bei Bedarf auslesen + * + * @return Smarty + */ + private static function getTemplateEngine() { + if (self::$tpl == null) { + self::$tpl = new Smarty(); + + $tpl = self::$tpl; + + $tpl->setCompileDir('./data/templates_c/'); + $tpl->setTemplateDir('./classes/bfw/mvc/view/'); + } + + return self::$tpl; + } + + /** + * @param $template + * @return string + */ + public function fetch($template) { + return self::$tpl->fetch($template); + } + + /** + * Anzeige der komplett gerenderten Seite mit dem Layout $layout + * + * @param string $layout + * @return int + */ + public function display($layout = 'layout.tpl') { + $request = $this->controller->getRequest(); + + $controller = $this->controller; + + $response = $controller->getResponse(); + $this->assign('response', $response); + + $this->assign('request', $request); + + $model = $controller->getModel(); + $user = $model->getUser(); + $group = $model->getGroup(); + + if ($request->getKey('isLoggedIn')) { + $user->find($request->getKey('user_id')); + } + + $this->assign('user', $user); + $this->assign('group', $group); + + try { + self::$tpl->display($layout); + } catch (SmartyException $se) { + $response->setStatusCode(404); + + self::$tpl->display('layout.tpl'); + } + + // Msg wieder auf Null setzen... + $request->setKey('msg', ''); + + // Fehler wieder auf Null setzen... + $request->setKey('error', ''); + + return http_response_code(); + } + + public function assign($key, $value) { + self::$tpl->assign($key, $value); + } + + /** + * @param string $key + * @return string + */ + public function get($key) { + return self::$tpl->getTemplateVars($key); + } + +} diff --git a/classes/bfw/database/DBInterface.php b/classes/bfw/database/DBInterface.php --- a/classes/bfw/database/DBInterface.php +++ b/classes/bfw/database/DBInterface.php @@ -1,45 +1,45 @@ - - * - */ - -namespace bfw\database; - -/** - * Interface DBInterface - */ -interface DBInterface { - /* fetch methods */ - - public function fetch($table, $cond); - - public function fetchAll($table, $cond); - - /* find methoden */ - - public function find($table, $id); - - public function findAll($table, $initial_id); - - public function findByField($table, $field, $value); - - function findAllByField($table, $field, $value); - - /* Abfrage Methoden */ - - public function query($sql); - - /* Persistence Methods */ - - public function persist($table, $array); - - public function store($table, $id, $array); - - public function delete($table, $id); - - /* PK Management */ - - public function getLastInsertedId(); -} + + * + */ + +namespace bfw\database; + +/** + * Interface DBInterface + */ +interface DBInterface { + /* fetch methods */ + + public function fetch($table, $cond); + + public function fetchAll($table, $cond); + + /* find methoden */ + + public function find($table, $id); + + public function findAll($table, $initial_id); + + public function findByField($table, $field, $value); + + function findAllByField($table, $field, $value); + + /* Abfrage Methoden */ + + public function query($sql); + + /* Persistence Methods */ + + public function persist($table, $array); + + public function store($table, $id, $array); + + public function delete($table, $id); + + /* PK Management */ + + public function getLastInsertedId(); +} diff --git a/classes/bfw/mvc/controller/BenutzerverwaltungController.php b/classes/bfw/mvc/controller/BenutzerverwaltungController.php --- a/classes/bfw/mvc/controller/BenutzerverwaltungController.php +++ b/classes/bfw/mvc/controller/BenutzerverwaltungController.php @@ -1,141 +1,141 @@ - - * - */ - -namespace bfw\mvc\controller; - -use bfw\core\Controller; -use bfw\Dispatcher; -use bfw\entities\TGroup; - -/** - * Class BenutzerverwaltungsController - */ -class BenutzerverwaltungController extends Controller { - - /** - * BenutzerverwaltungsController constructor. - * - */ - public function __construct() { - parent::__construct(); - } - - /** - * - */ - public function meinProfil() { - $request = $this->getRequest(); - - $model = $this->getModel(); - if ($request->hasPost()) { - $input = array( - "username" => $request->session('username', ''), - 'password' => md5($request->session('password', '')), - 'firstname' => $request->session('firstname', ''), - 'lastname' => $request->session('lastname', ''), - ); - - $user = $model->getUser(); - $user->find($request->getKey('user_id')); - - $user->merge($input); - if (!$user->store()) { - $request->setKey('error', 'Fehler beim Aktualisieren des Benutzers.'); - } else { - $request->setKey('msg', 'Die Daten wurden aktualisiert.'); - } - } - - $view = $this->getView(); - $view->display(); - } - - /** - * - */ - public function abmelden() { - $request = $this->getRequest(); - - $request->destroySession(); - $request->initSession(); - - Dispatcher::route('/'); - } - - /** - * - */ - public function anmelden() { - $request = $this->getRequest(); - $view = $this->getView(); - - $this->getView()->display(); - - if (!$request->hasPost()) { - // nothing to do! - return; - } - - $model = $this->getModel()->getUser(); - - $username = $request->post('username'); - $password = $request->post('password'); - - $lastpage = $request->getKey('lastpage'); - - $model->findByUsername($username); - - if ($model->getPassword() == md5($password)) { - $request->setKey('user_id', $model->getId()); - $request->setKey('group_id', $model->getGroupId()); - - $request->setKey('isLoggedIn', true); - - Dispatcher::route(sprintf('/%s/', $lastpage)); - } - } - - /** - * - */ - public function registrieren() { - $request = $this->getRequest(); - $view = $this->getView(); - - $model = $this->getModel(); - - $view->assign('currentUser', $model->getUser()); - - $this->getView()->display(); - } - - public function index() { - $request = $this->getRequest(); - $view = $this->getView(); - - $model = $this->getModel(); - - $group_id = $request->getKey('group_id'); - - /** - * Hier muss eine ACL-Schicht dazu - * - */ - if ($group_id != TGroup::ADMIN) { - Dispatcher::route('/'); - } - - $users = $model->getUsers(); - $groups = $model->getGroups(); - - $view->assign('users', $users); - $view->assign('groups', $groups); - - $this->getView()->display(); - } - -} + + * + */ + +namespace bfw\mvc\controller; + +use bfw\core\Controller; +use bfw\Dispatcher; +use bfw\entities\TGroup; + +/** + * Class BenutzerverwaltungsController + */ +class BenutzerverwaltungController extends Controller { + + /** + * BenutzerverwaltungsController constructor. + * + */ + public function __construct() { + parent::__construct(); + } + + /** + * + */ + public function meinProfil() { + $request = $this->getRequest(); + + $model = $this->getModel(); + if ($request->hasPost()) { + $input = array( + "username" => $request->session('username', ''), + 'password' => md5($request->session('password', '')), + 'firstname' => $request->session('firstname', ''), + 'lastname' => $request->session('lastname', ''), + ); + + $user = $model->getUser(); + $user->find($request->getKey('user_id')); + + $user->merge($input); + if (!$user->store()) { + $request->setKey('error', 'Fehler beim Aktualisieren des Benutzers.'); + } else { + $request->setKey('msg', 'Die Daten wurden aktualisiert.'); + } + } + + $view = $this->getView(); + $view->display(); + } + + /** + * + */ + public function abmelden() { + $request = $this->getRequest(); + + $request->destroySession(); + $request->initSession(); + + Dispatcher::route('/'); + } + + /** + * + */ + public function anmelden() { + $request = $this->getRequest(); + $view = $this->getView(); + + $this->getView()->display(); + + if (!$request->hasPost()) { + // nothing to do! + return; + } + + $model = $this->getModel()->getUser(); + + $username = $request->post('username'); + $password = $request->post('password'); + + $lastpage = $request->getKey('lastpage'); + + $model->findByUsername($username); + + if ($model->getPassword() == md5($password)) { + $request->setKey('user_id', $model->getId()); + $request->setKey('group_id', $model->getGroupId()); + + $request->setKey('isLoggedIn', true); + + Dispatcher::route(sprintf('/%s/', $lastpage)); + } + } + + /** + * + */ + public function registrieren() { + $request = $this->getRequest(); + $view = $this->getView(); + + $model = $this->getModel(); + + $view->assign('currentUser', $model->getUser()); + + $this->getView()->display(); + } + + public function index() { + $request = $this->getRequest(); + $view = $this->getView(); + + $model = $this->getModel(); + + $group_id = $request->getKey('group_id'); + + /** + * Hier muss eine ACL-Schicht dazu + * + */ + if ($group_id != TGroup::ADMIN) { + Dispatcher::route('/'); + } + + $users = $model->getUsers(); + $groups = $model->getGroups(); + + $view->assign('users', $users); + $view->assign('groups', $groups); + + $this->getView()->display(); + } + +} diff --git a/classes/bfw/mvc/controller/DokumentationController.php b/classes/bfw/mvc/controller/DokumentationController.php --- a/classes/bfw/mvc/controller/DokumentationController.php +++ b/classes/bfw/mvc/controller/DokumentationController.php @@ -1,30 +1,30 @@ - - * - */ - -namespace bfw\mvc\controller; - -use bfw\core\Controller; - -/** - * Class DokumentationController - * @package bfw\mvc\controller - */ -class DokumentationController extends Controller { - - public function __construct() { - parent::__construct(); - } - - public function index() { - $request = $this->getRequest(); - $view = $this->getView(); - $model = $this->getModel(); - - $this->getView()->display(); - } - -} + + * + */ + +namespace bfw\mvc\controller; + +use bfw\core\Controller; + +/** + * Class DokumentationController + * @package bfw\mvc\controller + */ +class DokumentationController extends Controller { + + public function __construct() { + parent::__construct(); + } + + public function index() { + $request = $this->getRequest(); + $view = $this->getView(); + $model = $this->getModel(); + + $this->getView()->display(); + } + +} diff --git a/classes/bfw/mvc/controller/ErrorController.php b/classes/bfw/mvc/controller/ErrorController.php --- a/classes/bfw/mvc/controller/ErrorController.php +++ b/classes/bfw/mvc/controller/ErrorController.php @@ -1,30 +1,30 @@ - - * - */ - -namespace bfw\mvc\controller; - -use bfw\core\Controller; - -/** - * Class ErrorController - * - */ -class ErrorController extends Controller { - - public function __construct() { - parent::__construct(); - - $this->getView()->assign('controller', 'error'); - $this->getView()->assign('action', 'index'); - } - - public function index() { - http_response_code(404); - return $this->getView()->display(); - } - -} + + * + */ + +namespace bfw\mvc\controller; + +use bfw\core\Controller; + +/** + * Class ErrorController + * + */ +class ErrorController extends Controller { + + public function __construct() { + parent::__construct(); + + $this->getView()->assign('controller', 'error'); + $this->getView()->assign('action', 'index'); + } + + public function index() { + http_response_code(404); + return $this->getView()->display(); + } + +} diff --git a/classes/bfw/mvc/controller/HomeController.php b/classes/bfw/mvc/controller/HomeController.php --- a/classes/bfw/mvc/controller/HomeController.php +++ b/classes/bfw/mvc/controller/HomeController.php @@ -1,33 +1,33 @@ - - * - */ - -namespace bfw\mvc\controller; - -use bfw\core\Controller; - -/** - * Class HomeController - */ -class HomeController extends Controller { - - /** - * HomeController constructor. - * - */ - public function __construct() { - parent::__construct(); - } - - /** - * Default Index Action - * - */ - public function index() { - $this->getView()->display(); - } - -} + + * + */ + +namespace bfw\mvc\controller; + +use bfw\core\Controller; + +/** + * Class HomeController + */ +class HomeController extends Controller { + + /** + * HomeController constructor. + * + */ + public function __construct() { + parent::__construct(); + } + + /** + * Default Index Action + * + */ + public function index() { + $this->getView()->display(); + } + +} diff --git a/classes/bfw/mvc/model/benutzerverwaltung/DataModel.php b/classes/bfw/mvc/model/benutzerverwaltung/DataModel.php --- a/classes/bfw/mvc/model/benutzerverwaltung/DataModel.php +++ b/classes/bfw/mvc/model/benutzerverwaltung/DataModel.php @@ -1,17 +1,17 @@ - - * - */ - -namespace bfw\mvc\model\benutzerverwaltung; - -use bfw\core\Model; - -/** - * Class DataModel - */ -class DataModel extends Model { - -} + + * + */ + +namespace bfw\mvc\model\benutzerverwaltung; + +use bfw\core\Model; + +/** + * Class DataModel + */ +class DataModel extends Model { + +} diff --git a/classes/bfw/mvc/model/dokumentation/DataModel.php b/classes/bfw/mvc/model/dokumentation/DataModel.php --- a/classes/bfw/mvc/model/dokumentation/DataModel.php +++ b/classes/bfw/mvc/model/dokumentation/DataModel.php @@ -1,17 +1,17 @@ - - * - */ - -namespace bfw\mvc\model\dokumentation; - -use bfw\core\Model; - -/** - * Class DataModel - */ -class DataModel extends Model { - -} + + * + */ + +namespace bfw\mvc\model\dokumentation; + +use bfw\core\Model; + +/** + * Class DataModel + */ +class DataModel extends Model { + +} diff --git a/classes/bfw/mvc/model/error/DataModel.php b/classes/bfw/mvc/model/error/DataModel.php --- a/classes/bfw/mvc/model/error/DataModel.php +++ b/classes/bfw/mvc/model/error/DataModel.php @@ -1,17 +1,17 @@ - - * - */ - -namespace bfw\mvc\model\error; - -use bfw\core\Model; - -/** - * Class DataModel - */ -class DataModel extends Model { - -} + + * + */ + +namespace bfw\mvc\model\error; + +use bfw\core\Model; + +/** + * Class DataModel + */ +class DataModel extends Model { + +} diff --git a/classes/bfw/mvc/model/home/DataModel.php b/classes/bfw/mvc/model/home/DataModel.php --- a/classes/bfw/mvc/model/home/DataModel.php +++ b/classes/bfw/mvc/model/home/DataModel.php @@ -1,17 +1,17 @@ - - * - */ - -namespace bfw\mvc\model\home; - -use bfw\core\Model; - -/** - * Class DataModel - */ -class DataModel extends Model { - -} + + * + */ + +namespace bfw\mvc\model\home; + +use bfw\core\Model; + +/** + * Class DataModel + */ +class DataModel extends Model { + +} diff --git a/config/config.php b/config/config.php --- a/config/config.php +++ b/config/config.php @@ -1,16 +1,16 @@ - - */ - -use bfw\Dispatcher; - -require_once 'config/config.php'; - -$dispatcher = new Dispatcher(); -return $dispatcher->delegate(); \ No newline at end of file + + */ +use bfw\Dispatcher; + +require_once 'config/config.php'; + +$dispatcher = new Dispatcher(); +return $dispatcher->delegate(); diff --git a/patches/Test.php b/patches/Test.php --- a/patches/Test.php +++ b/patches/Test.php @@ -1,12 +1,12 @@ -findAll(); - -foreach ($users as $user) { - printf("Benutzer: %s %s", $user->getFirstname(), $user->getUsername()); +findAll(); + +foreach ($users as $user) { + printf("Benutzer: %s %s", $user->getFirstname(), $user->getUsername()); } \ No newline at end of file diff --git a/setup/index.php b/setup/index.php --- a/setup/index.php +++ b/setup/index.php @@ -1,52 +1,52 @@ - 'mysql:host=localhost;', - 'config' => array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'), - 'username' => 'root', - 'password' => '', -); - -require_once '../config/config.php'; - -use bfw\database\Database; - -$db = Database::getInstance($cfg); - -$dropSQLStatements = array( - "DROP USER 'bfw'@'localhost'", - "DROP DATABASE IF EXISTS bfw;", -); - -$createSQLStatements = array( - "CREATE DATABASE bfw CHARACTER SET utf8 COLLATE utf8_unicode_ci;", - "CREATE USER 'bfw'@'localhost' IDENTIFIED BY 'bfw';", - "GRANT ALL PRIVILEGES ON bfw.* TO 'bfw'@'localhost' WITH GRANT OPTION;", -); - -foreach ($dropSQLStatements as $statement) { - $status = $db->execute($statement); - echo sprintf("%s\n", $statement); -} - -foreach ($createSQLStatements as $statement) { - $status = $db->execute($statement); - echo sprintf("%s\n", $statement); -} - -$handle = fopen(BFW_PATH . '/sql/init.sql', 'r'); - -$sql = "USE bfw;\n\n"; -while (!feof($handle)) { - $sql .= fgets($handle); -} - -fclose($handle); - -if ($db->execute($sql) == 0) { - echo sprintf("%s", $sql); - - header('Location: /'); -} + 'mysql:host=localhost;', + 'config' => array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'), + 'username' => 'root', + 'password' => '', +); + +require_once '../config/config.php'; + +use bfw\database\Database; + +$db = Database::getInstance($cfg); + +$dropSQLStatements = array( + "DROP USER 'bfw'@'localhost'", + "DROP DATABASE IF EXISTS bfw;", +); + +$createSQLStatements = array( + "CREATE DATABASE bfw CHARACTER SET utf8 COLLATE utf8_unicode_ci;", + "CREATE USER 'bfw'@'localhost' IDENTIFIED BY 'bfw';", + "GRANT ALL PRIVILEGES ON bfw.* TO 'bfw'@'localhost' WITH GRANT OPTION;", +); + +foreach ($dropSQLStatements as $statement) { + $status = $db->execute($statement); + echo sprintf("%s\n", $statement); +} + +foreach ($createSQLStatements as $statement) { + $status = $db->execute($statement); + echo sprintf("%s\n", $statement); +} + +$handle = fopen(BFW_PATH . '/sql/init.sql', 'r'); + +$sql = "USE bfw;\n\n"; +while (!feof($handle)) { + $sql .= fgets($handle); +} + +fclose($handle); + +if ($db->execute($sql) == 0) { + echo sprintf("%s", $sql); + + header('Location: /'); +} diff --git a/tests/bfw/DatabaseTest.php b/tests/bfw/DatabaseTest.php --- a/tests/bfw/DatabaseTest.php +++ b/tests/bfw/DatabaseTest.php @@ -1,52 +1,52 @@ -object = Database::getInstance(); - } - - public function testStore() { - $data = array(); - $data['password'] = md5(rand(0, 255)); - - $result = $this->object->store('t_user', 1, $data); - $this->assertTrue($result !== false); - } - - public function testFetch() { - $data = $this->object->fetch('t_user', 'id = 1'); - - $this->assertEquals('system@testbox.de', $data['username']); - } - - public function testFetchAll() { - $data = $this->object->fetchAll('t_user', 'id < 3'); - - $this->assertTrue(is_array($data)); - - foreach ($data as $row) { - echo sprintf("%s\n", implode(', ', $row)); - } - } - - public function testFind() { - $data = $this->object->find('t_user', -1); - $this->assertEquals(null, $data); - - $data = $this->object->find('t_user', 1); - $this->assertEquals(1, $data['id']); - } - - public function testFindAll() { - $data1 = $this->object->findAll('t_user'); - $data2 = $this->object->findAll('t_user', 5); - - $this->assertTrue(count($data1) != count($data2)); - } -} +object = Database::getInstance(); + } + + public function testStore() { + $data = array(); + $data['password'] = md5(rand(0, 255)); + + $result = $this->object->store('t_user', 1, $data); + $this->assertTrue($result !== false); + } + + public function testFetch() { + $data = $this->object->fetch('t_user', 'id = 1'); + + $this->assertEquals('system@testbox.de', $data['username']); + } + + public function testFetchAll() { + $data = $this->object->fetchAll('t_user', 'id < 3'); + + $this->assertTrue(is_array($data)); + + foreach ($data as $row) { + echo sprintf("%s\n", implode(', ', $row)); + } + } + + public function testFind() { + $data = $this->object->find('t_user', -1); + $this->assertEquals(null, $data); + + $data = $this->object->find('t_user', 1); + $this->assertEquals(1, $data['id']); + } + + public function testFindAll() { + $data1 = $this->object->findAll('t_user'); + $data2 = $this->object->findAll('t_user', 5); + + $this->assertTrue(count($data1) != count($data2)); + } +}