PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / trunk
JetBackup – Backup, Restore & Migrate vtrunk
3.1.22.3 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.8.1 1.4.9 1.5.0 1.5.1 1.5.1.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.10 1.6.11 1.6.12 1.6.13 1.6.15 1.6.5.1 1.6.8.8 1.6.9 1.6.9.1 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7.5 2.0.8.7 2.0.9.11 2.0.9.14 2.0.9.15 2.0.9.6 2.0.9.7 2.0.9.9 3.1.10.7 3.1.11.1 3.1.12.3 3.1.13.4 3.1.14.17 3.1.15.4 3.1.16.1 3.1.17.5 3.1.18.10 3.1.18.8 3.1.18.9 3.1.19.8 3.1.20.3 3.1.21.3 3.1.7.9 3.1.9.2 trunk 1.1.90 1.1.91 1.2.0 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2
backup / src / JetBackup / Data / ReflectionObject.php
backup / src / JetBackup / Data Last commit date
.htaccess 1 year ago ArrayData.php 1 year ago DBObject.php 1 year ago Engine.php 1 year ago Mysqldump.php 5 months ago ReflectionObject.php 1 year ago SleekStore.php 1 year ago index.html 1 year ago web.config 1 year ago
ReflectionObject.php
84 lines
1 <?php
2
3 namespace JetBackup\Data;
4
5 use JetBackup\Exception\IOException;
6 use JetBackup\IO\Lock;
7 use ReflectionClass;
8 use ReflectionException;
9
10 if (!defined( '__JETBACKUP__')) die('Direct access is not allowed');
11
12 class ReflectionObject extends ArrayData {
13
14 private string $_file;
15 private string $_className;
16 private array $_diff;
17
18 /**
19 * @param string $file
20 * @param string $className
21 *
22 * @throws ReflectionException
23 * @throws IOException
24 */
25 public function __construct(string $file, string $className) {
26 $this->_file = $file;
27 $this->_className = $className;
28 $this->_diff = [];
29
30 // Create the class if not exists
31 if(!file_exists($this->_file)) {
32 $this->loadFromDatabase();
33 $this->save();
34 }
35
36 chmod($this->_file, 0600);
37
38 require_once($this->_file);
39 $this->setData((new ReflectionClass($this->_className))->getConstants());
40 }
41
42 function loadFromDatabase():void {}
43
44 public function getDiff():array { return $this->_diff; }
45
46 public function set($key, $value) {
47 $this->_diff[$key] = $value;
48 parent::set($key, $value);
49 }
50
51 /**
52 * @return void
53 * @throws IOException
54 */
55 public function save():void {
56 if (!($f = fopen($this->_file, 'w'))) {
57 Lock::UnlockFile($this->_file . '.lock');
58 throw new IOException("Error creating config file " . $this->_file);
59 }
60 fwrite($f, "<?php" . PHP_EOL);
61 fwrite($f, "if (!defined( '__JETBACKUP__')) die('Direct access is not allowed');" . PHP_EOL);
62 fwrite($f, "class $this->_className {" . PHP_EOL);
63 foreach ($this->getData() as $key => $value) {
64 switch (true) {
65 case is_array($value):
66 case is_object($value):
67 $value = ''; // Unsupported types default to an empty string
68 break;
69 case is_bool($value):
70 $value = $value ? 'true' : 'false'; // Convert booleans to 'true' or 'false'
71 break;
72 case is_null($value):
73 $value = 'null'; // set null values to 'null'
74 break;
75 case !is_int($value) && !is_float($value):
76 $value = "'" . preg_replace("/([\\\'])/", "\\\\$1", $value) . "'"; // Wrap non-numeric strings in single quotes
77 break;
78 }
79 fwrite($f, "\tconst $key = $value;" . PHP_EOL);
80 }
81 fwrite($f, "}");
82 fclose($f);
83 }
84 }