1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105:
<?php
namespace Coast\View;
class Content
{
protected $_params = [];
protected $_blocks = [];
public function __construct(array $blocks = array())
{
$this->_blocks = $blocks;
}
public function param($name, $value = null)
{
if (func_num_args() > 1) {
$this->_params[$name] = $value;
return $this;
}
return isset($this->_params[$name])
? $this->_params[$name]
: null;
}
public function params(array $querys = null)
{
if (func_num_args() > 0) {
foreach ($querys as $name => $value) {
$this->param($name, $value);
}
return $this;
}
return $this->_params;
}
public function block($name, $value = null)
{
if (func_num_args() > 1) {
if (isset($name)) {
$this->_blocks[$name] = $value;
} else {
$this->_blocks[] = $value;
}
return $this;
}
return isset($this->_blocks[$name])
? $this->_blocks[$name]
: null;
}
public function blocks(array $blocks = null)
{
if (func_num_args() > 0) {
foreach ($blocks as $name => $value) {
$this->block($name, $value);
}
return $this;
}
return $this->_blocks;
}
public function next()
{
$temp = array_combine($keys = array_keys($this->_blocks), $keys);
$temp[] = null;
end($temp);
return key($temp);
}
public function __set($name, $value)
{
$this->block($name, $value);
}
public function __get($name)
{
return $this->block($name);
}
public function __isset($name)
{
return $this->block($name) !== null;
}
public function __unset($name)
{
$this->block($name, null);
}
public function toString()
{
return implode($this->_blocks);
}
public function __toString()
{
return $this->toString();
}
}