TemplateFileLocator.php 856 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OC\Template;
  8. class TemplateFileLocator {
  9. protected $dirs;
  10. private $path;
  11. /**
  12. * @param string[] $dirs
  13. */
  14. public function __construct($dirs) {
  15. $this->dirs = $dirs;
  16. }
  17. /**
  18. * @param string $template
  19. * @return string
  20. * @throws \Exception
  21. */
  22. public function find($template) {
  23. if ($template === '') {
  24. throw new \InvalidArgumentException('Empty template name');
  25. }
  26. foreach ($this->dirs as $dir) {
  27. $file = $dir.$template.'.php';
  28. if (is_file($file)) {
  29. $this->path = $dir;
  30. return $file;
  31. }
  32. }
  33. throw new \Exception('template file not found: template:'.$template);
  34. }
  35. public function getPath() {
  36. return $this->path;
  37. }
  38. }