From b6c06553c2a38c45706acdac039351827ba2d97a Mon Sep 17 00:00:00 2001 From: MGatner Date: Thu, 14 Jan 2021 18:00:34 +0000 Subject: [PATCH 1/3] Clarify rendered docblocks --- system/View/RendererInterface.php | 8 ++------ system/View/View.php | 28 ++++++++++++++++------------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/system/View/RendererInterface.php b/system/View/RendererInterface.php index 0128d1c8f696..c8a3b7a6ed1e 100644 --- a/system/View/RendererInterface.php +++ b/system/View/RendererInterface.php @@ -26,9 +26,7 @@ interface RendererInterface * @param array $options Reserved for 3rd-party uses since * it might be needed to pass additional info * to other template engines. - * @param boolean $saveData If true, will save data for use with any other calls, - * if false, will clean the data after displaying the view, - * if not specified, use the config setting. + * @param boolean $saveData Whether to save data for subsequent calls * * @return string */ @@ -44,9 +42,7 @@ public function render(string $view, array $options = null, bool $saveData = fal * @param array $options Reserved for 3rd-party uses since * it might be needed to pass additional info * to other template engines. - * @param boolean $saveData If true, will save data for use with any other calls, - * if false, will clean the data after displaying the view, - * if not specified, use the config setting. + * @param boolean $saveData Whether to save data for subsequent calls * * @return string */ diff --git a/system/View/View.php b/system/View/View.php index 3d98fae92662..9e7093444796 100644 --- a/system/View/View.php +++ b/system/View/View.php @@ -152,12 +152,16 @@ public function __construct(ViewConfig $config, string $viewPath = null, FileLoc * data that has already been set. * * Valid $options: - * - cache number of seconds to cache for - * - cache_name Name to use for cache + * - cache Number of seconds to cache for + * - cache_name Name to use for cache * - * @param string $view - * @param array|null $options - * @param boolean|null $saveData + * @param string $view The view contents + * @param array $options Reserved for 3rd-party uses since + * it might be needed to pass additional info + * to other template engines. + * @param boolean|null $saveData If true, saves data for subsequent calls, + * if false, cleans the data after displaying, + * if null, uses the config setting. * * @return string */ @@ -272,13 +276,13 @@ public function render(string $view, array $options = null, bool $saveData = nul * data that has already been set. * Cache does not apply, because there is no "key". * - * @param string $view The view contents - * @param array $options Reserved for 3rd-party uses since - * it might be needed to pass additional info - * to other template engines. - * @param boolean $saveData If true, will save data for use with any other calls, - * if false, will clean the data after displaying the view, - * if not specified, use the config setting. + * @param string $view The view contents + * @param array $options Reserved for 3rd-party uses since + * it might be needed to pass additional info + * to other template engines. + * @param boolean|null $saveData If true, saves data for subsequent calls, + * if false, cleans the data after displaying, + * if null, uses the config setting. * * @return string */ From 0489678a54d0a4dab534cb1aaaece3faac459ec3 Mon Sep 17 00:00:00 2001 From: MGatner Date: Thu, 14 Jan 2021 18:08:52 +0000 Subject: [PATCH 2/3] Update UG --- system/View/View.php | 2 +- user_guide_src/source/outgoing/view_renderer.rst | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/system/View/View.php b/system/View/View.php index 9e7093444796..21094d64fb7d 100644 --- a/system/View/View.php +++ b/system/View/View.php @@ -155,7 +155,7 @@ public function __construct(ViewConfig $config, string $viewPath = null, FileLoc * - cache Number of seconds to cache for * - cache_name Name to use for cache * - * @param string $view The view contents + * @param string $view File name of the view source * @param array $options Reserved for 3rd-party uses since * it might be needed to pass additional info * to other template engines. diff --git a/user_guide_src/source/outgoing/view_renderer.rst b/user_guide_src/source/outgoing/view_renderer.rst index a55d848accae..e77413cbb97a 100644 --- a/user_guide_src/source/outgoing/view_renderer.rst +++ b/user_guide_src/source/outgoing/view_renderer.rst @@ -102,6 +102,9 @@ Several options can be passed to the ``render()`` or ``renderString()`` methods: ignored for renderString() - ``saveData`` - true if the view data parameters should be retained for subsequent calls +.. note:: ``saveData`` as defined by the interface must be a boolean, but implementing + classes (like ``View`` below) may extend this to include ``null`` values. + Class Reference *************** @@ -110,9 +113,9 @@ Class Reference .. php:method:: render($view[, $options[, $saveData=false]]) :noindex: - :param string $view: File name of the view source - :param array $options: Array of options, as key/value pairs - :param boolean $saveData: If true, will save data for use with any other calls, if false, will clean the data after rendering the view. + :param string $view: File name of the view source + :param array $options: Array of options, as key/value pairs + :param boolean|null $saveData: If true, will save data for use with any other calls. If false, will clean the data after rendering the view. If null, uses the config setting. :returns: The rendered text for the chosen view :rtype: string @@ -123,9 +126,9 @@ Class Reference .. php:method:: renderString($view[, $options[, $saveData=false]]) :noindex: - :param string $view: Contents of the view to render, for instance content retrieved from a database - :param array $options: Array of options, as key/value pairs - :param boolean $saveData: If true, will save data for use with any other calls, if false, will clean the data after rendering the view. + :param string $view: Contents of the view to render, for instance content retrieved from a database + :param array $options: Array of options, as key/value pairs + :param boolean|null $saveData: If true, will save data for use with any other calls. If false, will clean the data after rendering the view. If null, uses the config setting. :returns: The rendered text for the chosen view :rtype: string From 143088719f82b5156ea6518390d0c51beada9514 Mon Sep 17 00:00:00 2001 From: MGatner Date: Fri, 15 Jan 2021 14:41:21 +0000 Subject: [PATCH 3/3] Implement review fixes --- system/Config/View.php | 8 ++++++++ system/View/View.php | 8 ++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/system/Config/View.php b/system/Config/View.php index 6788b75b18ed..b57d94167422 100644 --- a/system/Config/View.php +++ b/system/Config/View.php @@ -16,6 +16,14 @@ */ class View extends BaseConfig { + /** + * When false, the view method will clear the data between each + * call. + * + * @var boolean + */ + public $saveData = true; + /** * Parser Filters map a filter name with any PHP callable. When the * Parser prepares a variable for display, it will chain it diff --git a/system/View/View.php b/system/View/View.php index 21094d64fb7d..a9f190afefdb 100644 --- a/system/View/View.php +++ b/system/View/View.php @@ -142,7 +142,7 @@ public function __construct(ViewConfig $config, string $viewPath = null, FileLoc $this->loader = $loader ?? Services::locator(); $this->logger = $logger ?? Services::logger(); $this->debug = $debug ?? CI_DEBUG; - $this->saveData = $config->saveData ?? null; + $this->saveData = (bool) $config->saveData; } //-------------------------------------------------------------------- @@ -156,7 +156,7 @@ public function __construct(ViewConfig $config, string $viewPath = null, FileLoc * - cache_name Name to use for cache * * @param string $view File name of the view source - * @param array $options Reserved for 3rd-party uses since + * @param array|null $options Reserved for 3rd-party uses since * it might be needed to pass additional info * to other template engines. * @param boolean|null $saveData If true, saves data for subsequent calls, @@ -176,7 +176,7 @@ public function render(string $view, array $options = null, bool $saveData = nul $fileExt = pathinfo($view, PATHINFO_EXTENSION); $realPath = empty($fileExt) ? $view . '.php' : $view; // allow Views as .html, .tpl, etc (from CI3) $this->renderVars['view'] = $realPath; - $this->renderVars['options'] = $options; + $this->renderVars['options'] = $options ?? []; // Was it cached? if (isset($this->renderVars['options']['cache'])) @@ -277,7 +277,7 @@ public function render(string $view, array $options = null, bool $saveData = nul * Cache does not apply, because there is no "key". * * @param string $view The view contents - * @param array $options Reserved for 3rd-party uses since + * @param array|null $options Reserved for 3rd-party uses since * it might be needed to pass additional info * to other template engines. * @param boolean|null $saveData If true, saves data for subsequent calls,