BundleFetcher.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 Lukas Reschke <lukas@statuscode.ch>
  4. *
  5. * @author Lukas Reschke <lukas@statuscode.ch>
  6. *
  7. * @license GNU AGPL version 3 or any later version
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. namespace OC\App\AppStore\Bundles;
  24. use OCP\IL10N;
  25. class BundleFetcher {
  26. /** @var IL10N */
  27. private $l10n;
  28. /**
  29. * @param IL10N $l10n
  30. */
  31. public function __construct(IL10N $l10n) {
  32. $this->l10n = $l10n;
  33. }
  34. /**
  35. * @return Bundle[]
  36. */
  37. public function getBundles() {
  38. return [
  39. new EnterpriseBundle($this->l10n),
  40. new GroupwareBundle($this->l10n),
  41. new SocialSharingBundle($this->l10n),
  42. new EducationBundle($this->l10n),
  43. ];
  44. }
  45. /**
  46. * Bundles that should be installed by default after installation
  47. *
  48. * @return Bundle[]
  49. */
  50. public function getDefaultInstallationBundle() {
  51. return [
  52. new CoreBundle($this->l10n),
  53. ];
  54. }
  55. /**
  56. * Get the bundle with the specified identifier
  57. *
  58. * @param string $identifier
  59. * @return Bundle
  60. * @throws \BadMethodCallException If the bundle does not exist
  61. */
  62. public function getBundleByIdentifier($identifier) {
  63. /** @var Bundle[] $bundles */
  64. $bundles = array_merge(
  65. $this->getBundles(),
  66. $this->getDefaultInstallationBundle()
  67. );
  68. foreach($bundles as $bundle) {
  69. if($bundle->getIdentifier() === $identifier) {
  70. return $bundle;
  71. }
  72. }
  73. throw new \BadMethodCallException('Bundle with specified identifier does not exist');
  74. }
  75. }