templatefilelocator.php 866 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace OC\Template;
  9. class TemplateFileLocator {
  10. protected $dirs;
  11. private $path;
  12. /**
  13. * @param string[] $dirs
  14. */
  15. public function __construct( $dirs ) {
  16. $this->dirs = $dirs;
  17. }
  18. /**
  19. * @param string $template
  20. * @return string
  21. * @throws \Exception
  22. */
  23. public function find( $template ) {
  24. if ($template === '') {
  25. throw new \InvalidArgumentException('Empty template name');
  26. }
  27. foreach($this->dirs as $dir) {
  28. $file = $dir.$template.'.php';
  29. if (is_file($file)) {
  30. $this->path = $dir;
  31. return $file;
  32. }
  33. }
  34. throw new \Exception('template file not found: template:'.$template);
  35. }
  36. public function getPath() {
  37. return $this->path;
  38. }
  39. }