Store.php 18.2 KB
Newer Older
1
2
3
4
5
6
7
8
<?php
/**
 * Created by PhpStorm.
 * User: crose
 * Date: 1/1/16
 * Time: 6:51 PM
 */

9
namespace qfq;
10

11
use qfq\CodeException;
12
13
use qfq\keyValueStringParser;
use qfq\OnArray;
14
use qfq;
15

16
require_once(__DIR__ . '/../../qfq/helper/KeyValueStringParser.php');
Carsten  Rose's avatar
Carsten Rose committed
17
require_once(__DIR__ . '/../../qfq/helper/Sanitize.php');
18
require_once(__DIR__ . '/../../qfq/Constants.php');
19
require_once(__DIR__ . '/../../qfq/store/Sip.php');
20
require_once(__DIR__ . '/../../qfq/Database.php');
21
22
23
24
25
26
27
28
29
30
31


/*
 * Stores:
 * - SIP
 * - webVar
 * - record
 * - form
 * - formElement
 */

Carsten  Rose's avatar
Carsten Rose committed
32
33
/**
 * Class Store
34
 * @package qfq
Carsten  Rose's avatar
Carsten Rose committed
35
 */
36
37
class Store {

Carsten  Rose's avatar
Carsten Rose committed
38
39
40
    /**
     * @var Store Instance of class Store. There should only be one class 'Store' at a time.
     */
41
42
    private static $instance = null;

Carsten  Rose's avatar
Carsten Rose committed
43
44
45
    /**
     * @var Sip Instance of class SIP
     */
46
47
    private static $sip = null;

Carsten  Rose's avatar
Carsten Rose committed
48
49
50
51
52
53
54
55
56
57
    /**
     * @var array Stores all indiviudal stores with the variable raw values
     *
     * $raw['D']['id'] = 0  - Defaultvalues from Tabledefinition
     * ...
     * $raw['S']['r'] = 1234 - record ID from current SIP identifier
     * ...
     * $raw['C']['HTTP_SERVER'] = 'qfq' - Servername
     * $raw['C']['s'] = 'badcaffee1234' - recent SIP
     */
58
    private static $raw = array();
Carsten  Rose's avatar
Carsten Rose committed
59
60

    /**
Carsten  Rose's avatar
Carsten Rose committed
61
     * @var array Default sanitize classes.
Carsten  Rose's avatar
Carsten Rose committed
62
     */
Carsten  Rose's avatar
Carsten Rose committed
63
    private static $sanitizeClass = array();
Carsten  Rose's avatar
Carsten Rose committed
64
65

    /**
Carsten  Rose's avatar
Carsten Rose committed
66
67
     * $sanitizeClass['S'] = false
     * $sanitizeClass['C'] = true
Carsten  Rose's avatar
Carsten Rose committed
68
69
     * ...
     *
Carsten  Rose's avatar
Carsten Rose committed
70
     * @var array each entry with true/false - depending if store needs to be sanitized.
Carsten  Rose's avatar
Carsten Rose committed
71
     */
Carsten  Rose's avatar
Carsten Rose committed
72
    private static $sanitizeStore = array();
73

Carsten  Rose's avatar
Carsten Rose committed
74
    private static $phpUnit = false;
75

76
    /**
77
     * @param string $bodytext
78
     */
79
    private function __construct($bodytext = '') {
80

Carsten  Rose's avatar
Carsten Rose committed
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
        self::$sanitizeClass = [
//            TYPO3_DEBUG_LOAD => SANITIZE_ALLOW_DIGIT,
//            TYPO3_DEBUG_SAVE => SANITIZE_ALLOW_DIGIT,
//            TYPO3_FORM => SANITIZE_ALLOW_ALNUMX,
//            TYPO3_FE_USER => SANITIZE_ALLOW_ALNUMX,
//            TYPO3_FE_USER_UID => SANITIZE_ALLOW_DIGIT,
//            TYPO3_FE_USER_GROUP => SANITIZE_ALLOW_ALNUMX,

            CLIENT_SIP => SANITIZE_ALLOW_ALNUMX,
            CLIENT_RECORD_ID => SANITIZE_ALLOW_DIGIT,
            CLIENT_KEY_SEM_ID => SANITIZE_ALLOW_DIGIT,
            CLIENT_KEY_SEM_ID_USER => SANITIZE_ALLOW_DIGIT,
            CLIENT_PAGE_ID => SANITIZE_ALLOW_DIGIT,
            CLIENT_PAGE_TYPE => SANITIZE_ALLOW_DIGIT,
            CLIENT_PAGE_LANGUAGE => SANITIZE_ALLOW_DIGIT,
            CLIENT_FORM => SANITIZE_ALLOW_ALNUMX,

            // Part of $_SERVER. Missing vars must be requested individual with the needed sanitize class.
            CLIENT_SCRIPT_URL => SANITIZE_ALLOW_ALNUMX,
            CLIENT_SCRIPT_URI => SANITIZE_ALLOW_ALNUMX,
            CLIENT_HTTP_HOST => SANITIZE_ALLOW_ALNUMX,
            CLIENT_HTTP_USER_AGENT => SANITIZE_ALLOW_ALNUMX,
            CLIENT_SERVER_NAME => SANITIZE_ALLOW_ALNUMX,
            CLIENT_SERVER_ADDRESS => SANITIZE_ALLOW_ALNUMX,
            CLIENT_SERVER_PORT => SANITIZE_ALLOW_DIGIT,
            CLIENT_REMOTE_ADDRESS => SANITIZE_ALLOW_ALNUMX,
            CLIENT_REQUEST_SCHEME => SANITIZE_ALLOW_ALNUMX,
            CLIENT_SCRIPT_FILENAME => SANITIZE_ALLOW_ALNUMX,
            CLIENT_QUERY_STRING => SANITIZE_ALLOW_ALL,
            CLIENT_REQUEST_URI => SANITIZE_ALLOW_ALL,
            CLIENT_SCRIPT_NAME => SANITIZE_ALLOW_ALNUMX,
            CLIENT_PHP_SELF => SANITIZE_ALLOW_ALNUMX,

//            SYSTEM_DBUSER => SANITIZE_ALLOW_ALNUMX,
//            SYSTEM_DBSERVER => SANITIZE_ALLOW_ALNUMX,
//            SYSTEM_DBPW => SANITIZE_ALLOW_ALL,
//            SYSTEM_DB => SANITIZE_ALLOW_ALNUMX,
//            SYSTEM_TESTDB => SANITIZE_ALLOW_ALNUMX,
//            SYSTEM_SESSIONNAME => SANITIZE_ALLOW_ALNUMX,
//            SYSTEM_DBH => SANITIZE_ALLOW_ALL,

//            SYSTEM_SQL_RAW => SANITIZE_ALLOW_ALL,
//            SYSTEM_SQL_FINAL => SANITIZE_ALLOW_ALL,
//            SYSTEM_SQL_COUNT => SANITIZE_ALLOW_DIGIT,
//            SYSTEM_SQL_PARAM_ARRAY => SANITIZE_ALLOW_ALL,

//            SIP_SIP => SANITIZE_ALLOW_ALNUMX,
//            SIP_RECORD_ID => SANITIZE_ALLOW_DIGIT,
//            SIP_FORM => SANITIZE_ALLOW_ALNUMX,
//            SIP_URLPARAM => SANITIZE_ALLOW_ALL
131

132
133
        ];

Carsten  Rose's avatar
Carsten Rose committed
134
        self::$sanitizeStore = [
135
136
137
138
            STORE_FORM => true,
            STORE_SIP => false,
            STORE_RECORD => false,
            STORE_PARENT_RECORD => false,
139
140
            STORE_TABLE_DEFAULT => false,
            STORE_TABLE_COLUMN_TYPES => false,
141
142
            STORE_CLIENT => true,
            STORE_TYPO3 => false,
143
            STORE_ZERO => false,
144
145
            STORE_SYSTEM => false,
            STORE_EXTRA => true
146
147
        ];

148
        self::fillSystemStore();
149
        self::fillStoreTypo3($bodytext);
150
        self::fillStoreClient();
151
        self::fillStoreSip();
Carsten  Rose's avatar
Carsten Rose committed
152
        self::fillStoreExtra();
153
    }
154

155
156
    /**
     * @throws CodeException
157
     * @throws qfq\UserFormException
158
     */
159
    private static function fillSystemStore() {
160
        try {
161
162
            //TODO: Vernuenftige Fehlermeldung falls nicht auf qfq.ini zugegriffen werden kann.
            //TODO: sinnvollen Platz fuer qfq.ini bestimmen. In der Installationsdoku erwaehnen.
163
            $config = parse_ini_file(__DIR__ . '/../../../' . CONFIG_INI, false);
164

165
166
            //TODO: auskommentiert weil dann die Unittests nicht mehr laufen. Sollte eigentlich wieder aktiviert werden.
//            $config['SQLLOG'] = Support::ifRelativePathPrependExtensionPath($config['SQLLOG']);
167

168
        } catch (\Exception $e) {
169
            throw new qfq\UserFormException ("Error read file " . CONFIG_INI . ": " . $e->getMessage(), ERROR_IO_READ_FILE);
170
        }
171

172
        // Adjust config
173
        if (!isset($config['SHOW_DEBUG_INFO']) || $config['SHOW_DEBUG_INFO'] === 'auto') {
174
175
176
            $config['SHOW_DEBUG_INFO'] = (isset($GLOBALS["TSFE"]->beUserLogin) && $GLOBALS["TSFE"]->beUserLogin === true) ? 'yes' : 'no';
        }

177
178
179
180
181
182
183
        // SYSTEM_PATH_EXT: compute only if not already defined.
        if (!isset($config[SYSTEM_PATH_EXT]) || $config[SYSTEM_PATH_EXT] === '' || $config[SYSTEM_PATH_EXT][0] !== '/') {
            $relExtDir = '/typo3conf/ext/' . EXT_KEY;

            // If we are called through AJAX API (e.g. api/save.php), there is no TYPO3 environment.
            if (isset($_SERVER['SCRIPT_FILENAME'])) {
                $pos = strpos($_SERVER['SCRIPT_FILENAME'], $relExtDir);
184
185
                if ($pos === false && isset($GLOBALS['TYPO3_LOADED_EXT'][EXT_KEY]['ext_localconf.php'])) {

186
187
188
189
190
191
192
193
                    // probably: index.php - THERE should be a TYPO3 environment.
                    $config[SYSTEM_PATH_EXT] = dirname($GLOBALS['TYPO3_LOADED_EXT'][EXT_KEY]['ext_localconf.php']);
                } else {
                    $config[SYSTEM_PATH_EXT] = substr($_SERVER['SCRIPT_FILENAME'], 0, $pos + strlen($relExtDir));
                }
            }
        }

194
195
196
        // Defaults
        Support::setIfNotSet($config, SYSTEM_DATE_FORMAT, 'yyyy-mm-dd');

197
198
199
200
201
202
        // make SQL PATH absolute. This is necessary to work in different directories correctly.
        if (isset($config[SYSTEM_SQL_LOG]) && $config[SYSTEM_SQL_LOG][0] !== '/') {
            $config[SYSTEM_SQL_LOG] = $config[SYSTEM_PATH_EXT] . '/' . $config[SYSTEM_SQL_LOG];
        }


203
        self::setVarArray($config, STORE_SYSTEM, true);
204
205
    }

206
207
208
    /**
     * @param array $dataArray
     * @param $store
209
     * @param bool|false $flagOverwrite
210
     * @throws UserFormException
211
     * @throws \qfq\CodeException
212
     */
213
    public static function setVarArray(array $dataArray, $store, $flagOverwrite = false) {
Carsten  Rose's avatar
Carsten Rose committed
214
        // Check valid Storename
Carsten  Rose's avatar
Carsten Rose committed
215
        if (!isset(self::$sanitizeStore))
216
            throw new UserFormException("Unknown Store: $store", ERROR_UNNOWN_STORE);
Carsten  Rose's avatar
Carsten Rose committed
217
218


219
        if ($store === STORE_ZERO)
Carsten  Rose's avatar
Carsten Rose committed
220
            throw new CodeException("setVarArray() for STORE_ZERO is impossible - there are no values.", ERROR_SET_STORE_ZERO);
221

Carsten  Rose's avatar
Carsten Rose committed
222
        if (!$flagOverwrite && isset(self::$raw[$store]) && count(self::$raw[$store]) > 0) {
223
            throw new CodeException("Raw values already been copied to store '$store'. Do this only one time.", ERROR_STORE_VALUE_ALREADY_CODPIED);
224
        }
225

226
227
        self::$raw[$store] = $dataArray;
    }
228

229
230
231
232
    /**
     * @param $bodytext
     * @throws CodeException
     */
233
    private static function fillStoreTypo3($bodytext) {
234

235
        $arr = KeyValueStringParser::parse($bodytext, "=", "\n");
236
237
238
239
240
241
242
243
244

        if (isset($GLOBALS["TSFE"]->fe_user->user["username"]))
            $arr[TYPO3_FE_USER] = $GLOBALS["TSFE"]->fe_user->user["username"];

        if (isset($GLOBALS["TSFE"]->fe_user->user["uid"]))
            $arr[TYPO3_FE_USER_UID] = $GLOBALS["TSFE"]->fe_user->user["uid"];

        if (isset($GLOBALS["TSFE"]->fe_user->user["usergroup"]))
            $arr[TYPO3_FE_USER_GROUP] = $GLOBALS["TSFE"]->fe_user->user["usergroup"];
245

Carsten  Rose's avatar
Carsten Rose committed
246
247
248
        if (isset($GLOBALS["TSFE"]->page["uid"]))
            $arr[TYPO3_TT_CONTENT_UID] = $GLOBALS["TSFE"]->page["uid"];

249
250
251
        if (isset($GLOBALS["TSFE"]->id))
            $arr[TYPO3_PAGE_ID] = $GLOBALS["TSFE"]->id;

Carsten  Rose's avatar
Carsten Rose committed
252
253
254
        if (isset($GLOBALS["TSFE"]->type))
            $arr[TYPO3_PAGE_TYPE] = $GLOBALS["TSFE"]->type;

255
256
257
        if (isset($GLOBALS["TSFE"]->sys_language_uid))
            $arr[TYPO3_PAGE_LANGUAGE] = $GLOBALS["TSFE"]->sys_language_uid;

258
        self::setVarArray($arr, STORE_TYPO3, true);
259
    }
260

261
262
263
    /**
     * @throws CodeException
     */
264
    private static function fillStoreClient() {
265
        // copy GET and POST and SERVER Parameter. Priority: SERVER, POST, GET
266
267
268
269
270
271
272
273
274
        $arr = array();
        if (isset($_GET))
            $arr = array_merge($arr, $_GET);

        if (isset($_POST))
            $arr = array_merge($arr, $_POST);

        if (isset($_SERVER))
            $arr = array_merge($arr, $_SERVER);
275

276
        self::setVarArray($arr, STORE_CLIENT, true);
277
    }
278

Carsten  Rose's avatar
Carsten Rose committed
279
280
    /**
     * @throws CodeException
281
     * @throws UserFormException
Carsten  Rose's avatar
Carsten Rose committed
282
     */
283
    private static function fillStoreSip() {
Carsten  Rose's avatar
Carsten Rose committed
284

285
        $sessionName = self::getVar(SYSTEM_SESSION_NAME, STORE_SYSTEM);
286
        self::$sip = new Sip($sessionName);
287

288
289
290
291
        $s = self::getVar(CLIENT_SIP, STORE_CLIENT);
        if ($s !== false) {
            // if session is given, copy values to store
            $param = self::$sip->getVarsFromSip($s);
292
293
            $param[SIP_SIP] = $s;
            $param[SIP_URLPARAM] = self::$sip->getQueryStringFromSip($s);
294

295
//            self::setVarArray(KeyValueStringParser::parse($param, "=", "&"), STORE_SIP);
296
            self::setVarArray($param, STORE_SIP, true);
297
298
299
        }
    }

300
    /**
301
     * Cycles through all stores in $useStore.
302
     * First match will return the found value.
Carsten  Rose's avatar
Carsten Rose committed
303
     * During cycling: fill cache with requestet value and sanitize raw value.
304
     *
305
     * @param string $key
306
     * @param string $useStores f.e.: 'FSRD'
Carsten  Rose's avatar
Carsten Rose committed
307
     * @param string $sanitizeClass
Carsten  Rose's avatar
Carsten Rose committed
308
     * @param string $foundInStore Returns the name of the store where $key has been found. If $key is not found, return ''.
309
     * @return string a) if found: value, b) false
Carsten  Rose's avatar
Carsten Rose committed
310
     * @throws \qfq\CodeException
311
     */
Carsten  Rose's avatar
Carsten Rose committed
312
    public static function getVar($key, $useStores = STORE_USE_DEFAULT, $sanitizeClass = '', &$foundInStore = '') {
313
314

        // no store specifed?
315
        if ($useStores === "" || $useStores === null) {
316
            $useStores = STORE_USE_DEFAULT;
317
318
        }

319
        // no sanitizeClass specified: take predefined (if exist) or default.
320
        if ($sanitizeClass === '' || $sanitizeClass === null) {
Carsten  Rose's avatar
Carsten Rose committed
321
            $sanitizeClass = isset(self::$sanitizeClass[$key]) ? self::$sanitizeClass[$key] : SANITIZE_DEFAULT;
322
323
        }

324
325
326
        while ($useStores !== false) {

            $store = substr($useStores, 0, 1); // next store
Carsten  Rose's avatar
Carsten Rose committed
327
            $foundInStore = $store;
328
329
            $useStores = substr($useStores, 1); // shift left remaining stores

330
            if (!isset(self::$raw[$store][$key])) {
331
332
333
                switch ($store) {
                    case STORE_ZERO:
                        return 0;
334
335
                    case STORE_EMPTY:
                        return '';
336
337
                    case STORE_VAR:
                        if ($key === VAR_RANDOM) {
338
                            return Support::randomAlphaNum(RANDOM_LENGTH);
339
340
341
342
343
344
345
                        } else {
                            continue 2;  // no value provided, continue with while loop
                        }
                        break;
                    default:
                        continue 2; // no value provided, continue with while loop
                        break;
Carsten  Rose's avatar
Carsten Rose committed
346
                }
347
348
            }

349
            $rawVal = isset(self::$raw[$store][$key]) ? self::$raw[$store][$key] : null;
Carsten  Rose's avatar
Carsten Rose committed
350
            if (self::$sanitizeStore[$store] && $sanitizeClass != '') {
351
352
353
354
355
                if ($sanitizeClass == SANITIZE_ALLOW_PATTERN || $sanitizeClass == SANITIZE_ALLOW_MIN_MAX || $sanitizeClass == SANITIZE_ALLOW_MIN_MAX_DATE) {
                    // We do not have any pattern or min|max values at this point. For those who be affected, they already checked earlier. So set 'no check'
                    $sanitizeClass = SANITIZE_ALLOW_ALL;
                }
                return \qfq\Sanitize::sanitize($rawVal, $sanitizeClass, '', SANATIZE_EMPTY_STRING);
356
357
            } else {
                return $rawVal;
358
            }
359
        }
Carsten  Rose's avatar
Carsten Rose committed
360
        $foundInStore = '';
361
        return false;
362
    }
363

Carsten  Rose's avatar
Carsten Rose committed
364
365
366
367
368
    /**
     * @throws UserFormException
     * @throws \qfq\CodeException
     */
    private static function fillStoreExtra() {
369

Carsten  Rose's avatar
Carsten Rose committed
370
371
372
373
374
375
        if (isset($_SESSION[STORE_EXTRA]))
            self::setVarArray($_SESSION[STORE_EXTRA], STORE_EXTRA, true);
        else
            self::setVarArray(array(), STORE_EXTRA, true);
    }

376
377
    /**
     * @param string $bodytext
378
     * @param bool|false $phpUnit
379
     * @return null|\qfq\Store
380
     */
381
    public static function getInstance($bodytext = '', $phpUnit = false) {
382

383
        if ($phpUnit) {
384
385
386
387
388
389
390
            if (self::$instance !== null) {

                self::unsetStore(STORE_TYPO3);
                self::fillStoreTypo3($bodytext);

                self::unsetStore(STORE_CLIENT);
                self::fillStoreClient();
391
392
393
394
395
            }
        }

        // Design Pattern: Singleton
        if (self::$instance === null) {
396
397
398
            self::$phpUnit = $phpUnit;

            self::$instance = new self($bodytext);
Carsten  Rose's avatar
Carsten Rose committed
399
400
401
402
        } else {
            // Class Store seems to be presistent over multiple QFQ instantiation. Set bodytext again, with every new request (if bodytext is given).
            if ($bodytext !== '')
                self::fillStoreTypo3($bodytext);
403
404
        }

405
406
407
408
409
410
411
        // Disable TYPO3_DEBUG_SHOW_BODY_TEXT=1 if SYSTEM_SHOW_DEBUG_INFO!='yes'
        if (self::getVar(TYPO3_DEBUG_SHOW_BODY_TEXT, STORE_TYPO3) === '1' &&
            self::getVar(SYSTEM_SHOW_DEBUG_INFO, STORE_SYSTEM) !== 'yes'
        ) {
            self::setVar(TYPO3_DEBUG_SHOW_BODY_TEXT, '0', STORE_TYPO3);
        }

412
        return self::$instance;
413
    }
414

415
416
    /**
     * @param $store
417
418
     * @throws UserFormException
     * @throws \qfq\CodeException
419
420
     */
    public static function unsetStore($store) {
Carsten  Rose's avatar
Carsten Rose committed
421
        // Check valid Storename
Carsten  Rose's avatar
Carsten Rose committed
422
        if (!isset(self::$sanitizeStore))
423
            throw new UserFormException("Unknown Store: $store", ERROR_UNNOWN_STORE);
Carsten  Rose's avatar
Carsten Rose committed
424

425
        if ($store === STORE_ZERO)
Carsten  Rose's avatar
Carsten Rose committed
426
427
            throw new CodeException("unsetStore() for STORE_ZERO is impossible - there are no values.", ERROR_SET_STORE_ZERO);

428
429
430
        if (isset(self::$raw[$store])) {
            self::$raw[$store] = array();
        }
Carsten  Rose's avatar
Carsten Rose committed
431

432
433
    }

434
    /**
Carsten  Rose's avatar
Carsten Rose committed
435
436
437
     * @param string $key
     * @param string|array $value
     * @param string $store
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
     * @param bool|true $overWrite
     * @throws UserFormException
     * @throws \qfq\CodeException
     */
    public static function setVar($key, $value, $store, $overWrite = true) {
        // Check valid Storename
        if (!isset(self::$sanitizeStore))
            throw new UserFormException("Unknown Store: $store", ERROR_UNNOWN_STORE);

        if ($store === STORE_ZERO)
            throw new CodeException("setVar() for STORE_ZERO is impossible - there are no values.", ERROR_SET_STORE_ZERO);

        if ($overWrite === false && isset(self::$raw[$store][$key])) {
            throw new UserFormException("Value of '$key' already be set in store '$store'.", ERROR_STORE_KEY_EXIST);
        }

        self::$raw[$store][$key] = $value;
Carsten  Rose's avatar
Carsten Rose committed
455
456
457

        // The STORE_EXTRA saves arrays and is persistent
        if ($store === STORE_EXTRA) {
458
459

            $_SESSION[STORE_EXTRA][$key] = $value;
Carsten  Rose's avatar
Carsten Rose committed
460
461
        }

462
463
    }

464
465
466
467
    /**
     * @param $formName
     * @throws CodeException
     */
468
    public static function createSipAfterFormLoad($formName) {
469
        $recordId = self::getVar(CLIENT_RECORD_ID, STORE_TYPO3 . STORE_CLIENT);
470
471
472
473
474
475
476
        if ($recordId === false) {
            $recordId = 0;
        }

        $tmpParam = [SIP_RECORD_ID => $recordId, SIP_FORM => $formName];

        // Construct fake urlparam
477
        $tmpUrlparam = OnArray::toString($tmpParam);
478
479

        // Create a fake SIP which has never been passed by URL - further processing might expect this to exist.
480
        $sip = self::getSipInstance()->queryStringToSip($tmpUrlparam, RETURN_SIP);
481
        self::setVar(CLIENT_SIP, $sip, STORE_CLIENT);
482
483
484
485
486

        // Store in SIP Store (cause it's empty until now).
        $tmpParam[SIP_SIP] = $sip;
        self::setVarArray($tmpParam, STORE_SIP);

487
488
489
    }

    /**
490
     * @return null|Sip
491
     */
492
    public static function getSipInstance() {
493
494
        return self::$sip;
    }
495

496
497
    /**
     * @param $store
498
499
500
     * @return array
     * @throws UserFormException
     * @throws \qfq\CodeException
501
502
     */
    public static function getStore($store) {
Carsten  Rose's avatar
Carsten Rose committed
503
        // Check valid Storename
Carsten  Rose's avatar
Carsten Rose committed
504
        if (!isset(self::$sanitizeStore[$store]))
505
            throw new UserFormException("Unknown Store: $store", ERROR_UNNOWN_STORE);
Carsten  Rose's avatar
Carsten Rose committed
506

507
        if ($store === STORE_ZERO)
Carsten  Rose's avatar
Carsten Rose committed
508
509
            throw new CodeException("getStore() for STORE_ZERO is impossible - there are no values saved.", ERROR_GET_STORE_ZERO);

510
511
512
513
514
        if (isset(self::$raw[$store])) {
            return self::$raw[$store];
        }
        return array();
    }
515

Carsten  Rose's avatar
Carsten Rose committed
516

517
    /**
Carsten  Rose's avatar
Carsten Rose committed
518
519
     * Fills STORE_TABLE_DEFAULT and STORE_TABLE_COLUMN_TYPES
     *
520
521
522
     * @param $tableName
     * @throws CodeException
     */
523
    public static function fillStoreTableDefaultColumnType($tableName) {
524
525
526
527
        $db = new qfq\Database();

        $tableDefinition = $db->getTableDefinition($tableName);

Carsten  Rose's avatar
Carsten Rose committed
528
529
        self::setVarArray(array_column($tableDefinition, 'Default', 'Field'), STORE_TABLE_DEFAULT, true);
        self::setVarArray(array_column($tableDefinition, 'Type', 'Field'), STORE_TABLE_COLUMN_TYPES, true);
530
    }
531
532
533
534
535
}