Skip to content

Commit

Permalink
Chainable set()
Browse files Browse the repository at this point in the history
  • Loading branch information
euromark committed Dec 11, 2014
1 parent c1a4d03 commit 3f3a875
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/View/ViewVarsTrait.php
Expand Up @@ -93,24 +93,25 @@ public function createView($viewClass = null) {
}

/**
* Saves a variable for use inside a template.
* Saves a variable or an associative array of variables for use inside a template.
*
* @param string|array $name A string or an array of data.
* @param string|array|null $val Value in case $name is a string (which then works as the key).
* @param string|array|null $value Value in case $name is a string (which then works as the key).
* Unused if $name is an associative array, otherwise serves as the values to $name's keys.
* @return void
* @return $this
*/
public function set($name, $val = null) {
public function set($name, $value = null) {
if (is_array($name)) {
if (is_array($val)) {
$data = array_combine($name, $val);
if (is_array($value)) {
$data = array_combine($name, $value);
} else {
$data = $name;
}
} else {
$data = [$name => $val];
$data = [$name => $value];
}
$this->viewVars = $data + $this->viewVars;
return $this;
}

/**
Expand Down

0 comments on commit 3f3a875

Please sign in to comment.