39 if (! is_string($url)) {
40 throw new \InvalidArgumentException();
43 $this->application_url = $url;
56 if (! is_string($path)) {
57 throw new \InvalidArgumentException();
60 $url = $this->application_url;
81 if (! is_string($directory) || empty(
83 throw new \InvalidArgumentException();
86 $this->application_path = $directory;
99 if (empty($filename)) {
100 throw new \InvalidArgumentException();
103 if (empty($this->application_path)) {
105 $dir = dirname($dir);
106 $dir = dirname($dir);
107 $dir = dirname($dir);
108 $dir = dirname($dir);
109 $this->application_path = $dir;
111 $file = $this->application_path;
112 if(empty($filename)) {
115 if($filename[0] !=
'/') {
130 return new \ReflectionClass($this);
137 $name = $this->
getClass()->getShortName();
138 $name = preg_replace(
'/(_[Pp]|P)age$/',
'', $name);
155 if (! is_string($locale) || empty($locale)) {
156 throw new \InvalidArgumentException();
159 putenv(
"LC_ALL=" . $locale);
160 setlocale(LC_ALL, $locale);
161 $domain =
"messages";
188 protected final function openPDO($dsn, $user =
"", $password =
"")
191 if (! is_string($dsn) || empty($dsn)) {
192 throw new \InvalidArgumentException();
195 if (! is_string($user)) {
196 throw new \InvalidArgumentException();
199 if (! is_string($password)) {
200 throw new \InvalidArgumentException();
206 if (empty($password)) {
209 $this->pdo = new \PDO(
214 \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
215 \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_OBJ
228 if (is_null($this->pdo))
229 $this->
openPDO(
"pgsql:",
"",
"");
256 if (is_null($this->auth)) {
303 if(in_array($page_name, $public_pages))
return true;
304 $role_attr =
"is_" . strtolower($page_name) .
"_manager";
328 protected function render($template, array $view_data = array(), $code = 200)
331 if (! is_string($template) || empty($template)) {
332 throw new \InvalidArgumentException();
336 if (! is_int($code) || $code < 100 || $code > 599) {
337 throw new \InvalidArgumentException($code);
341 http_response_code($code);
345 $contents = ob_get_contents();
367 if (! is_string($message)) {
368 throw new \InvalidArgumentException();
371 if (! is_int($code) || $code < 100 || $code > 599) {
372 throw new \InvalidArgumentException();
379 "message" => $message
394 $file = basename($ex->getFile());
395 $line = $ex->getLine();
396 $message = $ex->getMessage();
397 $classname = get_class($ex);
398 return $this->
renderError(
"$message ($classname@$file:$line)", 500);
406 $action = @$_REQUEST[
"action"];
407 if (! isset($action))
408 $action = $_SERVER[
"REQUEST_METHOD"];
409 assert($action != null);
410 $action = strtolower($action);
411 $method =
"do" . ucwords($action);
412 if (method_exists($this, $method)) {
416 echo call_user_method($method, $this);
417 }
catch (\Exception $ex) {
421 $classname = get_class($this);
423 _(
"Method not found") .
": {$classname}::{$method}",
430 private $auth = null;
431 private $application_path = null;
432 private $application_url =
"";
setApplicationDirectory($directory)
Sets the application directory.
setApplicationURL($url)
Sets the application URL.
authorizeByAttribute($attribute)
Performs authorization by the account attribute.
render($template, array $view_data=array(), $code=200)
Renders a view.
getApplicationURL($path)
Returns a path relative to the application URL.
getPageName()
Returns short class name without 'Page' suffix.
getClass()
Returns new \ReflectionClass($this).
Performs basic HTTP authentication.
renderError($message, $code=500)
Renders an error.
show()
Handles a server request and displays this page.
getAuthentication()
Returns an AbstractAuthentication object; never null.
authorizeByPageName(array $public_pages=array())
Performs authorization by the page name.
setAuthentication(AbstractAuthentication $auth)
Sets an authentication to use with this page.
setLocale($locale)
Sets a locale to use with this page.
An abstract authentication.
getPDO()
Returns a PDO connection.
authorize()
Performs authorization.
getApplicationFile($filename)
Returns a file path relative to the application directory.
renderException(\Exception $ex)
Renders an exception.
openPDO($dsn, $user="", $password="")
Opens a database connection to use in this application.