aboutsummaryrefslogtreecommitdiff
path: root/ratatoeskr/sys/Env.php
diff options
context:
space:
mode:
Diffstat (limited to 'ratatoeskr/sys/Env.php')
-rw-r--r--ratatoeskr/sys/Env.php37
1 files changed, 37 insertions, 0 deletions
diff --git a/ratatoeskr/sys/Env.php b/ratatoeskr/sys/Env.php
new file mode 100644
index 0000000..cfe1598
--- /dev/null
+++ b/ratatoeskr/sys/Env.php
@@ -0,0 +1,37 @@
+<?php
+
+
+namespace r7r\cms\sys;
+
+use r7r\cms\sys\textprocessors\TextprocessorRepository;
+
+/**
+ * Env holds several global global objects. It's basically a DI container.
+ */
+class Env
+{
+ /** @var self|null */
+ private static $globalInstance = null;
+
+ private $lazyLoaded = [];
+
+ private function lazy(string $ident, callable $callback)
+ {
+ if (!isset($this->lazyLoaded[$ident])) {
+ $this->lazyLoaded[$ident] = $callback();
+ }
+ return $this->lazyLoaded[$ident];
+ }
+
+ public static function getGlobal(): self
+ {
+ self::$globalInstance = self::$globalInstance ?? new self();
+
+ return self::$globalInstance;
+ }
+
+ public function textprocessors(): TextprocessorRepository
+ {
+ return $this->lazy("textprocessors", [TextprocessorRepository::class, 'buildDefault']);
+ }
+}