dbxapp 4.1.3
CMS, Shop, Workflows und modulare Geschäftsanwendungen
Loading...
Searching...
No Matches
dbxTPL_raw_cache_test.php
Go to the documentation of this file.
1<?php
9
10class dbxObj
11{
12}
13
15{
16 public string $baseDir = '';
17
18 public array $system = array(
19 'dbx_lng' => '',
20 'dbx_design' => 'first',
21 'dbx_activ_design' => 'first',
22 'dbx_edit' => 0,
23 );
24
25 public function get_base_dir(): string
26 {
27 if ($this->baseDir !== '') {
28 return $this->baseDir;
29 }
30 return __DIR__ . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'dbxTPL' . DIRECTORY_SEPARATOR;
31 }
32
33 public function get_system_var(string $name, $default = '')
34 {
35 return $this->system[$name] ?? $default;
36 }
37
38 public function get_request_var(string $name, $default = '')
39 {
40 return $default;
41 }
42
43 public function set_system_var(string $name, $value): void
44 {
45 $this->system[$name] = $value;
46 }
47
48 public function get_base_url(): string
49 {
50 return 'https://localhost/dbxapp/';
51 }
52
53 public function get_skin(): string
54 {
55 return 'default';
56 }
57
58 public function get_skin_css(): string
59 {
60 return 'default.css';
61 }
62
63 public function get_skin_class(): string
64 {
65 return 'skin-default';
66 }
67
68 public function editor_file_path(string $path): string
69 {
70 return str_replace('\\', '/', $path);
71 }
72
73 public function os_path(string $path): string
74 {
75 return str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $path);
76 }
77
78 public function register_editor_file(string $kind, string $path): void
79 {
80 }
81}
82
84{
85 static $api;
86 if (!$api) {
88 }
89 return $api;
90}
91
92$_SESSION = array('dbx' => array('cache' => array('tpl' => array())));
93
94require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'dbxTPL.class.php';
95
96$tpl = new dbxTPL();
97$first = $tpl->get_tpl('dbx|test-dbx-runtime-cache', array());
98
99if (trim($first) !== 'first') {
100 fwrite(STDERR, "FAIL: Erster DBX-Systemwert wurde nicht eingesetzt.\n");
101 exit(1);
102}
103
104$cached = $_SESSION['dbx']['cache']['tpl']['dbx']['test-dbx-runtime-cache']['htm']['']['tpl'] ?? '';
105if (strpos($cached, '{dbx:design}') === false) {
106 fwrite(STDERR, "FAIL: Template-Cache enthält keinen rohen DBX-Platzhalter.\n");
107 exit(1);
108}
109
110dbx()->set_system_var('dbx_activ_design', 'second');
111$second = $tpl->get_tpl('dbx|test-dbx-runtime-cache', array());
112
113if (trim($second) !== 'second') {
114 fwrite(STDERR, "FAIL: Cache-Treffer verwendet einen veralteten DBX-Systemwert.\n");
115 exit(1);
116}
117
118$design = $tpl->get_design_tpl('test', '1', 'de', 'htm', 0);
119if (trim($design) !== 'visible') {
120 fwrite(STDERR, "FAIL: Design-Template-Bedingung sieht den aktuellen DBX-Systemwert nicht.\n");
121 exit(1);
122}
123
124$tempRoot = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'dbx-tpl-cache-' . bin2hex(random_bytes(6));
125$tempTplDir = $tempRoot . DIRECTORY_SEPARATOR . 'dbx' . DIRECTORY_SEPARATOR . 'modules'
126 . DIRECTORY_SEPARATOR . 'dbx' . DIRECTORY_SEPARATOR . 'tpl' . DIRECTORY_SEPARATOR . 'htm';
127if (!mkdir($tempTplDir, 0777, true) && !is_dir($tempTplDir)) {
128 fwrite(STDERR, "FAIL: Temporaeres Template-Verzeichnis konnte nicht angelegt werden.\n");
129 exit(1);
130}
131$tempTpl = $tempTplDir . DIRECTORY_SEPARATOR . 'test-source-change.htm';
132file_put_contents($tempTpl, 'erste Version');
133dbx()->baseDir = $tempRoot . DIRECTORY_SEPARATOR;
134$_SESSION['dbx']['cache']['tpl'] = array();
135
136$sourceFirst = $tpl->get_tpl('dbx|test-source-change', array());
137file_put_contents($tempTpl, 'zweite, laengere Version');
138clearstatcache(true, $tempTpl);
139$sourceSecond = $tpl->get_tpl('dbx|test-source-change', array());
140
141@unlink($tempTpl);
142@rmdir($tempTplDir);
143@rmdir(dirname($tempTplDir));
144@rmdir(dirname(dirname($tempTplDir)));
145@rmdir(dirname(dirname(dirname($tempTplDir))));
146@rmdir(dirname(dirname(dirname(dirname($tempTplDir)))));
147@rmdir($tempRoot);
148
149if ($sourceFirst !== 'erste Version' || $sourceSecond !== 'zweite, laengere Version') {
150 fwrite(STDERR, "FAIL: Geaenderte Template-Datei blieb in der Session veraltet.\n");
151 exit(1);
152}
153
154echo "OK: dbxTPL cached rohe Templates, aktualisiert geaenderte Quellen und setzt DBX-Systemwerte bei jeder Ausgabe neu ein.\n";
Gemeinsame Basisklasse fuer dbXapp-System-, Modul- und Include-Objekte.
Definition dbxKernel.php:63
get_request_var(string $name, $default='')
set_system_var(string $name, $value)
get_system_var(string $name, $default='')
register_editor_file(string $kind, string $path)
$api system['dbx_permalink']
if($web->content_permalink_redirect_target() !=='') $tpl
if(trim($second) !=='second') $design
if(!mkdir($tempTplDir, 0777, true) &&!is_dir($tempTplDir)) $tempTpl
if(trim($first) !=='first') $cached
if(trim($design) !=='visible') $tempRoot
exit
Definition index.php:146