TemplateFileLocator.php 1.5 KB

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