diff --git a/inc/context.php b/inc/context.php new file mode 100644 index 00000000..4746be0d --- /dev/null +++ b/inc/context.php @@ -0,0 +1,31 @@ +definitions = $definitions; + } + + public function get(string $name): mixed { + if (!isset($this->definitions[$name])) { + throw new \RuntimeException("Could not find a dependency named $name"); + } + + $ret = $this->definitions[$name]; + if (is_callable($ret) && !is_string($ret) && !is_array($ret)) { + $ret = $ret($this); + $this->definitions[$name] = $ret; + } + return $ret; + } +} + +function build_context(array $config): Context { + return new Context([ + 'config' => $config, + ]); +}