1: <?php
2:
3: /**
4: * Picon Framework
5: * http://code.google.com/p/picon-framework/
6: *
7: * Copyright (C) 2011-2012 Martin Cassidy <martin.cassidy@webquub.com>
8:
9: * Picon Framework is free software: you can redistribute it and/or modify
10: * it under the terms of the GNU General Public License as published by
11: * the Free Software Foundation, either version 3 of the License, or
12: * (at your option) any later version.
13:
14: * Picon Framework is distributed in the hope that it will be useful,
15: * but WITHOUT ANY WARRANTY; without even the implied warranty of
16: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: * General Public License for more details.
18:
19: * You should have received a copy of the GNU General Public License
20: * along with Picon Framework. If not, see <http://www.gnu.org/licenses/>.
21: * */
22:
23: namespace picon;
24:
25: /**
26: * Stateless page request that will retrieve and invoke a listener on the page
27: *
28: * @author Martin Cassidy
29: * @package web/request/target
30: */
31: class PageRequestWithListenerTarget extends PageRequestTarget
32: {
33: private $componentPath;
34: private $behaviour;
35:
36: /**
37: *
38: * @param string $page The name of the page
39: * @param type $componentPath The path to the listener component
40: */
41: public function __construct(Identifier $pageClass, $componentPath, $behaviour = null)
42: {
43: parent::__construct($pageClass);
44: $this->componentPath = $componentPath;
45: $this->behaviour = $behaviour;
46: }
47:
48: public function respond(Response $response)
49: {
50: $fullClassName = $this->getPageClass()->getFullyQualifiedName();
51: $page = new $fullClassName();
52: $page->beforePageRender();
53:
54: $listener = null;
55:
56: if($this->behaviour==null)
57: {
58: $listener = $page->get($this->componentPath);
59: }
60: else
61: {
62: $component = $page->get($this->componentPath);
63: if($component!=null && $component instanceof Component)
64: {
65: $listener = $component->getBehaviourById($this->behaviour);
66: }
67: }
68:
69: if($listener==null)
70: {
71: throw new \RuntimeException(sprintf("Listener component %s was not found", $this->componentPath));
72: }
73:
74: $listener->onEvent();
75: $page->renderPage();
76: $response->flush();
77: }
78:
79: public function getComponentPath()
80: {
81: return $this->componentPath;
82: }
83:
84: public function getBehaviour()
85: {
86: return $this->behaviour;
87: }
88: }
89:
90: ?>
91: