PageRenderTime 49ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/library/Application/Config/Format/Serialize.php

https://github.com/visor/nano
PHP | 54 lines | 25 code | 8 blank | 21 comment | 0 complexity | 3970aac7f66725c4439c95e4f1f065b5 MD5 | raw file
  1. <?php
  2. namespace Nano\Application\Config\Format;
  3. class Serialize implements \Nano\Application\Config\Format {
  4. /**
  5. * @return boolean
  6. */
  7. public function available() {
  8. return true;
  9. }
  10. /**
  11. * @return stdClass
  12. * @param string $fileName
  13. */
  14. public function read($fileName) {
  15. $result = file_get_contents($fileName);
  16. $result = unSerialize($result);
  17. return $result;
  18. }
  19. /**
  20. * @return \Nano\Routes
  21. * @param string $fileName
  22. */
  23. public function readRoutes($fileName) {
  24. return $this->read($fileName);
  25. }
  26. /**
  27. * @return boolean
  28. * @param array $data
  29. * @param string $fileName
  30. */
  31. public function write(array $data, $fileName) {
  32. $source = serialize(json_decode(json_encode($data)));
  33. file_put_contents($fileName, $source);
  34. return true;
  35. }
  36. /**
  37. * @return boolean
  38. * @param \Nano\Routes $routes
  39. * @param string $fileName
  40. */
  41. public function writeRoutes(\Nano\Routes $routes, $fileName) {
  42. $source = serialize($routes);
  43. file_put_contents($fileName, $source);
  44. return true;
  45. }
  46. }