From 834b1048090026289b09c170bc29592b9dd0d888 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Sun, 17 Mar 2024 22:35:58 +0100 Subject: [PATCH] !!! TASK: Add strict types to `ViewInterface` --- Neos.Flow/Classes/Mvc/View/AbstractView.php | 12 +++++------ Neos.Flow/Classes/Mvc/View/ViewInterface.php | 20 +++++++++---------- .../Classes/View/AbstractTemplateView.php | 16 +++++++++++++-- .../Classes/View/StandaloneView.php | 4 ++-- 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/Neos.Flow/Classes/Mvc/View/AbstractView.php b/Neos.Flow/Classes/Mvc/View/AbstractView.php index b352885ee3..ea85dfbd00 100644 --- a/Neos.Flow/Classes/Mvc/View/AbstractView.php +++ b/Neos.Flow/Classes/Mvc/View/AbstractView.php @@ -61,9 +61,9 @@ abstract class AbstractView implements ViewInterface * Factory method to create an instance with given options. * * @param array $options - * @return ViewInterface + * @return static */ - public static function createWithOptions(array $options) + public static function createWithOptions(array $options): self { return new static($options); } @@ -143,10 +143,10 @@ public function setOption($optionName, $value) * * @param string $key Key of variable * @param mixed $value Value of object - * @return AbstractView an instance of $this, to enable chaining + * @return $this for chaining * @api */ - public function assign($key, $value) + public function assign(string $key, mixed $value): self { $this->variables[$key] = $value; return $this; @@ -156,10 +156,10 @@ public function assign($key, $value) * Add multiple variables to $this->variables. * * @param array $values array in the format array(key1 => value1, key2 => value2) - * @return AbstractView an instance of $this, to enable chaining + * @return $this for chaining * @api */ - public function assignMultiple(array $values) + public function assignMultiple(array $values): self { foreach ($values as $key => $value) { $this->assign($key, $value); diff --git a/Neos.Flow/Classes/Mvc/View/ViewInterface.php b/Neos.Flow/Classes/Mvc/View/ViewInterface.php index 06b8399f08..838b401ace 100644 --- a/Neos.Flow/Classes/Mvc/View/ViewInterface.php +++ b/Neos.Flow/Classes/Mvc/View/ViewInterface.php @@ -30,27 +30,27 @@ interface ViewInterface * @param ControllerContext $controllerContext Context of the controller associated with this view * @return void */ - // public function setControllerContext(ControllerContext $controllerContext); + // public function setControllerContext(ControllerContext $controllerContext): void; /** * Add a variable to the view data collection. - * Can be chained, so $this->view->assign(..., ...)->assign(..., ...); is possible + * Can be chained: $this->view->assign(..., ...)->assign(..., ...); * * @param string $key Key of variable * @param mixed $value Value of object - * @return ViewInterface an instance of $this, to enable chaining + * @return $this for chaining * @api */ - public function assign($key, $value); + public function assign(string $key, mixed $value): self; /** * Add multiple variables to the view data collection * - * @param array $values array in the format array(key1 => value1, key2 => value2) - * @return ViewInterface an instance of $this, to enable chaining + * @param array $values associative array with the key being its name + * @return $this for chaining * @api */ - public function assignMultiple(array $values); + public function assignMultiple(array $values): self; /** * Renders the view @@ -62,8 +62,8 @@ public function render(): ResponseInterface|StreamInterface; /** * Factory method to create an instance with given options. * - * @param array $options - * @return ViewInterface + * @param array $options + * @return static */ - public static function createWithOptions(array $options); + public static function createWithOptions(array $options): self; } diff --git a/Neos.FluidAdaptor/Classes/View/AbstractTemplateView.php b/Neos.FluidAdaptor/Classes/View/AbstractTemplateView.php index c9433cb6cf..bb92d96905 100644 --- a/Neos.FluidAdaptor/Classes/View/AbstractTemplateView.php +++ b/Neos.FluidAdaptor/Classes/View/AbstractTemplateView.php @@ -118,13 +118,25 @@ public function render($actionName = null): StreamInterface return $this->createStream(parent::render($actionName)); } + public function assign($key, $value): self + { + // layer to fix incompatibility error with typo3 fluid interface + return parent::assign($key, $value); + } + + public function assignMultiple(array $values): self + { + // layer to fix incompatibility error with typo3 fluid interface + return parent::assignMultiple($values); + } + /** * Factory method to create an instance with given options. * * @param array $options - * @return AbstractTemplateView + * @return static */ - public static function createWithOptions(array $options) + public static function createWithOptions(array $options): self { return new static($options); } diff --git a/Neos.FluidAdaptor/Classes/View/StandaloneView.php b/Neos.FluidAdaptor/Classes/View/StandaloneView.php index e738464e68..34252beb07 100644 --- a/Neos.FluidAdaptor/Classes/View/StandaloneView.php +++ b/Neos.FluidAdaptor/Classes/View/StandaloneView.php @@ -65,9 +65,9 @@ class StandaloneView extends AbstractTemplateView * Factory method to create an instance with given options. * * @param array $options - * @return StandaloneView + * @return static */ - public static function createWithOptions(array $options) + public static function createWithOptions(array $options): self { return new static(null, $options); }