You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UsersSettingsDataAccess.php 1009B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: robin
  5. * Date: 10/3/16
  6. * Time: 6:05 PM
  7. */
  8. namespace App\DataAccess;
  9. use Luticate\Utils\Controller\LuticateApplication;
  10. class UsersSettingsDataAccess
  11. {
  12. public static function getDir()
  13. {
  14. $dir = LuticateApplication::getInstance()->getSetting("USERS_SETTING_DIR");
  15. return __DIR__ . "/../../${dir}/";
  16. }
  17. public static function getFilePath(string $id)
  18. {
  19. $dir = static::getDir();
  20. $filename = preg_replace("([^a-zA-Z0-9])", '_', $id);
  21. return $dir . $filename;
  22. }
  23. public static function put(string $settings, string $id)
  24. {
  25. $filePath = self::getFilePath($id);
  26. file_put_contents($filePath, $settings);
  27. return true;
  28. }
  29. public static function get(string $id)
  30. {
  31. $filePath = self::getFilePath($id);
  32. if (file_exists($filePath)) {
  33. $settings = file_get_contents($filePath);
  34. return $settings;
  35. }
  36. return null;
  37. }
  38. }