From 7ee83329d9e34ba15db170d08069e8eca9bc4b78 Mon Sep 17 00:00:00 2001 From: pzinovkin Date: Fri, 26 Mar 2010 08:49:33 +0000 Subject: [PATCH] Added View methods append & preprend, #16 git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/branches/evo@135 4cb57b5f-5bbd-dd11-951b-001d605cbbc5 --- layout/Layout.php | 20 ++++++++++++++++++++ view/PHPView.php | 32 +++++++++++++++++++++++++++++++- view/iView.php | 2 ++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/layout/Layout.php b/layout/Layout.php index 03952f2..9c5eaae 100644 --- a/layout/Layout.php +++ b/layout/Layout.php @@ -33,6 +33,26 @@ abstract class Layout $this->view->assign($name, $action->fetch()); } + + /** + * @param string $name + * @param Action $action + */ + protected function append($name, $action) + { + $this->view->append($name, $action->fetch()); + } + + + /** + * @param string $name + * @param Action $action + */ + protected function prepend($name, $action) + { + $this->view->prepend($name, $action->fetch()); + } + abstract protected function execute(); /** diff --git a/view/PHPView.php b/view/PHPView.php index 32c3634..2d53292 100644 --- a/view/PHPView.php +++ b/view/PHPView.php @@ -24,7 +24,7 @@ class PHPView implements iView public function __construct($config) { if (!isset($config['path'])) { - throw new Exception('Configuration must have a "path".'); + throw new Exception('Configuration must have a "path" set.'); } $this->setPath($config['path']); } @@ -49,11 +49,41 @@ class PHPView implements iView } } + /** + * @param string $name + * @param mixed $value + */ public function assign($name, $value = null) { $this->variables[$name] = $value; } + /** + * @param string $name + * @param mixed $value + */ + public function prepend($name, $value) + { + if (isset($this->variables[$name])) { + $this->variables[$name] = $value . $this->variables[$name]; + } else { + $this->variables[$name] = $value; + } + } + + /** + * @param string $name + * @param mixed $value + */ + public function append($name, $value) + { + if (isset($this->variables[$name])) { + $this->variables[$name] .= $value; + } else { + $this->variables[$name] = $value; + } + } + public function fetch($template) { $this->template = $this->getTemplatePath($template); diff --git a/view/iView.php b/view/iView.php index 38f5467..b471c03 100644 --- a/view/iView.php +++ b/view/iView.php @@ -12,5 +12,7 @@ interface iView { public function assign($name, $value = null); + public function prepend($name, $value); + public function append($name, $value); public function fetch($template); } \ No newline at end of file