$container['controller'] = function ($c) { $route = $c['route']; $handler = $route->getHandler(); if (is_callable($handler)) { return $handler; } $parts = explode('@', $handler); return $c['controller_namespace'] . $parts[0]; }; $container['controller_namespace'] = function ($c) { return $c['app_namespace'] . 'controllers\\'; }; $container['controller_slug'] = function ($c) { $controller_class = basename($c['controller']); $controller_name = preg_replace('/.+(Controller)$/', '', $controller_class); return Stringy\StaticStringy::slugify($controller_name); }; $container['db'] = function ($c) { $db_config = (require $c['app_path'] . DIRECTORY_SEPARATOR . $c['config_folder'] . DIRECTORY_SEPARATOR . 'database.php'); if (isset($c['use_db'])) { $use_db = $c['use_db']; } else { $use_db = 'default'; } if (!array_key_exists($use_db, $db_config)) { throw new \RuntimeException("Database configuration preset '{$use_db}' does not exist"); } $config = $db_config[$use_db]; if (!isset($config)) { throw new \RuntimeException("Database is disabled."); }
/** * Generate a URL friendly "slug" from a given string. * * @param string $title * @param string $separator * @return string */ function str_slug($title, $separator = '-') { $title = Stringy\StaticStringy::toAscii($title); // Convert all dashes/underscores into separator $flip = $separator == '-' ? '_' : '-'; $title = preg_replace('![' . preg_quote($flip) . ']+!u', $separator, $title); // Remove all characters that are not the separator, letters, numbers, or whitespace. $title = preg_replace('![^' . preg_quote($separator) . '\\pL\\pN\\s]+!u', '', mb_strtolower($title)); // Replace all separator characters and whitespace by a single separator $title = preg_replace('![' . preg_quote($separator) . '\\s]+!u', $separator, $title); return trim($title, $separator); }