'controllers/', 'Core\\' => 'core/', 'Model\\' => 'models/', 'Service\\' => 'services/', 'View\\' => 'views/', ]; private $basedir = __DIR__; /** * @var Config */ public $config; /** * @var \PDO */ public $db = null; /** * App constructor. * * @param bool $start Start router. Default true. */ public function __construct(bool $start = true) { global $app; $app = $this; spl_autoload_register([$this, 'autoload']); $this->config = (new Config())->setDbName('db') ->setDbPort(3306) ->setDbUser('user') ->setDbPassword('password') ->setSrcDir($this->basedir) ->setTimezone('Europe/Moscow') ->setClassDirs($this->classDirs) ->setControllersDir($this->basedir.'/controllers/') ->setControllersNamespace('\\MyApp\\Controller\\') ->setSiteName('BadPing. Nagios better'); if ($start) { new Router(); } } /** * Autoload function. * * @param string $className */ public function autoload(string $className) { if (0 !== strpos($className, $this->prefix)) { return; } $fileName = substr($className, strlen($this->prefix)); $fileName = str_replace(array_keys($this->classDirs), array_values($this->classDirs), $fileName); $fileName = $this->basedir.'/'.str_replace('\\', '/', $fileName).'.php'; if (file_exists($fileName)) { require $fileName; } } /** * Parse tags from method comments. * * @param string $comment * @param string $tags * * @return array|null */ public function parseTagsFromComment(string $comment, string $tags = 'RouteRegExp|HttpMethod') { if (preg_match_all("/^\\ *\\* \\@(?$tags)\\ =\\ \"(?.*)\\\".*\$/m", $comment, $matches)) { $out = []; foreach ($matches['type'] as $key => $type) { if ('HttpMethod' == $type) { $out[$type] = explode(',', $matches['value'][$key]); } else { $out[$type] = $matches['value'][$key]; } } return $out; } return null; } }