Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2020-07-16 16:47:28 +0300
committerJoas Schilling <coding@schilljs.com>2020-07-16 16:47:28 +0300
commit49970639faecbf5acd24b2b84e5df1a8fa9c746a (patch)
tree2cb28e5876b45f1fd3d5cc3c5b5136259859cb45 /lib/public/AppFramework
parent33aeef2d101029dd4538994d462a51062a5975d7 (diff)
Add constants for the magic strings of template rendering
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/public/AppFramework')
-rw-r--r--lib/public/AppFramework/Http/TemplateResponse.php37
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);