1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21:
22:
23: namespace picon;
24: require_once("core/ApplicationInitializer.php");
25:
26: require_once("addendum/annotation_parser.php");
27: require_once("addendum/annotations.php");
28: require_once("addendum/doc_comment.php");
29:
30: require_once("cache/CacheManager.php");
31: require_once("cache/PiconSerializer.php");
32:
33: 34: 35: 36:
37: abstract class PiconApplication
38: {
39: const GLOBAL_APPLICATION_KEY = "picon-application";
40:
41: private $applicatoinContext;
42: private $config;
43: private $requestProcessor;
44: private $initialiser;
45:
46:
47: private $configLoadListeners;
48: private $contextLoadListeners;
49: private $pageMapInitializationListener;
50:
51:
52: private $componentInstantiationListeners;
53: private $componentInitializationListeners;
54: private $componentBeforeRenderListeners;
55: private $componentAfterRenderListeners;
56: private $componentRenderHeadListener;
57:
58:
59: private $converters = array();
60:
61: private $securitySettings;
62:
63: 64: 65: 66: 67: 68:
69: public function __construct()
70: {
71: if(isset($GLOBALS[self::GLOBAL_APPLICATION_KEY]))
72: {
73: throw new \IllegalStateException("An instance of picon application already exists");
74: }
75: $GLOBALS[self::GLOBAL_APPLICATION_KEY] = $this;
76:
77: $this->initialiser = new ApplicationInitializer();
78: $this->initialiser->addScannedDirectory(PICON_DIRECTORY, 'picon');
79: $this->initialiser->addScannedDirectory(PICON_DIRECTORY."/annotations");
80: $this->initialiser->addScannedDirectory(PICON_DIRECTORY."/web/annotations");
81: $this->initialiser->addScannedDirectory(PICON_DIRECTORY."/exceptions");
82: $this->initialiser->addScannedDirectory(PICON_DIRECTORY."/web/pages");
83: $this->initialiser->addScannedDirectory(ASSETS_DIRECTORY);
84:
85: $this->internalInit();
86:
87: $this->initialiser->initialise();
88:
89: ob_start();
90: }
91:
92: private function internalInit()
93: {
94: $this->securitySettings = new WebApplicationSecuritySettings();
95:
96: $this->configLoadListeners = new ApplicationInitializerConfigLoadListenerCollection();
97: $this->contextLoadListeners = new ApplicationInitializerContextLoadListenerCollection();
98:
99: $config = &$this->config;
100: $context = &$this->applicatoinContext;
101:
102: $this->addConfigLoaderListener(new ApplicationConfigLoadListener(function($loadedConfig) use (&$config)
103: {
104: $config = $loadedConfig;
105: }));
106: $this->addContextLoaderListener(new ApplicationContextLoadListener(function($createdContext) use (&$context)
107: {
108: $context = $createdContext;
109: session_start();
110: }));
111:
112: $this->pageMapInitializationListener = new PageMapInitializationListenerCollection();
113:
114: $this->componentInstantiationListeners = new ComponentInstantiationListenerCollection();
115: $this->addComponentInstantiationListener(new ComponentInjector());
116: $this->addComponentInstantiationListener(new ComponentAuthorisationListener());
117:
118: $this->componentInitializationListeners = new ComponentInitializationListenerCollection();
119: $this->componentBeforeRenderListeners = new ComponentBeforeRenderListenerCollection();
120: $this->componentAfterRenderListeners = new ComponentAfterRenderListenerCollection();
121: $this->componentRenderHeadListener = new ComponentRenderHeadListenerCollection();
122:
123: $this->init();
124: }
125:
126: 127: 128: 129:
130: public function init()
131: {
132:
133: }
134:
135: public final function run()
136: {
137: $this->requestProcessor = new RequestCycle();
138: $this->requestProcessor->process();
139: }
140:
141: public final function getConfig()
142: {
143: return $this->config;
144: }
145:
146: public final function getApplicationContext()
147: {
148: return $this->applicatoinContext;
149: }
150:
151: public final function getProfile()
152: {
153: return $this->config->getProfile();
154: }
155:
156: public static function get()
157: {
158: if(!isset($GLOBALS[self::GLOBAL_APPLICATION_KEY]))
159: {
160: throw new \IllegalStateException("Failed to get picon application. The application has not been instantiated.");
161: }
162: return $GLOBALS[self::GLOBAL_APPLICATION_KEY];
163: }
164:
165: public function getHomePage()
166: {
167: return $this->getConfig()->getHomePage();
168: }
169:
170: public function getConfigLoadListener()
171: {
172: return $this->configLoadListeners;
173: }
174:
175: public function getContextLoadListener()
176: {
177: return $this->contextLoadListeners;
178: }
179:
180: public function getComponentInstantiationListener()
181: {
182: return $this->componentInstantiationListeners;
183: }
184:
185: public function getComponentInitializationListener()
186: {
187: return $this->componentInitializationListeners;
188: }
189:
190: public function getComponentBeforeRenderListener()
191: {
192: return $this->componentBeforeRenderListeners;
193: }
194:
195: public function getComponentAfterRenderListenersr()
196: {
197: return $this->componentAfterRenderListeners;
198: }
199:
200: public function getComponentRenderHeadListener()
201: {
202: return $this->componentRenderHeadListener;
203: }
204:
205: public function getPageMapInitializationListener()
206: {
207: return $this->pageMapInitializationListener;
208: }
209:
210: public function addConfigLoaderListener(ApplicationInitializerConfigLoadListener $listener)
211: {
212: $this->configLoadListeners->add($listener);
213: }
214:
215: public function addContextLoaderListener(ApplicationInitializerContextLoadListener $listener)
216: {
217: $this->contextLoadListeners->add($listener);
218: }
219:
220: public function addComponentInstantiationListener(ComponentInstantiationListener $listener)
221: {
222: $this->componentInstantiationListeners->add($listener);
223: }
224:
225: public function addComponentInitializationListener(ComponentInitializationListener $listener)
226: {
227: $this->componentInitializationListener->add($listener);
228: }
229:
230: public function addComponentBeforeRenderListener(ComponentBeforeRenderListener $listener)
231: {
232: $this->componentBeforeRenderListeners->add($listener);
233: }
234:
235: public function addComponentAfterRenderListenersr(ComponentAfterRenderListener $listener)
236: {
237: $this->componentAfterRenderListeners->add($listener);
238: }
239:
240: public function addComponentRenderHeadListener(ComponentRenderHeadListener $listener)
241: {
242: $this->componentRenderHeadListener->add($listener);
243: }
244:
245: public function addPageMapInitializationListenerCollection(PageMapInitializationListenerCollection $listener)
246: {
247: $this->pageMapInitializationListener->add($listener);
248: }
249:
250: public function getConverter($className)
251: {
252: if(array_key_exists($className, $this->converters))
253: {
254: return $this->converters[$className];
255: }
256: return null;
257: }
258:
259: public function __destruct()
260: {
261: ob_end_flush();
262: }
263:
264: public function getSecuritySettings()
265: {
266: return $this->securitySettings;
267: }
268: }
269:
270: ?>
271: