diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2020-07-16 22:00:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-16 22:00:57 +0200 |
commit | cae849bcf93a46dfaa07d27854374c270a12a60a (patch) | |
tree | f98bc25fb54c5c3fbc40e0a795155d42cd1fe19a /lib/public | |
parent | dfcb49b9b77396ef5aa96591b1d3762a4a8245e6 (diff) | |
parent | 49970639faecbf5acd24b2b84e5df1a8fa9c746a (diff) | |
download | nextcloud-server-cae849bcf93a46dfaa07d27854374c270a12a60a.tar.gz nextcloud-server-cae849bcf93a46dfaa07d27854374c270a12a60a.zip |
Merge pull request #21869 from nextcloud/techdebt/noid/add-constants-for-magic-strings
Add constants for the magic strings of template rendering
Diffstat (limited to 'lib/public')
-rw-r--r-- | lib/public/AppFramework/Http/TemplateResponse.php | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/lib/public/AppFramework/Http/TemplateResponse.php b/lib/public/AppFramework/Http/TemplateResponse.php index 48e6c43411f..9622d9696dc 100644 --- a/lib/public/AppFramework/Http/TemplateResponse.php +++ b/lib/public/AppFramework/Http/TemplateResponse.php @@ -39,6 +39,27 @@ namespace OCP\AppFramework\Http; */ class TemplateResponse extends Response { /** + * @since 20.0.0 + */ + public const RENDER_AS_GUEST = 'guest'; + /** + * @since 20.0.0 + */ + public const RENDER_AS_BLANK = ''; + /** + * @since 20.0.0 + */ + public const RENDER_AS_USER = 'user'; + /** + * @since 20.0.0 + */ + public const RENDER_AS_ERROR = 'error'; + /** + * @since 20.0.0 + */ + public const RENDER_AS_PUBLIC = 'public'; + + /** * @deprecated 20.0.0 use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent */ public const EVENT_LOAD_ADDITIONAL_SCRIPTS = self::class . '::loadAdditionalScripts'; @@ -81,7 +102,7 @@ class TemplateResponse extends Response { * @since 6.0.0 - parameters $params and $renderAs were added in 7.0.0 */ public function __construct($appName, $templateName, array $params=[], - $renderAs='user') { + $renderAs = self::RENDER_AS_USER) { parent::__construct(); $this->templateName = $templateName; @@ -160,8 +181,18 @@ class TemplateResponse extends Response { * @since 6.0.0 */ public function render() { - // \OCP\Template needs an empty string instead of 'blank' for an unwrapped response - $renderAs = $this->renderAs === 'blank' ? '' : $this->renderAs; + $renderAs = self::RENDER_AS_USER; + if ($this->renderAs === 'blank') { + // Legacy fallback as \OCP\Template needs an empty string instead of 'blank' for an unwrapped response + $renderAs = self::RENDER_AS_BLANK; + } elseif (in_array($this->renderAs, [ + self::RENDER_AS_GUEST, + self::RENDER_AS_BLANK, + self::RENDER_AS_ERROR, + self::RENDER_AS_PUBLIC, + self::RENDER_AS_USER], true)) { + $renderAs = $this->renderAs; + } \OCP\Util::addHeader('meta', ['name' => 'robots', 'content' => 'noindex, nofollow']); $template = new \OCP\Template($this->appName, $this->templateName, $renderAs); |