This repository has been 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
/
Section.php
118 lines (106 loc) · 2.2 KB
/
Section.php
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
<?php
/**
* Section.php
* Contains the THINKER_Section class
*
* @author Cory Gehr
*/
abstract class THINKER_Section
{
protected $reflectionClass; // Contains information about the class (ReflectionClass)
protected $data; // Contains the data being passed back from the Section
protected $session; // Contains session data
public $view; // Contains the view being loaded for the section
/**
* __construct()
* Constructor for the THINKER_Section Class
*
* @author Cory Gehr
* @access public
*/
public function __construct()
{
// Initialize classInfo with information about the target class
$this->reflectionClass = new ReflectionClass($this);
$this->data = array();
// Override view if necessary
if(isset($_GET['view']))
{
$this->view = getPageVar('view', 'str', 'GET', true);
}
else
{
$this->view = DEFAULT_VIEW;
}
// Get the session information
$sessionClass = SESSION_CLASS;
$this->session = $sessionClass::singleton();
}
/**
* getData()
* Passes back the data array from this section
*
* @access public
* @return Data Array
*/
public function getData()
{
return $this->data;
}
/**
* getVal()
* Gets a value from this object
*
* @access public
* @param $name: Name of the Variable
* @return Variable Value, or NULL on non-existence
*/
public function getVal($name)
{
if(isset($this->data[$name]))
{
return $this->data[$name];
}
else
{
return null;
}
}
/**
* set()
* Sets a value in the local data array
*
* @access public
* @param $key: Array key
* @param $value: Value
*/
public function set($key, $value)
{
$this->data[$key] = $value;
}
/**
* toArray()
* Returns an object's variables as an associative array
*
* @author Joe Stump <joe@joestump.net>
* @access public
* @return Array of Variables (VarName => Value)
*/
public function toArray()
{
$defaults = $this->reflectionClass->getDefaultProperties();
$return = array();
foreach($defaults as $var => $val)
{
if($this->$var instanceof THINKER_Object)
{
$return[$var] = $this->$var->toArray();
}
else
{
$return[$var] = $this->$var;
}
}
return $return;
}
}