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: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188:
<?php
namespace Nethgui\View;
class LegacyCommandBag extends \ArrayObject implements \Nethgui\Component\DependencyConsumer
{
private $view;
private $currentSelector, $currentOrigin;
private $userNotifications;
public $response;
private $dc;
public function __construct(\Nethgui\View\View $view, \Pimple\Container $dc)
{
parent::__construct(array());
$this->view = $view;
$this->dc = $dc;
}
public function setContext($origin, $selector)
{
$this->currentOrigin = $origin;
$this->currentSelector = $selector;
return $this;
}
public function __call($name, $arguments)
{
$this->getLog()->deprecated();
$receiver = $this->currentOrigin->getUniqueId($this->currentSelector);
$argsArray = $this->prepareArguments($this->view, $arguments);
$this[] = array(
'R' => $receiver,
'M' => $name,
'A' => $argsArray,
);
return $this;
}
public function getLog()
{
return $this->view->getLog();
}
private function prepareArguments(\Nethgui\View\ViewInterface $view, $value)
{
$a = array();
foreach ($value as $k => $v) {
if ($v instanceof \Nethgui\View\ViewableInterface) {
$this->getLog()->deprecated();
} elseif ($v instanceof \Traversable || is_array($v)) {
$v = $this->prepareArguments($view, $v);
}
$a[$k] = $v;
}
return $a;
}
public function httpHeader($value)
{
$this->getLog()->deprecated();
$this->response->addHeader($value);
return $this;
}
public function setDecoratorParameter($paramName, $paramValue)
{
$this->getLog()->deprecated();
$this->dc['decorator.xhtml.params'][$paramName] = $paramValue;
return $this;
}
public function setDecoratorTemplate($template)
{
$this->getLog()->deprecated();
if ($this->dc['View']->getTargetFormat() === 'xhtml') {
$this->dc['decorator.xhtml.template'] = is_callable($template) ? $this->dc->protect($template) : $template;
} else {
$this->dc['View']->setTemplate($template);
}
return $this;
}
public function sendQuery($location)
{
if ($this->view->getTargetFormat() === \Nethgui\View\View::TARGET_JSON) {
return $this->__call('sendQuery', array($location));
}
$this->httpRedirection(302, $location);
return $this;
}
public function showMessage($text, $type)
{
$this->getLog()->deprecated();
if ($type === \Nethgui\Module\Notification\AbstractNotification::NOTIFY_ERROR) {
$this->userNotifications->error($text);
} else {
$this->userNotifications->info($text);
}
}
private function httpRedirection($code, $location)
{
if ( ! in_array(parse_url($location, PHP_URL_SCHEME), array('http', 'https'))) {
$url = $this->view->getSiteUrl() . $location;
}
$this->response
->setStatus(302)
->addHeader('Location: ' . $url)
;
return $this;
}
public function getDependencySetters()
{
$response = &$this->response;
$notifications = &$this->userNotifications;
return array(
'UserNotifications' => function ($n) use (&$notifications) {
$notifications = $n;
},
'HttpResponse' => function ($r) use (&$response) {
$response = $r;
}
);
}
}