This repository has been archived by the owner on Jan 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 195
Adding parameters to templates before render-time #143
Merged
weierophinney
merged 15 commits into
zendframework:develop
from
kynx:template-add-parameter
Oct 10, 2015
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
20aa249
TemplateInterface::addParameters() method for building up parameters …
kynx ff7f176
Fixed failing tests
kynx 52f7f18
Fix for adding shared params to Plates. Default for template name now…
kynx 97a8087
Fix for adding shared params to Plates. Default for template name now…
kynx b246c91
CS fix
kynx 8cd7645
Added Plates tests
kynx d0ce891
Merge branch 'feature/uri-generation-encoding' into develop
weierophinney d30bbbd
TemplateInterface::addParameters() method for building up parameters …
kynx 3e750a4
Fixed failing tests
kynx 561855f
Fix for adding shared params to Plates. Default for template name now…
kynx cd52672
Fix for adding shared params to Plates. Default for template name now…
kynx ddcf662
CS fix
kynx 7d8334f
Added Plates tests
kynx 203402f
Merge branch 'template-add-parameter' of github.com:kynx/zend-express…
kynx 7cdab23
Changed PlatesTemplate to PlatesRenderer in tests
kynx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @see https://github.com/zendframework/zend-expressive for the canonical source repository | ||
* @copyright Copyright (c) 2015 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license https://github.com/zendframework/zend-expressive/blob/master/LICENSE.md New BSD License | ||
*/ | ||
|
||
namespace Zend\Expressive\Template; | ||
|
||
trait AddParametersTrait | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
protected $templateParams = []; | ||
|
||
/** | ||
* Add parameters to template | ||
* | ||
* If no template name is given, the parameters will be added to all templates rendered | ||
* | ||
* @param array|object $params | ||
* @param string|null $name | ||
*/ | ||
public function addParameters($params, $name = null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method also needs to be added to the interface; otherwise, an implementation could omit it, leaving developers depending on concretions instead of abstractions. |
||
{ | ||
if (method_exists($this, 'normalizeParams')) { | ||
$params = $this->normalizeParams($params); | ||
} | ||
$name = (string) $name; | ||
$existing = isset($this->templateParams[$name]) ? $this->templateParams[$name] : null; | ||
$this->templateParams[$name] = array_merge($existing, $params, $name); | ||
} | ||
|
||
/** | ||
* Returns merged global, template-specific and given params | ||
* | ||
* @param array $params | ||
* @param string $name | ||
* @return array | ||
*/ | ||
protected function mergeParams($params, $name) | ||
{ | ||
return array_merge( | ||
isset($this->templateParams['']) ? $this->templateParams[''] : [], | ||
isset($this->templateParams[$name]) ? $this->templateParams[$name] : [], | ||
$params | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<h1>This is a second template file for Plates</h1> | ||
|
||
<p>You are using <strong><?=$this->e($name)?></strong>!</p> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since these members (this and the
mergeParameters()
method) are in the trait, they can beprivate
visibility.