Advertisement
Guest User

Untitled

a guest
May 28th, 2015
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. <?php
  2. class ICG_CLASS_my_app
  3. {
  4. public $data;
  5.  
  6. //Главный конструктор инициализирует созданные переменные
  7. public function __construct()
  8. {
  9. $this->data = json_decode('{"version":2}', true);
  10. }
  11.  
  12. //Деструктор, при уничтожении сохраняет все данные
  13. public function __destruct()
  14. {
  15. $this->save();
  16. }
  17.  
  18. //Сеттер для переменных
  19. public function __set($key, $value)
  20. {
  21. $this->data[$key] = $value;
  22. }
  23.  
  24. //Геттер для переменных
  25. public function __get($key)
  26. {
  27. if (!isset($this->data[$key])) return null;
  28. return $this->data[$key];
  29. }
  30.  
  31. //Функция самосохранения, изменять данные файла
  32. public function save()
  33. {
  34. $file_data = preg_replace_callback('/\$this->data = json_decode\((.*?)\);/', function ($matches)
  35. {
  36. return "\$this->data = json_decode('".json_encode($this->data)."', true);";
  37. }, file_get_contents(dirname(__FILE__)."/"."my_app.config.php"), 1);
  38.  
  39. file_put_contents(dirname(__FILE__)."/"."my_app.config.php", $file_data);
  40. }
  41. }
  42.  
  43. return new ICG_CLASS_my_app;
  44. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement