summaryrefslogtreecommitdiff
path: root/classes/Registry.php
diff options
context:
space:
mode:
authorGeorge Halkiadakis <gchalkiadakis@sklavenitis.co.gr>2023-03-12 07:16:23 +0200
committerGeorge Halkiadakis <gchalkiadakis@sklavenitis.co.gr>2023-03-12 07:16:23 +0200
commit7076343338ae3439f3c86f01144818abe8c31978 (patch)
tree794abb1e6b8f821091fd095341885496b6dad51d /classes/Registry.php
parent47cbb529f5723b246125ae083a193e11481b89ef (diff)
downloadclassroom-7076343338ae3439f3c86f01144818abe8c31978.tar.gz
classroom-7076343338ae3439f3c86f01144818abe8c31978.tar.bz2
classroom-7076343338ae3439f3c86f01144818abe8c31978.zip
add container helpers; constuct public directory-tree
Diffstat (limited to 'classes/Registry.php')
-rw-r--r--classes/Registry.php129
1 files changed, 0 insertions, 129 deletions
diff --git a/classes/Registry.php b/classes/Registry.php
deleted file mode 100644
index df012e9..0000000
--- a/classes/Registry.php
+++ /dev/null
@@ -1,129 +0,0 @@
-<?php
-
-/** Registry
- * ---
- * Regisrty is a global repository of {key: value} pairs,
- * where key is a friendly label, and...
- * value can be anything (numbet|string|array|object etc)
- *
- * It has a central role in the framework.
- * By default it holds the Request instance and several
- * othe core instanses like database connections etc.
- */
-class Registry
-{
- /** STATIC PROPERTIES
- * -------------------------------------------------------------------------
- */
-
- /** keeps all ready-to-use records
- * ---
- * These are all records defined via Registry::set(), and
- * vow-records defined (Registry::vow()) AND called (Registry::use())
- * (it does not include the vows that have not carried-out yet )
- */
- private static $records = Array();
-
- /** keeps all records that will be carried-out later (if ever)
- * ---
- * These are registered via Registry::vow()
- */
- private static $wish = Array();
-
-
- /** METHODS
- * -------------------------------------------------------------------------
- */
-
- /** set
- * ---
- * store $data to the registry undel the label $key
- * @param $key (string)
- * @param $data *
- */
- static function set($key, $data)
- {
- // TODO: not use if needed...
- // you may include an explicit method for reseting the key
- // or even reVOWing a wish;
- // or it could be just a 3rd paremeter like
- // function set($key, $data, $reset = false) {...}
- // function set($key, $function, $reset = false) {...}
-
- if (!isset(self::$records[$key])) {
-
- self::$records[$key] = $data;
- return true;
-
- } else { return fasle; }
- }
-
-
- /** get
- * ---
- * get data from registry,
- * stored under the label $key
- * @param $key (string): the label
- * @return data (mixed)
- */
- static function get($key)
- {
- // if defined and not beeing a vow/wish, serve
- if (isset(self::$records[$key]) && (!isset(self::$wish[$key]))) {
-
- return self::$records[$key];
-
- } else { return false; }
- }
-
-
- /** vow
- * ---
- * implements a promise of a function operation
- * when/if the registry label is called;
- * it can store a function, an object handler etc.
- *
- * example:
- * Registry::vow('key', function(){ return new Obj(); })
- *
- * The main advantage of using a 'vow' vs a 'set' is
- * that a 'vow' will not use system resources to prepare
- * the data/object/handler/etc until/if-ever is called.
- *
- * @param $label (string): label / refference key
- * @param function :
- */
- static function vow($label, $function)
- {
- self::$wish[$label] = $function;
- }
-
-
- /** use (some vow)
- * ---
- * this is the method that carries out
- * the promissed function (with arguments)
- */
- static function use($label, $args=[])
- {
- // if already prepered (and is a wish) serve it
- if (isset(self::$records[$label]) && isset(self::$wish[$label])) {
-
- return self::$records[$label];
-
- } else {
-
- // otherwise if is a wish/promise
- if (array_key_exists($label, self::$wish)) {
-
- // prepare, store and serve it
- $carryOut = call_user_func_array(self::$wish[$label], $args);
- self::$records[$label] = $carryOut;
-
- return $carryOut;
-
- } else { return false; }
- }
- }
-
-}