Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class ICG_CLASS_my_app
- {
- public $data;
- //Главный конструктор инициализирует созданные переменные
- public function __construct()
- {
- $this->data = json_decode('{"version":2}', true);
- }
- //Деструктор, при уничтожении сохраняет все данные
- public function __destruct()
- {
- $this->save();
- }
- //Сеттер для переменных
- public function __set($key, $value)
- {
- $this->data[$key] = $value;
- }
- //Геттер для переменных
- public function __get($key)
- {
- if (!isset($this->data[$key])) return null;
- return $this->data[$key];
- }
- //Функция самосохранения, изменять данные файла
- public function save()
- {
- $file_data = preg_replace_callback('/\$this->data = json_decode\((.*?)\);/', function ($matches)
- {
- return "\$this->data = json_decode('".json_encode($this->data)."', true);";
- }, file_get_contents(dirname(__FILE__)."/"."my_app.config.php"), 1);
- file_put_contents(dirname(__FILE__)."/"."my_app.config.php", $file_data);
- }
- }
- return new ICG_CLASS_my_app;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement