summaryrefslogtreecommitdiff
path: root/src/_base.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/_base.php')
-rw-r--r--src/_base.php61
1 files changed, 35 insertions, 26 deletions
diff --git a/src/_base.php b/src/_base.php
index d53905d..e029130 100644
--- a/src/_base.php
+++ b/src/_base.php
@@ -35,7 +35,7 @@ abstract class Base {
* @param string $dir - the directory theese objects are stored in
* @param string $type - the type of the object
*/
- private function load_type($name, $dir, $type): object|NULL
+ private static function load_type($name, $dir, $type): object|NULL
{
$path = $dir . '/' . $name . '.php';
@@ -71,20 +71,20 @@ abstract class Base {
* Loads a model
* @param string $name - the name of the model to load
*/
- public function load_model($name): Model|NULL
+ public static function load_model($name): Model|NULL
{
$dir = WEB_ROOT . '/_model';
- return $this->load_type($name, $dir, 'model');
+ return self::load_type($name, $dir, 'model');
}
/**
* Loads a controller
* @param string $name - the name of the controller to load
*/
- public function load_controller($name): Controller|NULL
+ public static function load_controller($name): Controller|NULL
{
$dir = WEB_ROOT . '/_controller';
- return $this->load_type($name, $dir, 'controller');
+ return self::load_type($name, $dir, 'controller');
}
// ==================================================================== LANG ==
@@ -96,7 +96,7 @@ abstract class Base {
/**
* Loads a php lang file into the lang array
*/
- private function load_lang_file(string $file): void
+ private static function load_lang_file(string $file): void
{
if (isset(self::$loaded[$file]))
return;
@@ -110,13 +110,13 @@ abstract class Base {
/**
* Loads each php file lang strings in a directory
*/
- private function load_lang_dir(string $dir): void
+ private static function load_lang_dir(string $dir): void
{
if ($handle = opendir($dir)) {
while (false !== ($entry = readdir($handle))) {
if ($entry === '.' || $entry === '..')
continue;
- $this->load_lang_file($entry);
+ self::load_lang_file($entry);
}
}
}
@@ -124,7 +124,7 @@ abstract class Base {
/**
* Loads the given common lang
*/
- public function load_lang(string ...$langs): array
+ public static function load_lang(string ...$langs): array
{
$root = WEB_ROOT . '/lang';
@@ -133,9 +133,9 @@ abstract class Base {
$dir = "{$root}/{$lang}";
if (file_exists($file))
- $this->load_lang_file($file);
+ self::load_lang_file($file);
else if (is_dir($dir))
- $this->load_lang_dir($dir);
+ self::load_lang_dir($dir);
}
@@ -145,7 +145,7 @@ abstract class Base {
/**
* Returns the currently loaded lang
*/
- public function get_lang(): array
+ public static function get_lang(): array
{
return self::$loaded_lang;
}
@@ -158,7 +158,7 @@ abstract class Base {
/**
* Loads the database
*/
- public function db(): DatabaseHelper
+ public static function db(): DatabaseHelper
{
if (!self::$db)
self::$db = new DatabaseHelper();
@@ -171,7 +171,7 @@ abstract class Base {
* Gets the stamp for a asset path
* @param string $path
*/
- public function asset_stamp(string $path): int
+ public static function asset_stamp(string $path): int
{
if (ENVIRONMENT == 'development')
return time();
@@ -185,7 +185,7 @@ abstract class Base {
* @param string $path
* @param bool $timestamp
*/
- public function get_url(string $path, bool $timestamp = FALSE): string
+ public static function get_url(string $path, bool $timestamp = FALSE): string
{
$scheme = 'http';
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']))
@@ -205,7 +205,7 @@ abstract class Base {
$base = CONFIG['base_path'];
$url = "{$scheme}://{$host}{$base}{$path}";
if ($timestamp) {
- $time = $this->asset_stamp($path);
+ $time = self::asset_stamp($path);
$url .= "?timestamp={$time}";
}
return $url;
@@ -215,10 +215,10 @@ abstract class Base {
* Loads a js html link
* @param string $path - the path to the js file
*/
- public function link_js(string $path): string
+ public static function link_js(string $path): string
{
- $stamp = $this->asset_stamp("public/$path");
- $href = $this->get_url("public/{$path}?timestamp={$stamp}");
+ $stamp = self::asset_stamp("public/$path");
+ $href = self::get_url("public/{$path}?timestamp={$stamp}");
return '<script src="'. $href .'"></script>';
}
@@ -226,10 +226,10 @@ abstract class Base {
* Loads a css html link
* @param string $path - the path to the css file
*/
- public function link_css(string $path): string
+ public static function link_css(string $path): string
{
- $stamp = $this->asset_stamp("public/$path");
- $href = $this->get_url("public/{$path}?timestamp={$stamp}");
+ $stamp = self::asset_stamp("public/$path");
+ $href = self::get_url("public/{$path}?timestamp={$stamp}");
return '<link rel="stylesheet" href="'. $href .'">';
}
@@ -237,7 +237,7 @@ abstract class Base {
* Loads a css html link
* @param string $path - the path to the css file
*/
- public function embed_css(string $path): string
+ public static function embed_css(string $path): string
{
$file = PUBLIC_ROOT . '/' . $path;
if (file_exists($file)) {
@@ -248,6 +248,15 @@ abstract class Base {
}
}
+ /**
+ * Formats a ISO date
+ * @param $iso_date the ISO date
+ */
+ public function format_date(string $iso_date): string
+ {
+ return date("Y-m-d D H:i", strtotime($iso_date));
+ }
+
// =============================================================== HTTP POST ==
/**
@@ -255,7 +264,7 @@ abstract class Base {
* php://input if AJAX. Returns FALSE if input is not a post request,
* or NULL if unable to parse request body.
*/
- private function get_post_data()
+ private static function get_post_data()
{
static $data = NULL;
@@ -290,9 +299,9 @@ abstract class Base {
* @returns FALSE if request is POST but has invalid body.
* @returns NULL if request is not POST.
*/
- public function post_data(?string $key = NULL)
+ public static function post_data(?string $key = NULL)
{
- $data = $this->get_post_data();
+ $data = self::get_post_data();
if (!$data)
return $data;