dbXapp 2.0
RAD, CMS, Module und Runtime-IDE fuer dbXapp
Loading...
Searching...
No Matches
dbxKernel.php
Go to the documentation of this file.
1<?php
20
21//global $dbxGlobalObj; $dbxGlobalVar; $dbxCacheTPL;
22
23
24
25
26require_once __DIR__ .'/dbxApi.php';
27
28/*
29set_error_handler(function ($errno, $errstr, $errfile, $errline) {
30 $log = sprintf("[%s] Fehler (%d): %s in %s Zeile %d\n",
31 date('Y-m-d H:i:s'), $errno, $errstr, $errfile, $errline
32 );
33 error_log($log);
34});
35
36set_exception_handler(function ($exception) {
37 $log = sprintf("[%s] Ausnahme: %s in %s Zeile %d\n",
38 date('Y-m-d H:i:s'), $exception->getMessage(),
39 $exception->getFile(), $exception->getLine()
40 );
41 error_log($log);
42});
43
44 */
45
46
63class dbxObj {
64
65 Public $_properties=array();
66 Public $_section='';
67 Public $_process='';
68 protected $_callback_owner = null;
69 protected $_callback_id = '';
70 protected $_callbacks = array();
71
72
82 public function set_callback_owner($owner): void {
83 if (is_object($owner)) {
84 $this->_callback_owner = $owner;
85 }
86 }
87
96 public function set_callback_id(string $id): void {
97 $this->_callback_id = $this->normalize_callback_id($id);
98 }
99
112 public function set_callback(string $event, string $callback): void {
113 if ($event !== '') {
114 $this->_callbacks[$event] = $callback;
115 }
116 }
117
124 protected function normalize_callback_id(string $id): string {
125 $id = preg_replace('/[^A-Za-z0-9_]+/', '_', $id);
126 $id = trim((string) $id, '_');
127
128 if ($id !== '' && preg_match('/^[0-9]/', $id)) {
129 $id = '_' . $id;
130 }
131
132 return $id;
133 }
134
144 protected function get_callback_name(string $event): string {
145 if ($event === '') {
146 return '';
147 }
148
149 if (isset($this->_callbacks[$event]) && $this->_callbacks[$event] !== '') {
150 return $this->_callbacks[$event];
151 }
152
153 if ($this->_callback_id === '') {
154 return '';
155 }
156
157 return $this->_callback_id . '_' . $event;
158 }
159
168 protected function get_callback_owner() {
169 if (is_object($this->_callback_owner)) {
170 return $this->_callback_owner;
171 }
172
173 if (function_exists('dbx')) {
174 return dbx()->get_current_owner();
175 }
176
177 return null;
178 }
179
191 protected function callback(string $event, mixed $value): mixed {
192 $callback = $this->get_callback_name($event);
193
194 if ($callback === '') {
195 return $value;
196 }
197
198 $owner = $this->get_callback_owner();
199
200 if (!is_object($owner)) {
201 return $value;
202 }
203
204 if (is_callable(array($owner, $callback))) {
205 return $owner->$callback($this, $value);
206 }
207
208 if (!method_exists($owner, $callback)) {
209 return $value;
210 }
211
212 try {
213 $method = new ReflectionMethod($owner, $callback);
214 } catch (ReflectionException $e) {
215 return $value;
216 }
217
218 if ($method->isStatic()) {
219 return $value;
220 }
221
222 return $method->invoke($owner, $this, $value);
223 }
224
225
226
246 public function set_property($name,$value,$section='',$modul='modul') {
247 if (!$section) $section=$this->_section;
248 if ( $modul=='modul') $modul=dbx()->get_system_var('dbx_activ_modul');
249 if (!$section) {
250 $this->_properties[$name]=$value;
251 } else {
252 dbx()->set_session_var($name,$value,$section,$modul);
253 }
254 //if (!is_array($value)) dbx_debug("Set_property=($name) section ($section) modul=($modul) value=($value)");
255 }
256
266 public function get_property($name,$default='',$section='',$modul='modul') {
267 if (!$section) $section=$this->_section;
268 if (!$section) {
269 if (isset($this->_properties[$name])) {
270 $value=$this->_properties[$name];
271 } else {
272 $value=$default;
273 }
274 } else {
275 if ($modul=='modul') $modul=dbx()->get_system_var('dbx_activ_modul');
276 $value=dbx()->get_session_var($name,$default,$section,$modul);
277 }
278 //if (!is_array($value)) dbx_debug("Get_property=($name) section ($section) modul=($modul) value=($value)");
279 return $value;
280 }
281
282
293 public function del_property($name,$section='',$modul='modul') {
294 if (!$section) $section=$this->_section;
295 if (!$section) {
296 if ($name != '*') {
297 if (isset($this->_properties[$name])) unset($this->_properties[$name]);
298 } else {
299 $this->_properties=array();
300 }
301 }
302 if ($section) {
303 if ($modul=='modul') $modul=dbx()->get_system_var('dbx_activ_modul');
304 dbx()->delete_session_var($name,$section,$modul);
305 }
306 }
307
319 public function dbx_next_process($content,$process='',$mode='append') {
320 $next=''; $pos=0;
321 if (!$process) $process=dbx()->get_session_var('dbx_process',0);
322 //dbx_debug("#GET-PROCESS=($process)");
323 if ($process) {
324 $oProcess=dbx()->get_system_obj('dbxProcess');
325 $next=$oProcess->run($process);
326 $pos =$oProcess->get_property('stepp');
327 }
328
329 //$content.="<br>Process=($process) Pos=($pos)<br>$next";
330 if ($mode=='append') $content.=$next;
331 if ($mode=='insert') $content =$next.$content;
332 if ($mode=='replace') $content =$next;
333
334 return $content;
335 }
336
337
338
339}
340
341// - - - - - -
342
347 function run() {
348 $class = dbx()->get_system_var('dbx_modul');
349 return "The Modul Classfile <b>$class</b> is undef!";
350 }
351}
352
357 function run() {
358 $url = dbx()->get_base_url();
359 $path = dbx_get_base_dir();
360 $action= dbx()->get_modul_var('dbx_run1');
361 $class = dbx()->get_system_var('dbx_modul');
362 $inc = dbx()->get_system_var('dbx_inc');
363 $master= dbx()->get_system_var('dbx_master_modul');
364 $mact = dbx()->get_system_var('dbx_master_action');
365 return "Aktion=($action) Modul Inc-Classfile <b>$inc</b> from <b>$class</b> is undef!<br> Master=($master) Action=($mact)<br>Base-Url=($url)";
366 }
367}
Gemeinsame Basisklasse fuer dbXapp-System-, Modul- und Include-Objekte.
Definition dbxKernel.php:63
normalize_callback_id(string $id)
Normalisiert Callback-IDs auf gueltige PHP-Methodenbestandteile.
set_callback_id(string $id)
Setzt den Namenspraefix fuer konventionelle Callback-Methoden.
Definition dbxKernel.php:96
Public $_properties
Definition dbxKernel.php:65
get_property($name, $default='', $section='', $modul='modul')
Liest eine Objekt- oder Session-Property.
get_callback_name(string $event)
Liefert den Methodennamen fuer ein Event.
set_callback(string $event, string $callback)
Ordnet einem Event einen konkreten Methodennamen zu.
get_callback_owner()
Liefert das aktuelle Owner-Objekt fuer Callback-Aufrufe.
set_property($name, $value, $section='', $modul='modul')
Speichert eine Objekt- oder Session-Property.
set_callback_owner($owner)
Setzt ein explizites Owner-Objekt fuer Callback-Aufrufe.
Definition dbxKernel.php:82
dbx_next_process($content, $process='', $mode='append')
Fuegt den naechsten dbxProcess-Schritt in eine Ausgabe ein.
Public $_section
Definition dbxKernel.php:66
del_property($name, $section='', $modul='modul')
Loescht eine Objekt- oder Session-Property.
$_callback_owner
Definition dbxKernel.php:68
Public $_process
Definition dbxKernel.php:67
$_callback_id
Definition dbxKernel.php:69
callback(string $event, mixed $value)
Fuehrt einen Callback aus und gibt dessen Rueckgabewert zurueck.
Fallback fuer nicht vorhandene Include- oder Systemklassen.
Fallback fuer nicht vorhandene Modulklassen.
if( $syncRequest)
Definition index.php:520
dbx_get_base_dir($cut_Data=0)
Definition index.php:157
DBX schema administration.