Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify Renderer discrepancy #4102

Merged
merged 3 commits into from
Jan 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions system/Config/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's can be false by default - RendererInterface::render(string $view, array $options = null, bool $saveData = false)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is true in app/Config/View.php which extends this, so I think it makes more sense to mirror that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MGatner why not same to RendererInterface::render()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no clue, I didn't write any of this. Probably a mistake or miscommunication among earlier devs. At this point though we have a public interface which we can't change and an App config file which we could change but would need to note in docs - I think keeping the config files consistent even though they don't match the interface makes the most sense given the mess it already is.


/**
* Parser Filters map a filter name with any PHP callable. When the
* Parser prepares a variable for display, it will chain it
Expand Down
8 changes: 2 additions & 6 deletions system/View/RendererInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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
*/
Expand Down
32 changes: 18 additions & 14 deletions system/View/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
paulbalandan marked this conversation as resolved.
Show resolved Hide resolved
}

//--------------------------------------------------------------------
Expand All @@ -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 File name of the view source
* @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,
* if false, cleans the data after displaying,
* if null, uses the config setting.
*
* @return string
*/
Expand All @@ -172,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']))
Expand Down Expand Up @@ -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|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,
* if false, cleans the data after displaying,
* if null, uses the config setting.
*
* @return string
*/
Expand Down
15 changes: 9 additions & 6 deletions user_guide_src/source/outgoing/view_renderer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
***************

Expand All @@ -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

Expand All @@ -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

Expand Down