diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/composer/composer/autoload_classmap.php | 1 | ||||
-rw-r--r-- | lib/composer/composer/autoload_static.php | 1 | ||||
-rw-r--r-- | lib/private/Template/Template.php | 9 | ||||
-rw-r--r-- | lib/private/Template/TemplateFileLocator.php | 29 | ||||
-rw-r--r-- | lib/private/Template/TemplateManager.php | 2 | ||||
-rw-r--r-- | lib/public/Template/ITemplateManager.php | 1 | ||||
-rw-r--r-- | lib/public/Template/TemplateNotFoundException.php | 16 |
7 files changed, 39 insertions, 20 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 8b397620963..53516becad2 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -845,6 +845,7 @@ return array( 'OCP\\Template' => $baseDir . '/lib/public/Template.php', 'OCP\\Template\\ITemplate' => $baseDir . '/lib/public/Template/ITemplate.php', 'OCP\\Template\\ITemplateManager' => $baseDir . '/lib/public/Template/ITemplateManager.php', + 'OCP\\Template\\TemplateNotFoundException' => $baseDir . '/lib/public/Template/TemplateNotFoundException.php', 'OCP\\TextProcessing\\Events\\AbstractTextProcessingEvent' => $baseDir . '/lib/public/TextProcessing/Events/AbstractTextProcessingEvent.php', 'OCP\\TextProcessing\\Events\\TaskFailedEvent' => $baseDir . '/lib/public/TextProcessing/Events/TaskFailedEvent.php', 'OCP\\TextProcessing\\Events\\TaskSuccessfulEvent' => $baseDir . '/lib/public/TextProcessing/Events/TaskSuccessfulEvent.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 4072df51ee1..1a8fc66d918 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -894,6 +894,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OCP\\Template' => __DIR__ . '/../../..' . '/lib/public/Template.php', 'OCP\\Template\\ITemplate' => __DIR__ . '/../../..' . '/lib/public/Template/ITemplate.php', 'OCP\\Template\\ITemplateManager' => __DIR__ . '/../../..' . '/lib/public/Template/ITemplateManager.php', + 'OCP\\Template\\TemplateNotFoundException' => __DIR__ . '/../../..' . '/lib/public/Template/TemplateNotFoundException.php', 'OCP\\TextProcessing\\Events\\AbstractTextProcessingEvent' => __DIR__ . '/../../..' . '/lib/public/TextProcessing/Events/AbstractTextProcessingEvent.php', 'OCP\\TextProcessing\\Events\\TaskFailedEvent' => __DIR__ . '/../../..' . '/lib/public/TextProcessing/Events/TaskFailedEvent.php', 'OCP\\TextProcessing\\Events\\TaskSuccessfulEvent' => __DIR__ . '/../../..' . '/lib/public/TextProcessing/Events/TaskSuccessfulEvent.php', diff --git a/lib/private/Template/Template.php b/lib/private/Template/Template.php index 9c71208522d..b69d68b944f 100644 --- a/lib/private/Template/Template.php +++ b/lib/private/Template/Template.php @@ -18,6 +18,7 @@ use OCP\AppFramework\Http\TemplateResponse; use OCP\Defaults; use OCP\Server; use OCP\Template\ITemplate; +use OCP\Template\TemplateNotFoundException; use OCP\Util; require_once __DIR__ . '/../legacy/template/functions.php'; @@ -31,6 +32,7 @@ class Template extends Base implements ITemplate { * @param string $name of the template file (without suffix) * @param TemplateResponse::RENDER_AS_* $renderAs If $renderAs is set, will try to * produce a full page in the according layout. + * @throws TemplateNotFoundException */ public function __construct( protected string $app, @@ -68,7 +70,8 @@ class Template extends Base implements ITemplate { * Checking all the possible locations. * * @param string $name of the template file (without suffix) - * @return string[] + * @return array{string,string} Directory path and filename + * @throws TemplateNotFoundException */ protected function findTemplate(string $theme, string $app, string $name): array { // Check if it is a app template or not. @@ -83,9 +86,7 @@ class Template extends Base implements ITemplate { $dirs = $this->getCoreTemplateDirs($theme, \OC::$SERVERROOT); } $locator = new TemplateFileLocator($dirs); - $template = $locator->find($name); - $path = $locator->getPath(); - return [$path, $template]; + return $locator->find($name); } /** diff --git a/lib/private/Template/TemplateFileLocator.php b/lib/private/Template/TemplateFileLocator.php index 38583d158a3..11a568b5b21 100644 --- a/lib/private/Template/TemplateFileLocator.php +++ b/lib/private/Template/TemplateFileLocator.php @@ -1,29 +1,31 @@ <?php +declare(strict_types=1); + /** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. * SPDX-License-Identifier: AGPL-3.0-only */ + namespace OC\Template; -class TemplateFileLocator { - protected $dirs; - private $path; +use OCP\Template\TemplateNotFoundException; +class TemplateFileLocator { /** * @param string[] $dirs */ - public function __construct($dirs) { - $this->dirs = $dirs; + public function __construct( + private array $dirs, + ) { } /** - * @param string $template - * @return string - * @throws \Exception + * @return array{string,string} Directory path and filename + * @throws TemplateNotFoundException */ - public function find($template) { + public function find(string $template): array { if ($template === '') { throw new \InvalidArgumentException('Empty template name'); } @@ -31,14 +33,9 @@ class TemplateFileLocator { foreach ($this->dirs as $dir) { $file = $dir . $template . '.php'; if (is_file($file)) { - $this->path = $dir; - return $file; + return [$dir,$file]; } } - throw new \Exception('template file not found: template:' . $template); - } - - public function getPath() { - return $this->path; + throw new TemplateNotFoundException('template file not found: template:' . $template); } } diff --git a/lib/private/Template/TemplateManager.php b/lib/private/Template/TemplateManager.php index e57203ba2da..34da4deac72 100644 --- a/lib/private/Template/TemplateManager.php +++ b/lib/private/Template/TemplateManager.php @@ -17,6 +17,7 @@ use OCP\IRequest; use OCP\Server; use OCP\Template\ITemplate; use OCP\Template\ITemplateManager; +use OCP\Template\TemplateNotFoundException; use Psr\Log\LoggerInterface; class TemplateManager implements ITemplateManager { @@ -28,6 +29,7 @@ class TemplateManager implements ITemplateManager { /** * @param TemplateResponse::RENDER_AS_* $renderAs + * @throws TemplateNotFoundException if the template cannot be found */ public function getTemplate(string $app, string $name, string $renderAs = TemplateResponse::RENDER_AS_BLANK, bool $registerCall = true): ITemplate { return new Template($app, $name, $renderAs, $registerCall); diff --git a/lib/public/Template/ITemplateManager.php b/lib/public/Template/ITemplateManager.php index 94a2ee49399..05549bbddfd 100644 --- a/lib/public/Template/ITemplateManager.php +++ b/lib/public/Template/ITemplateManager.php @@ -17,6 +17,7 @@ use OCP\AppFramework\Http\TemplateResponse; interface ITemplateManager { /** * @param TemplateResponse::RENDER_AS_* $renderAs + * @throws TemplateNotFoundException if the template cannot be found * @since 32.0.0 */ public function getTemplate(string $app, string $name, string $renderAs = TemplateResponse::RENDER_AS_BLANK, bool $registerCall = true): ITemplate; diff --git a/lib/public/Template/TemplateNotFoundException.php b/lib/public/Template/TemplateNotFoundException.php new file mode 100644 index 00000000000..e77fcd8646a --- /dev/null +++ b/lib/public/Template/TemplateNotFoundException.php @@ -0,0 +1,16 @@ +<?php + +declare(strict_types=1); + +/** + * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace OCP\Template; + +/** + * @since 32.0.0 + */ +class TemplateNotFoundException extends \Exception { +} |