Skip to content

Commit

Permalink
Merge pull request #26 from wireframe-framework/dev
Browse files Browse the repository at this point in the history
0.27.0
  • Loading branch information
teppokoivula authored Sep 27, 2022
2 parents f0102b5 + cdc4111 commit 20a960d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.27.0] - 2022-09-26

### Changed
- Stash (and later restore) Wireframe class data array when a page is rendered within another page.
- Include Page object data array in cache key generated by Wireframe::render().

## [0.26.2] - 2022-08-31

### Fixed
Expand Down
17 changes: 12 additions & 5 deletions Wireframe.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @method static string|Page|NullPage page($source, $args = []) Static getter (factory) method for Pages.
* @method static string|null partial(string $partial_name, array $args = []) Static getter (factory) method for Partials.
*
* @version 0.26.2
* @version 0.27.0
* @author Teppo Koivula <[email protected]>
* @license Mozilla Public License v2.0 https://mozilla.org/MPL/2.0/
*/
Expand Down Expand Up @@ -178,20 +178,22 @@ public function ___init(array $settings = []): Wireframe {
return $this;
}

// if page, view, or controller are already set, stash them
if ($this->page || $this->view || $this->controller) {
// if page, view, controller, or data are already set, stash them
if ($this->page || $this->view || $this->controller || !empty($this->data)) {
$this->stash[] = [
'page' => $this->page,
'view' => $this->view,
'controller' => $this->controller,
'data' => $this->data,
];
$this->view = null;
$this->controller = null;
if ($this->page && $this->page->id === $current_page->id && $current_page->_wireframe_controller !== null) {
// if current page is the same as the page being stashed and it has controller defined, discard it;
// we've already stashed the controller, so there's no point in leaving a reference to it in place.
$current_page->_wireframe_controller = null;
}
$this->view = null;
$this->controller = null;
$this->data = [];
}

// set current page
Expand Down Expand Up @@ -779,10 +781,14 @@ public function ___render(array $data = []): ?string {
$ext = $this->ext;
$controller = $view->getController() ?: $this->getController($this->page);

// page data (for cache key)
$page_data = $this->page->data();

// attempt to return prerendered value from cache
$cache_key = implode(':', [
'render',
$this->page->id,
empty($page_data) ? '' : md5(json_encode($page_data)),
$this->settings_hash,
empty($data) ? '' : md5(json_encode($data)),
$view->getTemplate(),
Expand Down Expand Up @@ -848,6 +854,7 @@ public function ___render(array $data = []): ?string {
$this->page = $stashed_context['page'];
$this->view = $stashed_context['view'];
$this->controller = $stashed_context['controller'];
$this->data = $stashed_context['data'];
if ($this->page && $this->controller) {
$this->page->_wireframe_controller = $this->controller;
}
Expand Down

0 comments on commit 20a960d

Please sign in to comment.