-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathController.php
More file actions
160 lines (142 loc) · 3.69 KB
/
Controller.php
File metadata and controls
160 lines (142 loc) · 3.69 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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php // vim:ts=3:sts=3:sw=3:et:
/**
* Abstract MVC controller class for MindFrame2_Application
*
* PHP Version 5
*
* @category PHP
* @package MindFrame2
* @author Bryan C. Geraghty <bryan@ravensight.org>
* @copyright 2005-2011 Bryan C. Geraghty
* @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU LGPL
* @link https://github.com/archwisp/MindFrame2
*/
/**
* Abstract MVC controller class for MindFrame2_Application
*
* @category PHP
* @package MindFrame2
* @author Bryan C. Geraghty <bryan@ravensight.org>
* @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU LGPL
* @link https://github.com/archwisp/MindFrame2
*/
class MindFrame2_Controller
{
/**
* @var MindFrame2_Application_Config_Interface
*/
private $_config_loader;
/**
* @var array
*/
private $_application_arguments = array();
/**
* @var array
*/
private $_xml_rpc_methods = array();
/**
* Controller execution entry point. Executed as part of the MVC command
* pattern chain by the MindFrame2_Application object.
*
* @return void
*/
public function run()
{
}
/**
* Builds the underlying structure for the object. This function is called
* from the construct
*
* @return void
*/
protected function init()
{
}
/**
* Sets the application config parameter
*
* @param MindFrame2_ConfigurationLoader $configuration_loader
* @param array $application_arguments Arguments passed to the application
*/
public function __construct(array $application_arguments)
{
$this->_application_arguments = $application_arguments;
$this->init();
}
/**
* Creates an XML-RPC server
*
* @return MindFrame2_XmlRpc_Server
*/
public function createXmlRpcServer()
{
$username = NULL;
$password = NULL;
if ($this->config_loader instanceof MindFrame2_ConfigLoader_Interface)
{
$config = $this->_config_loader->load('xml-rpc', 'authentication');
$username = $config['username'];
$password = $config['password'];
}
return new MindFrame2_XmlRpc_Server(
$this, $this->_xml_rpc_methods, $username, $password);
}
/**
* Returns the application configuration
*
* @return mixed
*/
public function loadConfiguration($part)
{
return $this->_configuration_loader->load($part);
}
/**
* Returns the application configuration
*
* @return array or NULL
*/
public function getApplicationArguments()
{
return $this->_application_arguments;
}
/**
* Attempts to retreive the specified application argument
*
* @param string $argument The argument to be retrieved
*
* @return string or FALSE
*/
public function getApplicationArgument($argument)
{
if (is_array($this->_application_arguments)
&& array_key_exists($argument, $this->_application_arguments))
{
return $this->_application_arguments[$argument];
}
return FALSE;
}
protected function getBaseUrl()
{
return sprintf('http%s://%s',
isset($_SERVER['HTTPS']) ? 's' : NULL,
$_SERVER['HTTP_HOST']);
}
/**
* Registers a public method for use via the XML-RPC server.
*
* @return void
*/
protected function registerXmlRpcMethod($method_name)
{
$this->_xml_rpc_methods[] = $method_name;
}
/**
* Sets the config loader to be passed down the stack
*
* @param MindFrame2_ConfigLoader_Interface $config_loader Config Loader
*/
public function setConfigLoader(MindFrame2_ConfigLoader_Interface $config_loader)
{
$this->_config_loader = $config_loader;
}
}