Rev 51 | Rev 57 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 51 | Rev 52 | ||
|---|---|---|---|
| Line 1... | Line 1... | ||
| 1 | <?php
|
1 | <?php
|
| 2 | 2 | ||
| 3 | namespace PointedEars\PHPX; |
3 | namespace PointedEars\PHPX; |
| 4 | 4 | ||
| - | 5 | function autoload ($class) |
|
| - | 6 | {
|
|
| - | 7 | if (\strpos($class, '..')) |
|
| - | 8 | {
|
|
| 5 | require_once __DIR__ . '/AbstractModel.php'; |
9 | throw new \InvalidArgumentException( |
| - | 10 | 'Refusing to load unsafe class ' . $class); |
|
| - | 11 | }
|
|
| - | 12 | ||
| 6 | require_once __DIR__ . '/Registry.php'; |
13 | require_once \preg_replace('#\\\#', '/', |
| - | 14 | \preg_replace('#^' . \preg_quote(__NAMESPACE__) .'#', __DIR__, $class) |
|
| - | 15 | ) . '.php'; |
|
| - | 16 | }
|
|
| - | 17 | ||
| - | 18 | \spl_autoload_register(__NAMESPACE__ . '\\autoload'); |
|
| 7 | 19 | ||
| 8 | /**
|
20 | /**
|
| 9 | * Basic application class
|
21 | * Basic application class
|
| 10 | *
|
22 | *
|
| 11 | * @author Thomas Lahn
|
23 | * @author Thomas Lahn
|
| Line 75... | Line 87... | ||
| 75 | * @return mixed
|
87 | * @return mixed
|
| 76 | */
|
88 | */
|
| 77 | public function __get($name) |
89 | public function __get ($name) |
| 78 | {
|
90 | {
|
| 79 | /* Support for Object-Relational Mappers */
|
91 | /* Support for Object-Relational Mappers */
|
| 80 | if (strpos($name, 'persistent') === 0) |
92 | if (\strpos($name, 'persistent') === 0) |
| 81 | {
|
93 | {
|
| 82 | $class = get_class($this); |
94 | $class = \get_class($this); |
| 83 | return $class::${$name}; |
95 | return $class::${$name}; |
| 84 | }
|
96 | }
|
| 85 | 97 | ||
| 86 | $method = 'get' . ucfirst($name); |
98 | $method = 'get' . \ucfirst($name); |
| 87 | 99 | ||
| 88 | if (method_exists($this, $method)) |
100 | if (\method_exists($this, $method)) |
| 89 | {
|
101 | {
|
| 90 | return $this->$method(); |
102 | return $this->$method(); |
| 91 | }
|
103 | }
|
| 92 | 104 | ||
| 93 | if (property_exists($this, "_$name")) |
105 | if (\property_exists($this, "_$name")) |
| 94 | {
|
106 | {
|
| 95 | return $this->{"_$name"}; |
107 | return $this->{"_$name"}; |
| 96 | }
|
108 | }
|
| 97 | 109 | ||
| 98 | return $this->$name; |
110 | return $this->$name; |
| Line 105... | Line 117... | ||
| 105 | * @param mixed $value The new property value before assignment
|
117 | * @param mixed $value The new property value before assignment
|
| 106 | * @throws ModelPropertyException
|
118 | * @throws ModelPropertyException
|
| 107 | */
|
119 | */
|
| 108 | public function __set($name, $value) |
120 | public function __set ($name, $value) |
| 109 | {
|
121 | {
|
| 110 | $method = 'set' . ucfirst($name); |
122 | $method = 'set' . \ucfirst($name); |
| 111 | 123 | ||
| 112 | if (method_exists($this, $method)) |
124 | if (\method_exists($this, $method)) |
| 113 | {
|
125 | {
|
| 114 | return $this->$method($value); |
126 | return $this->$method($value); |
| 115 | }
|
127 | }
|
| 116 | 128 | ||
| 117 | if (property_exists($this, "_$name")) |
129 | if (\property_exists($this, "_$name")) |
| 118 | {
|
130 | {
|
| 119 | $this->{"_$name"} = $value; |
131 | $this->{"_$name"} = $value; |
| 120 | return $this->{"_$name"}; |
132 | return $this->{"_$name"}; |
| 121 | }
|
133 | }
|
| 122 | 134 | ||
| Line 135... | Line 147... | ||
| 135 | if (!$controller) |
147 | if (!$controller) |
| 136 | {
|
148 | {
|
| 137 | $controller = $this->_defaultController; |
149 | $controller = $this->_defaultController; |
| 138 | }
|
150 | }
|
| 139 | 151 | ||
| 140 | $controller = ucfirst($controller); |
152 | $controller = \ucfirst($controller); |
| 141 | 153 | ||
| 142 | $controller = $controller . 'Controller'; |
154 | $controller = $controller . 'Controller'; |
| 143 | require_once "{$this->_controllerPath}/{$controller}.php"; |
155 | require_once "{$this->_controllerPath}/{$controller}.php"; |
| 144 | $this->_currentController = new $controller(); |
156 | $this->_currentController = new $controller(); |
| 145 | 157 | ||
| 146 | return $this; |
158 | return $this; |
| 147 | }
|
159 | }
|
| 148 | 160 | ||
| 149 | protected function startSession() |
161 | protected function startSession () |
| 150 | {
|
162 | {
|
| 151 | session_start(); |
163 | \session_start(); |
| 152 | }
|
164 | }
|
| 153 | 165 | ||
| 154 | /**
|
166 | /**
|
| 155 | * Gets a request parameter
|
167 | * Gets a request parameter
|
| 156 | *
|
168 | *
|
| Line 246... | Line 258... | ||
| 246 | $url = self::getParam('URL', $_SERVER); |
258 | $url = self::getParam('URL', $_SERVER); |
| 247 | if ($url === null) |
259 | if ($url === null) |
| 248 | {
|
260 | {
|
| 249 | /* Server/PHP too old, compute URI */
|
261 | /* Server/PHP too old, compute URI */
|
| 250 | $url = self::getParam('REQUEST_URI', $_SERVER); |
262 | $url = self::getParam('REQUEST_URI', $_SERVER); |
| 251 | if (preg_match('/^[^?]+/', $url, $matches) > 0) |
263 | if (\preg_match('/^[^?]+/', $url, $matches) > 0) |
| 252 | {
|
264 | {
|
| 253 | $url = $matches[0]; |
265 | $url = $matches[0]; |
| 254 | }
|
266 | }
|
| 255 | else
|
267 | else
|
| 256 | {
|
268 | {
|
| 257 | /* Has .php in it, but at least it works */
|
269 | /* Has .php in it, but at least it works */
|
| 258 | $url = self::getParam('SCRIPT_NAME', $_SERVER); |
270 | $url = self::getParam('SCRIPT_NAME', $_SERVER); |
| 259 | if ($url === null) |
271 | if ($url === null) |
| 260 | {
|
272 | {
|
| 261 | throw new Exception( |
273 | throw new \Exception( |
| 262 | 'None of $_SERVER["SCRIPT_URL"], $_SERVER["URL"],'
|
274 | 'None of $_SERVER["SCRIPT_URL"], $_SERVER["URL"],'
|
| 263 | . ' $_SERVER["REQUEST_URI"], or $_SERVER["SCRIPT_NAME"]' |
275 | . ' $_SERVER["REQUEST_URI"], or $_SERVER["SCRIPT_NAME"]' |
| 264 | . ' is available, cannot continue.'); |
276 | . ' is available, cannot continue.'); |
| 265 | }
|
277 | }
|
| 266 | }
|
278 | }
|
| Line 281... | Line 293... | ||
| 281 | {
|
293 | {
|
| 282 | $script_uri = self::getParam('SCRIPT_URI', $_SERVER); |
294 | $script_uri = self::getParam('SCRIPT_URI', $_SERVER); |
| 283 | if ($script_uri === null) |
295 | if ($script_uri === null) |
| 284 | {
|
296 | {
|
| 285 | /* Server/PHP too old, compute URI */
|
297 | /* Server/PHP too old, compute URI */
|
| 286 | if (preg_match('/^[^?]+/', |
298 | if (\preg_match('/^[^?]+/', |
| 287 | self::getParam('REQUEST_URI', $_SERVER), $matches) > 0) |
299 | self::getParam('REQUEST_URI', $_SERVER), $matches) > 0) |
| 288 | {
|
300 | {
|
| 289 | $query_prefix = $matches[0]; |
301 | $query_prefix = $matches[0]; |
| 290 | }
|
302 | }
|
| 291 | else
|
303 | else
|
| Line 300... | Line 312... | ||
| 300 | : 'http://') |
312 | : 'http://') |
| 301 | . self::getParam('HTTP_HOST', $_SERVER) |
313 | . self::getParam('HTTP_HOST', $_SERVER) |
| 302 | . $query_prefix; |
314 | . $query_prefix; |
| 303 | }
|
315 | }
|
| 304 | 316 | ||
| 305 | header('Location: ' . $script_uri |
317 | \header('Location: ' . $script_uri |
| 306 | . ($query ? (substr($query, 0, 1) === '?' ? '' : '?') . $query : '')); |
318 | . ($query ? (substr($query, 0, 1) === '?' ? '' : '?') . $query : '')); |
| 307 | }
|
319 | }
|
| 308 | }
|
320 | }
|