summaryrefslogtreecommitdiff
path: root/src/web/core/loader.php
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2024-12-23 11:13:27 -0500
committerFreya Murphy <freya@freyacat.org>2024-12-23 11:13:27 -0500
commit5a2ba9c2e7605bb788bc406184547d22c6436867 (patch)
treecbd988d534e8a8593a31d70571222443f80da0b3 /src/web/core/loader.php
parentfix about modal (diff)
downloadxssbook2-5a2ba9c2e7605bb788bc406184547d22c6436867.tar.gz
xssbook2-5a2ba9c2e7605bb788bc406184547d22c6436867.tar.bz2
xssbook2-5a2ba9c2e7605bb788bc406184547d22c6436867.zip
v2.1.0, refactor w/ crimson
Diffstat (limited to '')
-rw-r--r--src/web/core/loader.php101
1 files changed, 0 insertions, 101 deletions
diff --git a/src/web/core/loader.php b/src/web/core/loader.php
deleted file mode 100644
index 2091533..0000000
--- a/src/web/core/loader.php
+++ /dev/null
@@ -1,101 +0,0 @@
-<?php /* Copyright (c) 2024 Freya Murphy */
-class Loader {
-
- // keep track of what has been loaded
- private $loaded;
-
- function __construct() {
- $this->loaded = array();
- }
-
- /**
- * Loads a $type of object from a $dir with a given $name
- * @param string $name - the name of the object to load
- * @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 {
- $path = $dir . '/' . $name . '.php';
- if (array_key_exists($path, $this->loaded)) {
- return $this->loaded[$path];
- }
-
- if (!file_exists($path)) {
- return NULL;
- }
-
- $parts = explode('/', $name);
- $part = end($parts);
- $class = ucfirst($part) . '_' . $type;
- require($path);
-
- $ref = NULL;
- try {
- $ref = new ReflectionClass($class);
- } catch (Exception $_e) {}
-
- if ($ref === NULL) {
- return NULL;
- }
-
- $obj = $ref->newInstance($this);
- $this->loaded[$path] = $obj;
-
- return $obj;
- }
-
- /**
- * Loads a model
- * @param string $name - the name of the model to load
- */
- public function model($name): object|NULL {
- $root = $GLOBALS['webroot'];
- $dir = $root . '/_model';
- return $this->load_type($name, $dir, 'model');
- }
-
- /**
- * Loads a controller
- * @param string $name - the name of the controller to load
- */
- public function controller($name): Controller|NULL {
- $root = $GLOBALS['webroot'];
- $dir = $root . '/_controller';
- return $this->load_type($name, $dir, 'controller');
- }
-
- /**
- * Loads the given common lang
- * @param string $lang_code 0 the language code
- */
- public function lang($lang_code): void {
- $dir = $GLOBALS['webroot'] . '/lang/' . $lang_code . '/';
- $lang = $GLOBALS['lang'];
- if ($handle = opendir($dir)) {
- while (false !== ($entry = readdir($handle))) {
- if ($entry === '.' || $entry === '..' || $entry === 'apps') {
- continue;
- }
- $path = $dir . $entry;
- require($path);
- }
- }
- $GLOBALS['lang'] = $lang;
- }
-
- /**
- * Loads a given app specific lang
- * @param string $lang_code - the language code
- * @param string $name - the name of the app
- */
- public function app_lang($lang_code, $name): void {
- $dir = $GLOBALS['webroot'] . '/lang/' . $lang_code . '/apps/';
- $file = $dir . $name . '.php';
- if (file_exists($file)) {
- $lang = $GLOBALS['lang'];
- require($dir . $name . '.php');
- $GLOBALS['lang'] = $lang;
- }
- }
-
-}