From 91063f0de637ec36e136f31e3e298dd811040fd3 Mon Sep 17 00:00:00 2001 From: xeonbb Date: Thu, 16 Apr 2020 03:04:05 -0600 Subject: [PATCH 1/8] Now it allows to send a result without the name of the variable that is used when the result is assigned, when the result is more than one variable, then if it took the name of each variable to use it as a key --- src/View/JsonView.php | 104 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 103 insertions(+), 1 deletion(-) diff --git a/src/View/JsonView.php b/src/View/JsonView.php index 07a800e..6ebf5fc 100644 --- a/src/View/JsonView.php +++ b/src/View/JsonView.php @@ -4,6 +4,7 @@ use Cake\Core\Exception\Exception; use Cake\View\View; +use Cake\Core\Configure; /** * Json View @@ -13,6 +14,13 @@ class JsonView extends View { + /** + * List of special view vars. + * + * @var array + */ + protected $_specialVars = ['_serialize', '_jsonOptions', '_jsonp']; + /** * Renders api response * @@ -41,12 +49,106 @@ public function render($view = null, $layout = null) $content['status'] = "NOK"; } - $content['result'] = $this->viewVars; + /** + Auto serialization + **/ + if ( !@$this->viewVars['_serialize'] ){ + + foreach( $this->viewVars as $name => $values ){ + if ( $name != 'status' ){ + $this->viewVars['_serialize'][] = $name; + } + } + if ( count($this->viewVars['_serialize']) === 1 ){ + $this->viewVars['_serialize'] = $this->viewVars['_serialize'][0]; + } + } + + $content['result'] = $this->renderResult($this->viewVars); + /** + / Auto serialization + **/ + $this->Blocks->set('content', $this->renderLayout(json_encode($content), $this->layout)); $this->hasRendered = true; return $this->Blocks->get('content'); } + + public function renderResult($view = null, $layout = null) + { + $serialize = false; + if (isset($this->viewVars['_serialize'])) { + $serialize = $this->viewVars['_serialize']; + } + + if ($serialize !== false) { + $result = $this->_serialize($serialize); + if ($result === false) { + throw new RuntimeException('Serialization of View data failed.'); + } + + return (string)$result; + } + if ($view !== false && $this->_getViewFileName($view)) { + return parent::render($view, false); + } + } + + /* SerializedView Methods */ + protected function _serialize($serialize) + { + $data = $this->_dataToSerialize($serialize); + + $jsonOptions = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | + JSON_PARTIAL_OUTPUT_ON_ERROR; + + if (isset($this->viewVars['_jsonOptions'])) { + if ($this->viewVars['_jsonOptions'] === false) { + $jsonOptions = 0; + } else { + $jsonOptions = $this->viewVars['_jsonOptions']; + } + } + + if (Configure::read('debug')) { + $jsonOptions |= JSON_PRETTY_PRINT; + } + + return json_encode($data, $jsonOptions); + } + + protected function _dataToSerialize($serialize = true) + { + if ($serialize === true) { + $data = array_diff_key( + $this->viewVars, + array_flip($this->_specialVars) + ); + + if (empty($data)) { + return null; + } + + return $data; + } + + if (is_array($serialize)) { + $data = []; + foreach ($serialize as $alias => $key) { + if (is_numeric($alias)) { + $alias = $key; + } + if (array_key_exists($key, $this->viewVars)) { + $data[$alias] = $this->viewVars[$key]; + } + } + + return !empty($data) ? $data : null; + } + + return isset($this->viewVars[$serialize]) ? $this->viewVars[$serialize] : null; + } } From bdef4fea752e8ec2403f935fc45a6da6f958ffb9 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 16 Apr 2020 09:11:14 +0000 Subject: [PATCH 2/8] Fixing style errors. --- src/View/JsonView.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/View/JsonView.php b/src/View/JsonView.php index 6ebf5fc..525ff58 100644 --- a/src/View/JsonView.php +++ b/src/View/JsonView.php @@ -49,27 +49,26 @@ public function render($view = null, $layout = null) $content['status'] = "NOK"; } - /** - Auto serialization - **/ - if ( !@$this->viewVars['_serialize'] ){ - - foreach( $this->viewVars as $name => $values ){ - if ( $name != 'status' ){ + /** + Auto serialization + **/ + if (!@$this->viewVars['_serialize']) { + foreach ($this->viewVars as $name => $values) { + if ($name != 'status') { $this->viewVars['_serialize'][] = $name; } } - if ( count($this->viewVars['_serialize']) === 1 ){ + if (count($this->viewVars['_serialize']) === 1) { $this->viewVars['_serialize'] = $this->viewVars['_serialize'][0]; } } $content['result'] = $this->renderResult($this->viewVars); - /** - / Auto serialization - **/ - + /** + / Auto serialization + **/ + $this->Blocks->set('content', $this->renderLayout(json_encode($content), $this->layout)); $this->hasRendered = true; @@ -97,7 +96,8 @@ public function renderResult($view = null, $layout = null) } } - /* SerializedView Methods */ + /* SerializedView Methods */ + protected function _serialize($serialize) { $data = $this->_dataToSerialize($serialize); From e9419b3c1001e96b3a953d2b1aaf719873b3323e Mon Sep 17 00:00:00 2001 From: xeonbb Date: Thu, 16 Apr 2020 03:28:42 -0600 Subject: [PATCH 3/8] Github suggestions --- src/View/JsonView.php | 49 +++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/src/View/JsonView.php b/src/View/JsonView.php index 6ebf5fc..3970484 100644 --- a/src/View/JsonView.php +++ b/src/View/JsonView.php @@ -45,14 +45,12 @@ public function render($view = null, $layout = null) $code = $this->response->getStatusCode(); + if ($code != 200) { $content['status'] = "NOK"; } - /** - Auto serialization - **/ - if ( !@$this->viewVars['_serialize'] ){ + if ( !isset($this->viewVars['_serialize']) ){ foreach( $this->viewVars as $name => $values ){ if ( $name != 'status' ){ @@ -60,16 +58,20 @@ public function render($view = null, $layout = null) } } - if ( count($this->viewVars['_serialize']) === 1 ){ - $this->viewVars['_serialize'] = $this->viewVars['_serialize'][0]; + if ( isset($this->viewVars['_serialize']) ){ + if ( count($this->viewVars['_serialize']) === 1 ){ + $this->viewVars['_serialize'] = $this->viewVars['_serialize'][0]; + } + } + else{ + $content['status'] = "NOK"; + $this->viewVars['message'] = ['message' => 'empty response']; + $this->viewVars['_serialize'] = 'message'; } } $content['result'] = $this->renderResult($this->viewVars); - /** - / Auto serialization - **/ - + $this->Blocks->set('content', $this->renderLayout(json_encode($content), $this->layout)); $this->hasRendered = true; @@ -77,6 +79,14 @@ public function render($view = null, $layout = null) return $this->Blocks->get('content'); } + /** + * Cumstom Render for api response + * + * @param string|null $view Name of view file to use + * @param string|null $layout Layout to use. + * @return string|null Rendered content or null if content already rendered and returned earlier. + * @throws Exception If there is an error in the view. + */ public function renderResult($view = null, $layout = null) { $serialize = false; @@ -97,7 +107,17 @@ public function renderResult($view = null, $layout = null) } } - /* SerializedView Methods */ + /** + * Serialize view vars + * + * ### Special parameters + * `_jsonOptions` You can set custom options for json_encode() this way, + * e.g. `JSON_HEX_TAG | JSON_HEX_APOS`. + * + * @param array|string|bool $serialize The name(s) of the view variable(s) + * that need(s) to be serialized. If true all available view variables. + * @return string|false The serialized data, or boolean false if not serializable. + */ protected function _serialize($serialize) { $data = $this->_dataToSerialize($serialize); @@ -120,6 +140,13 @@ protected function _serialize($serialize) return json_encode($data, $jsonOptions); } + /** + * Returns data to be serialized. + * + * @param array|string|bool $serialize The name(s) of the view variable(s) that + * need(s) to be serialized. If true all available view variables will be used. + * @return mixed The data to serialize. + */ protected function _dataToSerialize($serialize = true) { if ($serialize === true) { From 9ba8e6bcc6cfb05ce763bc19bb17ec4e555214c1 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 16 Apr 2020 09:39:01 +0000 Subject: [PATCH 4/8] Fixing style errors. --- src/View/JsonView.php | 129 +++++++++++++++++++++--------------------- 1 file changed, 64 insertions(+), 65 deletions(-) diff --git a/src/View/JsonView.php b/src/View/JsonView.php index 1f01abc..013bf80 100644 --- a/src/View/JsonView.php +++ b/src/View/JsonView.php @@ -21,53 +21,52 @@ class JsonView extends View */ protected $_specialVars = ['_serialize', '_jsonOptions', '_jsonp']; - /** - * Renders api response - * - * @param string|null $view Name of view file to use - * @param string|null $layout Layout to use. - * @return string|null Rendered content or null if content already rendered and returned earlier. - * @throws Exception If there is an error in the view. - */ - public function render($view = null, $layout = null) +/** + * Renders api response + * + * @param string|null $view Name of view file to use + * @param string|null $layout Layout to use. + * @return string|null Rendered content or null if content already rendered and returned earlier. + * @throws Exception If there is an error in the view. + */ +public function render($view = null, $layout = null) { - if ($this->hasRendered) { - return null; - } +if ($this->hasRendered) { + return null; +} $this->response = $this->response->withType('json'); $this->layout = "Rest.rest"; $content = [ - 'status' => 'OK' + 'status' => 'OK', ]; $code = $this->response->getStatusCode(); - if ($code != 200) { $content['status'] = "NOK"; } -<<<<<<< HEAD + << << <<< HEAD if ( !isset($this->viewVars['_serialize']) ){ foreach( $this->viewVars as $name => $values ){ if ( $name != 'status' ){ -======= + ======= /** Auto serialization **/ if (!@$this->viewVars['_serialize']) { foreach ($this->viewVars as $name => $values) { if ($name != 'status') { ->>>>>>> bdef4fea752e8ec2403f935fc45a6da6f958ffb9 + >>>>>>> bdef4fea752e8ec2403f935fc45a6da6f958ffb9 $this->viewVars['_serialize'][] = $name; } } -<<<<<<< HEAD + <<<<<<< HEAD if ( isset($this->viewVars['_serialize']) ){ if ( count($this->viewVars['_serialize']) === 1 ){ $this->viewVars['_serialize'] = $this->viewVars['_serialize'][0]; @@ -77,38 +76,38 @@ public function render($view = null, $layout = null) $content['status'] = "NOK"; $this->viewVars['message'] = ['message' => 'empty response']; $this->viewVars['_serialize'] = 'message'; -======= + ======= if (count($this->viewVars['_serialize']) === 1) { $this->viewVars['_serialize'] = $this->viewVars['_serialize'][0]; ->>>>>>> bdef4fea752e8ec2403f935fc45a6da6f958ffb9 + >>>>>>> bdef4fea752e8ec2403f935fc45a6da6f958ffb9 } } $content['result'] = $this->renderResult($this->viewVars); -<<<<<<< HEAD -======= + <<<<<<< HEAD + ======= /** / Auto serialization **/ ->>>>>>> bdef4fea752e8ec2403f935fc45a6da6f958ffb9 + >>>>>>> bdef4fea752e8ec2403f935fc45a6da6f958ffb9 $this->Blocks->set('content', $this->renderLayout(json_encode($content), $this->layout)); $this->hasRendered = true; return $this->Blocks->get('content'); - } + } - /** - * Cumstom Render for api response - * - * @param string|null $view Name of view file to use - * @param string|null $layout Layout to use. - * @return string|null Rendered content or null if content already rendered and returned earlier. - * @throws Exception If there is an error in the view. - */ - public function renderResult($view = null, $layout = null) - { + /** + * Cumstom Render for api response + * + * @param string|null $view Name of view file to use + * @param string|null $layout Layout to use. + * @return string|null Rendered content or null if content already rendered and returned earlier. + * @throws Exception If there is an error in the view. + */ + public function renderResult($view = null, $layout = null) + { $serialize = false; if (isset($this->viewVars['_serialize'])) { $serialize = $this->viewVars['_serialize']; @@ -125,26 +124,26 @@ public function renderResult($view = null, $layout = null) if ($view !== false && $this->_getViewFileName($view)) { return parent::render($view, false); } - } - -<<<<<<< HEAD - /** - * Serialize view vars - * - * ### Special parameters - * `_jsonOptions` You can set custom options for json_encode() this way, - * e.g. `JSON_HEX_TAG | JSON_HEX_APOS`. - * - * @param array|string|bool $serialize The name(s) of the view variable(s) - * that need(s) to be serialized. If true all available view variables. - * @return string|false The serialized data, or boolean false if not serializable. - */ -======= - /* SerializedView Methods */ + } ->>>>>>> bdef4fea752e8ec2403f935fc45a6da6f958ffb9 - protected function _serialize($serialize) - { + <<<<<<< HEAD + /** + * Serialize view vars + * + * ### Special parameters + * `_jsonOptions` You can set custom options for json_encode() this way, + * e.g. `JSON_HEX_TAG | JSON_HEX_APOS`. + * + * @param array|string|bool $serialize The name(s) of the view variable(s) + * that need(s) to be serialized. If true all available view variables. + * @return string|false The serialized data, or boolean false if not serializable. + */ + ======= + /* SerializedView Methods */ + + >>>>>>> bdef4fea752e8ec2403f935fc45a6da6f958ffb9 + protected function _serialize($serialize) + { $data = $this->_dataToSerialize($serialize); $jsonOptions = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | @@ -163,17 +162,17 @@ protected function _serialize($serialize) } return json_encode($data, $jsonOptions); - } + } - /** - * Returns data to be serialized. - * - * @param array|string|bool $serialize The name(s) of the view variable(s) that - * need(s) to be serialized. If true all available view variables will be used. - * @return mixed The data to serialize. - */ - protected function _dataToSerialize($serialize = true) - { + /** + * Returns data to be serialized. + * + * @param array|string|bool $serialize The name(s) of the view variable(s) that + * need(s) to be serialized. If true all available view variables will be used. + * @return mixed The data to serialize. + */ + protected function _dataToSerialize($serialize = true) + { if ($serialize === true) { $data = array_diff_key( $this->viewVars, @@ -202,5 +201,5 @@ protected function _dataToSerialize($serialize = true) } return isset($this->viewVars[$serialize]) ? $this->viewVars[$serialize] : null; - } -} + } + } From 8c2a3cc0bc037ad6e2215ffe5e75878a0d89ba8b Mon Sep 17 00:00:00 2001 From: xeonbb Date: Thu, 16 Apr 2020 08:38:11 -0600 Subject: [PATCH 5/8] Fixing style errors --- src/View/JsonView.php | 129 +++++++++++++++++------------------------- 1 file changed, 53 insertions(+), 76 deletions(-) diff --git a/src/View/JsonView.php b/src/View/JsonView.php index 013bf80..c57c798 100644 --- a/src/View/JsonView.php +++ b/src/View/JsonView.php @@ -2,9 +2,9 @@ namespace Rest\View; +use Cake\Core\Configure; use Cake\Core\Exception\Exception; use Cake\View\View; -use Cake\Core\Configure; /** * Json View @@ -21,52 +21,44 @@ class JsonView extends View */ protected $_specialVars = ['_serialize', '_jsonOptions', '_jsonp']; -/** - * Renders api response - * - * @param string|null $view Name of view file to use - * @param string|null $layout Layout to use. - * @return string|null Rendered content or null if content already rendered and returned earlier. - * @throws Exception If there is an error in the view. - */ -public function render($view = null, $layout = null) + /** + * Renders api response + * + * @param string|null $view Name of view file to use + * @param string|null $layout Layout to use. + * @return string|null Rendered content or null if content already rendered and returned earlier. + * @throws Exception If there is an error in the view. + */ + public function render($view = null, $layout = null) { -if ($this->hasRendered) { - return null; -} + if ($this->hasRendered) { + + return null ; + } $this->response = $this->response->withType('json'); $this->layout = "Rest.rest"; $content = [ - 'status' => 'OK', + 'status' => 'OK' ]; $code = $this->response->getStatusCode(); + if ($code != 200) { $content['status'] = "NOK"; } - << << <<< HEAD if ( !isset($this->viewVars['_serialize']) ){ foreach( $this->viewVars as $name => $values ){ if ( $name != 'status' ){ - ======= - /** - Auto serialization - **/ - if (!@$this->viewVars['_serialize']) { - foreach ($this->viewVars as $name => $values) { - if ($name != 'status') { - >>>>>>> bdef4fea752e8ec2403f935fc45a6da6f958ffb9 $this->viewVars['_serialize'][] = $name; } } - <<<<<<< HEAD if ( isset($this->viewVars['_serialize']) ){ if ( count($this->viewVars['_serialize']) === 1 ){ $this->viewVars['_serialize'] = $this->viewVars['_serialize'][0]; @@ -76,38 +68,28 @@ public function render($view = null, $layout = null) $content['status'] = "NOK"; $this->viewVars['message'] = ['message' => 'empty response']; $this->viewVars['_serialize'] = 'message'; - ======= - if (count($this->viewVars['_serialize']) === 1) { - $this->viewVars['_serialize'] = $this->viewVars['_serialize'][0]; - >>>>>>> bdef4fea752e8ec2403f935fc45a6da6f958ffb9 } } $content['result'] = $this->renderResult($this->viewVars); - <<<<<<< HEAD - ======= - /** - / Auto serialization - **/ - >>>>>>> bdef4fea752e8ec2403f935fc45a6da6f958ffb9 $this->Blocks->set('content', $this->renderLayout(json_encode($content), $this->layout)); $this->hasRendered = true; return $this->Blocks->get('content'); - } + } - /** - * Cumstom Render for api response - * - * @param string|null $view Name of view file to use - * @param string|null $layout Layout to use. - * @return string|null Rendered content or null if content already rendered and returned earlier. - * @throws Exception If there is an error in the view. - */ - public function renderResult($view = null, $layout = null) - { + /** + * Cumstom Render for api response + * + * @param string|null $view Name of view file to use + * @param string|null $layout Layout to use. + * @return string|null Rendered content or null if content already rendered and returned earlier. + * @throws Exception If there is an error in the view. + */ + public function renderResult($view = null, $layout = null) + { $serialize = false; if (isset($this->viewVars['_serialize'])) { $serialize = $this->viewVars['_serialize']; @@ -124,26 +106,21 @@ public function renderResult($view = null, $layout = null) if ($view !== false && $this->_getViewFileName($view)) { return parent::render($view, false); } - } + } - <<<<<<< HEAD - /** - * Serialize view vars - * - * ### Special parameters - * `_jsonOptions` You can set custom options for json_encode() this way, - * e.g. `JSON_HEX_TAG | JSON_HEX_APOS`. - * - * @param array|string|bool $serialize The name(s) of the view variable(s) - * that need(s) to be serialized. If true all available view variables. - * @return string|false The serialized data, or boolean false if not serializable. - */ - ======= - /* SerializedView Methods */ - - >>>>>>> bdef4fea752e8ec2403f935fc45a6da6f958ffb9 - protected function _serialize($serialize) - { + /** + * Serialize view vars + * + * ### Special parameters + * `_jsonOptions` You can set custom options for json_encode() this way, + * e.g. `JSON_HEX_TAG | JSON_HEX_APOS`. + * + * @param array|string|bool $serialize The name(s) of the view variable(s) + * that need(s) to be serialized. If true all available view variables. + * @return string|false The serialized data, or boolean false if not serializable. + */ + protected function _serialize($serialize) + { $data = $this->_dataToSerialize($serialize); $jsonOptions = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | @@ -162,17 +139,17 @@ protected function _serialize($serialize) } return json_encode($data, $jsonOptions); - } + } - /** - * Returns data to be serialized. - * - * @param array|string|bool $serialize The name(s) of the view variable(s) that - * need(s) to be serialized. If true all available view variables will be used. - * @return mixed The data to serialize. - */ - protected function _dataToSerialize($serialize = true) - { + /** + * Returns data to be serialized. + * + * @param array|string|bool $serialize The name(s) of the view variable(s) that + * need(s) to be serialized. If true all available view variables will be used. + * @return mixed The data to serialize. + */ + protected function _dataToSerialize($serialize = true) + { if ($serialize === true) { $data = array_diff_key( $this->viewVars, @@ -201,5 +178,5 @@ protected function _dataToSerialize($serialize = true) } return isset($this->viewVars[$serialize]) ? $this->viewVars[$serialize] : null; - } - } + } +} From 58c82639b3bd4f33a84c2fb5192a017556fd8a9b Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 16 Apr 2020 14:38:58 +0000 Subject: [PATCH 6/8] Fixing style errors. --- src/View/JsonView.php | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/View/JsonView.php b/src/View/JsonView.php index c57c798..f8acaee 100644 --- a/src/View/JsonView.php +++ b/src/View/JsonView.php @@ -32,8 +32,7 @@ class JsonView extends View public function render($view = null, $layout = null) { if ($this->hasRendered) { - - return null ; + return null; } $this->response = $this->response->withType('json'); @@ -41,30 +40,27 @@ public function render($view = null, $layout = null) $this->layout = "Rest.rest"; $content = [ - 'status' => 'OK' + 'status' => 'OK', ]; $code = $this->response->getStatusCode(); - if ($code != 200) { $content['status'] = "NOK"; } - if ( !isset($this->viewVars['_serialize']) ){ - - foreach( $this->viewVars as $name => $values ){ - if ( $name != 'status' ){ + if (!isset($this->viewVars['_serialize'])) { + foreach ($this->viewVars as $name => $values) { + if ($name != 'status') { $this->viewVars['_serialize'][] = $name; } } - if ( isset($this->viewVars['_serialize']) ){ - if ( count($this->viewVars['_serialize']) === 1 ){ + if (isset($this->viewVars['_serialize'])) { + if (count($this->viewVars['_serialize']) === 1) { $this->viewVars['_serialize'] = $this->viewVars['_serialize'][0]; } - } - else{ + } else { $content['status'] = "NOK"; $this->viewVars['message'] = ['message' => 'empty response']; $this->viewVars['_serialize'] = 'message'; From 10869b46fa312561f3aa199af36839600aea929f Mon Sep 17 00:00:00 2001 From: xeonbb Date: Sun, 26 Jul 2020 15:07:29 -0600 Subject: [PATCH 7/8] tag 1.2 Adding cakephp 4 to requirements --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index db82306..7777e02 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ }, "require": { "php": ">=5.6.0", - "cakephp/cakephp": "^3.4.0", + "cakephp/cakephp": "4.*", "firebase/php-jwt": "^5.0" }, "require-dev": { From f7d52d5bd07b059b06ea9a587bee22937e8da407 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Sun, 26 Jul 2020 21:14:18 +0000 Subject: [PATCH 8/8] Fixing style errors. --- src/View/JsonView.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/View/JsonView.php b/src/View/JsonView.php index f8acaee..e815cfc 100644 --- a/src/View/JsonView.php +++ b/src/View/JsonView.php @@ -61,7 +61,7 @@ public function render($view = null, $layout = null) $this->viewVars['_serialize'] = $this->viewVars['_serialize'][0]; } } else { - $content['status'] = "NOK"; + $content['status'] = 'NOK'; $this->viewVars['message'] = ['message' => 'empty response']; $this->viewVars['_serialize'] = 'message'; } @@ -82,7 +82,7 @@ public function render($view = null, $layout = null) * @param string|null $view Name of view file to use * @param string|null $layout Layout to use. * @return string|null Rendered content or null if content already rendered and returned earlier. - * @throws Exception If there is an error in the view. + * @throws \Cake\Core\Exception\Exception If there is an error in the view. */ public function renderResult($view = null, $layout = null) { @@ -173,6 +173,6 @@ protected function _dataToSerialize($serialize = true) return !empty($data) ? $data : null; } - return isset($this->viewVars[$serialize]) ? $this->viewVars[$serialize] : null; + return $this->viewVars[$serialize] ?? null; } }