1
0
www.mikescher.com/www/internals/urlroute.php

112 lines
2.1 KiB
PHP
Raw Normal View History

2020-01-14 22:25:43 +01:00
<?php
2020-01-13 14:39:35 +01:00
2020-01-14 22:25:43 +01:00
require_once "website.php";
2020-01-13 14:39:35 +01:00
class URLRoute
{
/** @var string */
public $targetpath;
/** @var string */
public $full_url;
/** @var array */
public $parameter;
/** @var int */
2020-01-14 22:25:43 +01:00
public $needsAdminLogin;
2020-01-13 14:39:35 +01:00
2020-01-16 13:21:14 +01:00
/** @var array */
public $urlParameter;
/** @var bool */
public $isAPI;
2020-01-13 14:39:35 +01:00
public function __construct(string $target, string $url)
{
2020-01-16 13:21:14 +01:00
$this->targetpath = (__DIR__ . '/../pages/' . $target);
2020-01-13 14:39:35 +01:00
$this->full_url = $url;
$this->parameter = [];
2020-01-14 22:25:43 +01:00
$this->needsAdminLogin = false;
2020-01-16 13:21:14 +01:00
$this->urlParameter = [];
$this->isAPI = false;
2020-01-13 14:39:35 +01:00
}
/**
2020-01-15 01:46:31 +01:00
* @param Website $site
2020-01-13 14:39:35 +01:00
* @return PageFrameOptions
*/
2020-01-15 01:46:31 +01:00
public function get(Website $site): PageFrameOptions
2020-01-13 14:39:35 +01:00
{
$pfo = new PageFrameOptions();
2020-01-15 01:46:31 +01:00
$pfo->addStylesheet($site->isProd() ? ('/data/css/styles.min.css') : ('/data/css/styles.css'));
2020-01-13 14:39:35 +01:00
2020-01-15 01:46:31 +01:00
return $this->getDirect($site, $pfo);
2020-01-13 14:39:35 +01:00
}
/**
2020-01-15 01:46:31 +01:00
* @param Website $site
2020-01-13 14:39:35 +01:00
* @param PageFrameOptions $pfo
* @return PageFrameOptions
*/
2020-01-15 01:46:31 +01:00
public function getDirect(Website $site, PageFrameOptions $pfo): PageFrameOptions
2020-01-13 14:39:35 +01:00
{
2020-01-15 02:50:23 +01:00
try
{
ob_start();
global $ROUTE;
global $FRAME_OPTIONS;
global $SITE;
$ROUTE = $this;
$FRAME_OPTIONS = $pfo;
$SITE = $site;
/** @noinspection PhpIncludeInspection */
require $this->targetpath;
$FRAME_OPTIONS->raw = ob_get_contents();
return $FRAME_OPTIONS;
}
finally
{
ob_end_clean();
}
2020-01-13 14:39:35 +01:00
}
/**
* @param URLRoute $route
* @param string $requri
* @return URLRoute
*/
public static function getLoginRoute(URLRoute $route, string $requri): URLRoute
{
$r = new URLRoute('login.php', $requri);
2020-01-15 01:46:31 +01:00
$r->parameter = [ 'login_target' => $route->full_url ];
2020-01-13 14:39:35 +01:00
return $r;
}
/**
* @param string $requri
* @return URLRoute
*/
public static function getNotFoundRoute(string $requri): URLRoute
{
2020-01-15 01:46:31 +01:00
$r = new URLRoute('error_notfound.php', $requri);
2020-01-13 14:39:35 +01:00
$r->parameter = [];
return $r;
}
/**
* @param string $requri
* @return URLRoute
*/
public static function getServerErrorRoute(string $requri): URLRoute
{
2020-01-15 01:46:31 +01:00
$r = new URLRoute('error_servererror.php', $requri);
2020-01-13 14:39:35 +01:00
$r->parameter = [];
return $r;
}
}