4
0

Factory.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. declare(strict_types=1);
  3. class FreshRSS_Factory {
  4. /**
  5. * @throws Minz_ConfigurationNamespaceException|Minz_PDOConnectionException
  6. */
  7. public static function createUserDao(?string $username = null): FreshRSS_UserDAO {
  8. return new FreshRSS_UserDAO($username);
  9. }
  10. /**
  11. * @throws Minz_ConfigurationNamespaceException|Minz_PDOConnectionException
  12. */
  13. public static function createCategoryDao(?string $username = null): FreshRSS_CategoryDAO {
  14. return match (FreshRSS_Context::systemConf()->db['type'] ?? '') {
  15. 'sqlite' => new FreshRSS_CategoryDAOSQLite($username),
  16. 'pgsql' => new FreshRSS_CategoryDAOPGSQL($username),
  17. default => new FreshRSS_CategoryDAO($username),
  18. };
  19. }
  20. /**
  21. * @throws Minz_ConfigurationNamespaceException|Minz_PDOConnectionException
  22. */
  23. public static function createFeedDao(?string $username = null): FreshRSS_FeedDAO {
  24. return match (FreshRSS_Context::systemConf()->db['type'] ?? '') {
  25. 'sqlite' => new FreshRSS_FeedDAOSQLite($username),
  26. 'pgsql' => new FreshRSS_FeedDAOPGSQL($username),
  27. default => new FreshRSS_FeedDAO($username),
  28. };
  29. }
  30. /**
  31. * @throws Minz_ConfigurationNamespaceException|Minz_PDOConnectionException
  32. */
  33. public static function createEntryDao(?string $username = null): FreshRSS_EntryDAO {
  34. return match (FreshRSS_Context::systemConf()->db['type'] ?? '') {
  35. 'sqlite' => new FreshRSS_EntryDAOSQLite($username),
  36. 'pgsql' => new FreshRSS_EntryDAOPGSQL($username),
  37. default => new FreshRSS_EntryDAO($username),
  38. };
  39. }
  40. /**
  41. * @throws Minz_ConfigurationNamespaceException|Minz_PDOConnectionException
  42. */
  43. public static function createTagDao(?string $username = null): FreshRSS_TagDAO {
  44. return match (FreshRSS_Context::systemConf()->db['type'] ?? '') {
  45. 'sqlite' => new FreshRSS_TagDAOSQLite($username),
  46. 'pgsql' => new FreshRSS_TagDAOPGSQL($username),
  47. default => new FreshRSS_TagDAO($username),
  48. };
  49. }
  50. /**
  51. * @throws Minz_ConfigurationNamespaceException|Minz_PDOConnectionException
  52. */
  53. public static function createStatsDAO(?string $username = null): FreshRSS_StatsDAO {
  54. return match (FreshRSS_Context::systemConf()->db['type'] ?? '') {
  55. 'sqlite' => new FreshRSS_StatsDAOSQLite($username),
  56. 'pgsql' => new FreshRSS_StatsDAOPGSQL($username),
  57. default => new FreshRSS_StatsDAO($username),
  58. };
  59. }
  60. /**
  61. * @throws Minz_ConfigurationNamespaceException|Minz_PDOConnectionException
  62. */
  63. public static function createDatabaseDAO(?string $username = null): FreshRSS_DatabaseDAO {
  64. return match (FreshRSS_Context::systemConf()->db['type'] ?? '') {
  65. 'sqlite' => new FreshRSS_DatabaseDAOSQLite($username),
  66. 'pgsql' => new FreshRSS_DatabaseDAOPGSQL($username),
  67. default => new FreshRSS_DatabaseDAO($username),
  68. };
  69. }
  70. }