templatefilelocator.php 985 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 $form_factor;
  11. protected $dirs;
  12. private $path;
  13. public function __construct( $form_factor, $dirs ) {
  14. $this->form_factor = $form_factor;
  15. $this->dirs = $dirs;
  16. }
  17. public function find( $template ) {
  18. if ($template === '') {
  19. throw new \InvalidArgumentException('Empty template name');
  20. }
  21. foreach($this->dirs as $dir) {
  22. $file = $dir.$template.$this->form_factor.'.php';
  23. if (is_file($file)) {
  24. $this->path = $dir;
  25. return $file;
  26. }
  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.' formfactor:'.$this->form_factor);
  34. }
  35. public function getPath() {
  36. return $this->path;
  37. }
  38. }