directory = $namespace; } else { $this->path[$namespace] = $directory; } } /** * Get * * @param string $key * * @return mixed */ public function get(string $key): mixed { return isset($this->data[$key]) ? $this->data[$key] : ''; } /** * Set * * @param string $key * @param string $value */ public function set(string $key, mixed $value): void { $this->data[$key] = $value; } /** * Has * * @param string $key * * @return mixed */ public function has(string $key): bool { return isset($this->data[$key]); } /** * Load * * @param string $filename */ public function load(string $filename): array { $file = $this->directory . $filename . '.php'; $namespace = ''; $parts = explode('/', $filename); foreach ($parts as $part) { if (!$namespace) { $namespace .= $part; } else { $namespace .= '/' . $part; } if (isset($this->path[$namespace])) { $file = $this->path[$namespace] . substr($filename, strlen($namespace)) . '.php'; } } if (is_file($file)) { $_ = []; require($file); $this->data = array_merge($this->data, $_); return $this->data; } else { return []; } } }