TemplateFileLocator.php 1.6 KB

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