define('initTime', function() { return time(); }); * * @param string $key * @param mixed $callback * @return mixed * The value of $callback (either cached or fresh) */ public function define($key, $callback) { if (!isset($this->data[$key])) { $this->set($key, $callback($this)); } return $this->data[$key]; } /** * Determine if $key has been set. * * @param string $key * @return bool */ public function has($key) { return isset($this->data[$key]); } /** * Get the value of $key. * * @param string $key * @param mixed $default * @return mixed */ public function get($key, $default = NULL) { return $this->data[$key] ?? $default; } /** * Set a value in the cache. * * This operation is only valid on the first page-load when a cache is built. * * @param string $key * @param mixed $value * @return static * @throws \Exception */ public function set($key, $value) { if ($this->locked) { throw new \Exception("Cannot modify a locked boot-cache."); } $this->data[$key] = $value; return $this; } public function lock() { $this->locked = TRUE; } }