4
0

Factory.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. default => new FreshRSS_CategoryDAO($username),
  17. };
  18. }
  19. /**
  20. * @throws Minz_ConfigurationNamespaceException|Minz_PDOConnectionException
  21. */
  22. public static function createFeedDao(?string $username = null): FreshRSS_FeedDAO {
  23. return match (FreshRSS_Context::systemConf()->db['type'] ?? '') {
  24. 'sqlite' => new FreshRSS_FeedDAOSQLite($username),
  25. default => new FreshRSS_FeedDAO($username),
  26. };
  27. }
  28. /**
  29. * @throws Minz_ConfigurationNamespaceException|Minz_PDOConnectionException
  30. */
  31. public static function createEntryDao(?string $username = null): FreshRSS_EntryDAO {
  32. return match (FreshRSS_Context::systemConf()->db['type'] ?? '') {
  33. 'sqlite' => new FreshRSS_EntryDAOSQLite($username),
  34. 'pgsql' => new FreshRSS_EntryDAOPGSQL($username),
  35. default => new FreshRSS_EntryDAO($username),
  36. };
  37. }
  38. /**
  39. * @throws Minz_ConfigurationNamespaceException|Minz_PDOConnectionException
  40. */
  41. public static function createTagDao(?string $username = null): FreshRSS_TagDAO {
  42. return match (FreshRSS_Context::systemConf()->db['type'] ?? '') {
  43. 'sqlite' => new FreshRSS_TagDAOSQLite($username),
  44. 'pgsql' => new FreshRSS_TagDAOPGSQL($username),
  45. default => new FreshRSS_TagDAO($username),
  46. };
  47. }
  48. /**
  49. * @throws Minz_ConfigurationNamespaceException|Minz_PDOConnectionException
  50. */
  51. public static function createStatsDAO(?string $username = null): FreshRSS_StatsDAO {
  52. return match (FreshRSS_Context::systemConf()->db['type'] ?? '') {
  53. 'sqlite' => new FreshRSS_StatsDAOSQLite($username),
  54. 'pgsql' => new FreshRSS_StatsDAOPGSQL($username),
  55. default => new FreshRSS_StatsDAO($username),
  56. };
  57. }
  58. /**
  59. * @throws Minz_ConfigurationNamespaceException|Minz_PDOConnectionException
  60. */
  61. public static function createDatabaseDAO(?string $username = null): FreshRSS_DatabaseDAO {
  62. return match (FreshRSS_Context::systemConf()->db['type'] ?? '') {
  63. 'sqlite' => new FreshRSS_DatabaseDAOSQLite($username),
  64. 'pgsql' => new FreshRSS_DatabaseDAOPGSQL($username),
  65. default => new FreshRSS_DatabaseDAO($username),
  66. };
  67. }
  68. }