This repository was archived by the owner on Dec 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathView.php
More file actions
61 lines (56 loc) · 1.23 KB
/
View.php
File metadata and controls
61 lines (56 loc) · 1.23 KB
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
<?php
/**
* View.php
* Contains the THINKER_View Class that all Views will inherit
* Uses the Factory Design Pattern to generate the view
*
* @author Cory Gehr
*/
class THINKER_View
{
/**
* factory()
* Draws the presentation layer for a section
*
* @author Cory Gehr
* @access public
* @static
* @param $view: View we want to use
* @param $section: Section being displayed
* @return View of Section, or Error on Failure
*/
public static function factory($view, THINKER_Section $section)
{
// Generate the View's File Name
$viewFile = "View/$view/$view.php";
// Attempt to include the View
if(include($viewFile))
{
// View Class Name
$viewClass = 'THINKER_View_' . $view;
// Create the new class if it exists
if(class_exists($viewClass))
{
// Create the view with the model as its parameter
$view = new $viewClass($section);
// Ensure we have a valid view
if($view instanceof THINKER_View_Common)
{
// Return the view
return $view;
}
}
else
{
// Throw an exception
throw new Exception("View could not be loaded.");
}
}
else
{
// Throw an exception
throw new Exception("Specified View File does not exist.");
}
}
}
?>