bst/webapp/fx/web/WebApplication.inc.php
2023-10-31 00:21:50 -04:00

79 lines
1.3 KiB
PHP

<?php
namespace MBS\Web;
class WebApplication
{
public $ApplicationRoot;
public $Pages;
public $Variables;
public static $Current;
public function __construct($root)
{
$this->ApplicationRoot = $root;
$this->Pages = array();
$this->Variables = array();
}
public function ExpandRelativePath($path)
{
if (substr($path, 0, 2) == "~/")
{
return $this->ApplicationRoot . "/" . substr($path, 2);
}
return $path;
}
private function _IsPostback()
{
// thanks https://stackoverflow.com/questions/4242035
return strtoupper($_SERVER['REQUEST_METHOD']) === 'POST';
//&& (basename($_SERVER['HTTP_REFERER']) == $_SERVER['SCRIPT_NAME']));
}
public function OnInitialize()
{
return true;
}
public function OnPostback()
{
}
public function Start()
{
WebApplication::$Current = $this;
if ($this->OnInitialize())
{
return;
}
if ($this->_IsPostback())
{
$this->OnPostback();
}
foreach ($this->Pages as $page)
{
$path = $_SERVER["REQUEST_URI"];
$rp = substr($path, strlen($this->ApplicationRoot));
$my_path = $page->Path;
if (strlen($my_path) == 0)
{
$my_path = "/";
}
else if (substr($my_path, 0, 1) != "/")
{
$my_path = "/" . $my_path;
}
if ($rp == $my_path)
{
$page->Render();
}
}
}
}
?>