templatefilelocator.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * @author Bart Visscher <bartv@thisnet.nl>
  4. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  5. * @author Morris Jobke <hey@morrisjobke.de>
  6. * @author Thomas Müller <thomas.mueller@tmit.eu>
  7. *
  8. * @copyright Copyright (c) 2015, ownCloud, Inc.
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. namespace OC\Template;
  25. class TemplateFileLocator {
  26. protected $dirs;
  27. private $path;
  28. /**
  29. * @param string[] $dirs
  30. */
  31. public function __construct( $dirs ) {
  32. $this->dirs = $dirs;
  33. }
  34. /**
  35. * @param string $template
  36. * @return string
  37. * @throws \Exception
  38. */
  39. public function find( $template ) {
  40. if ($template === '') {
  41. throw new \InvalidArgumentException('Empty template name');
  42. }
  43. foreach($this->dirs as $dir) {
  44. $file = $dir.$template.'.php';
  45. if (is_file($file)) {
  46. $this->path = $dir;
  47. return $file;
  48. }
  49. }
  50. throw new \Exception('template file not found: template:'.$template);
  51. }
  52. public function getPath() {
  53. return $this->path;
  54. }
  55. }