path[$namespace] = [ 'directory' => $directory, 'psr4' => $psr4 ]; } /** * Load * * @param string $class * * @return bool */ public function load(string $class): bool { $namespace = ''; $parts = explode('\\', $class); foreach ($parts as $part) { if (!$namespace) { $namespace .= $part; } else { $namespace .= '\\' . $part; } if (isset($this->path[$namespace])) { if (!$this->path[$namespace]['psr4']) { $file = $this->path[$namespace]['directory'] . trim(str_replace('\\', '/', strtolower(preg_replace('~([a-z])([A-Z]|[0-9])~', '\\1_\\2', substr($class, strlen($namespace))))), '/') . '.php'; } else { $file = $this->path[$namespace]['directory'] . trim(str_replace('\\', '/', substr($class, strlen($namespace))), '/') . '.php'; } } } if (isset($file) && is_file($file)) { include_once($file); return true; } else { return false; } } }