Commit 77c0bd79 authored by Carsten  Rose's avatar Carsten Rose
Browse files

StoreSystem, AbstractStore, Store: New Store implemented

parent b679902c
<?php
/**
* Created by PhpStorm.
* User: crose
* Date: 1/3/16
* Time: 9:09 PM
*/
namespace qfq\store;
class AbstractStore {
private static $instance = null;
// $cache[key]: null: never looked for, false: previous looked for, but not found, else: value
private static $cache = array();
private static $raw = array();
/**
* Design Pattern: Singleton - class should only be instanced internally
*/
private function __construct() {
}
/**
* Design Pattern: Singleton - class should only be instanced once.
*
* @return Store
*/
public static function getInstance() {
// Design Pattern: Singleton
if (self::$instance == null) {
self::$instance = new self;
}
return self::$instance;
}
/**
* @param array $dataArray
*/
public static function setVarArray(array $dataArray) {
if (count(self::$raw) > 0) {
throw new CodeException("Raw value already been copied. Do this only one time.", ERROR_VALUE_ALREADY_CODPIED);
}
self::$raw = $dataArray;
}
/**
* @param array $dataArray
*/
public static function setVar($key, $value) {
if (isset(self::$raw[$key])) {
throw new CodeException("Raw value already been set. Do this only one time.", ERROR_VALUE_ALREADY_CODPIED);
}
self::$raw[$key] = $value;
}
/**
* Get var, sanatize it and store it in cache.
* Further access will be delivered by cache.
* @param string $key
* @param string $sanatizeClass
* @return string a) if not found: false, b) if found but SANATIZE failed: empty string, c) given value
* @throws CodeException
*/
public static function getVar($key, $sanatizeClass = '') {
// Already cached?
if (isset(self::$cache[$key]))
return self::$cache[$key];
// No value? break
if (!isset(self::$raw[$key])) {
self::$cache[$key] = false;
return self::$cache[$key];
}
if ($sanatizeClass === '') {
$sanatizeClass = isset(self::$defaultSanatizeClass[$key]) ? self::$defaultSanatizeClass[$key] : SANATIZE_DEFAULT;
}
// sanatize
self::$cache[$key] = Sanatize::sanatize(self::$raw[$key], $sanatizeClass);
return self::$cache[$key];
}
}
\ No newline at end of file
......@@ -13,8 +13,10 @@ use qfq;
//use qfq\store\StoreT3Bodytext;
require_once(__DIR__ . '/../../qfq/store/AbstractStore.php');
require_once(__DIR__ . '/../../qfq/store/StoreWebVar.php');
require_once(__DIR__ . '/../../qfq/store/StoreT3Bodytext.php');
require_once(__DIR__ . '/../../qfq/store/StoreSystem.php');
require_once(__DIR__ . '/../../qfq/Constants.php');
......@@ -34,7 +36,7 @@ class Store {
// store Classes
public $StoreWebVar = null;
public $StoreT3Bodytext = null;
public $StoreSetup = null;
public $StoreSystem = null;
/**
* Design Pattern: Singleton - class 'store' should only be instanced once.
......@@ -42,13 +44,48 @@ class Store {
private function __construct() {
$this->StoreWebVar = StoreWebVar::getInstance();
$this->StoreT3Bodytext = StoreT3Bodytext::getInstance();
// $this->StoreSetup = StoreSetup::getInstance();
$this->StoreSystem = StoreSystem::getInstance();
try {
$config = parse_ini_file(QFQ_INI, false);
} catch (Exception $e) {
throw new qfq\exceptions\UserException ("Error read file " . QFQ_INI . ": " . $e->getMessage(), ERROR_READ_FILE);
}
$this->StoreSystem->setVarArray($config);
}
public function setVarArray(array $dataArray, $store) {
switch ($store) {
case STORE_CLIENT:
throw new CodeException("setVarArray not implemented for store: $store", ERROR_SETVARARRAY_NOT_IMPLEMENTED);
break;
case STORE_T3_BODYTEXT:
$this->StoreT3Bodytext->setVarArray($dataArray);
break;
case STORE_FORM:
case STORE_SIP:
case STORE_RECORD:
case STORE_TABLE_DEFINITION:
case STORE_ZERO:
throw new CodeException("store not implemented: $store", ERROR_STORE_NOT_IMPLEMENTED);
break;
default:
throw new CodeException("Unknown store: $store", ERROR_UNKNOWN_STORE);
break;
}
}
/**
*
* @return Store
*/
public static function getInstance() {
// Design Pattern: Singleton
if (self::$instance == null) {
self::$instance = new Store;
......@@ -101,32 +138,6 @@ class Store {
}
return false;
}
public function setVarArray(array $dataArray, $store) {
switch ($store) {
case STORE_CLIENT:
throw new CodeException("setVarArray not implemented for store: $store", ERROR_SETVARARRAY_NOT_IMPLEMENTED);
break;
case STORE_T3_BODYTEXT:
$this->StoreT3Bodytext->setVarArray($dataArray);
break;
case STORE_FORM:
case STORE_SIP:
case STORE_RECORD:
case STORE_TABLE_DEFINITION:
case STORE_ZERO:
throw new CodeException("store not implemented: $store", ERROR_STORE_NOT_IMPLEMENTED);
break;
default:
throw new CodeException("Unknown store: $store", ERROR_UNKNOWN_STORE);
break;
}
}
}
......
<?php
/**
* Created by PhpStorm.
* User: crose
* Date: 1/3/16
* Time: 9:20 PM
*/
namespace qfq\store;
class StoreSystem extends AbstractStore {
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment