/home
/loichore
/www
/kirby
/src
/Http
/Route.php
*
* @param string $key
* @param array $arguments
* @return mixed
*/
public function __call(string $key, array $arguments = null)
{
return $this->attributes[$key] ?? null;
}
/**
* Creates a new Route object for the given
* pattern(s), method(s) and the callback action
*
* @param string|array $pattern
* @param string|array $method
* @param Closure $action
* @param array $attributes
*/
public function __construct($pattern, $method = 'GET', Closure $action, array $attributes = [])
{
$this->action = $action;
$this->attributes = $attributes;
$this->method = $method;
$this->pattern = $this->regex(ltrim($pattern, '/'));
}
/**
* Getter for the action callback
*
* @return Closure
*/
public function action()
{
return $this->action;
}
/**
* Returns all parsed arguments
*
/home
/loichore
/www
/kirby
/vendor
/composer
/ClassLoader.php
}
}
// PSR-0 include paths.
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
return $file;
}
return false;
}
}
/**
* Scope isolated include.
*
* Prevents access to $this/self from included files.
*/
function includeFile($file)
{
include $file;
}
/home
/loichore
/www
/kirby
/vendor
/composer
/ClassLoader.php
}
}
// PSR-0 include paths.
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
return $file;
}
return false;
}
}
/**
* Scope isolated include.
*
* Prevents access to $this/self from included files.
*/
function includeFile($file)
{
include $file;
}
/home
/loichore
/www
/kirby
/vendor
/composer
/ClassLoader.php
}
/**
* Unregisters this instance as an autoloader.
*/
public function unregister()
{
spl_autoload_unregister(array($this, 'loadClass'));
}
/**
* Loads the given class or interface.
*
* @param string $class The name of the class
* @return bool|null True if loaded, null otherwise
*/
public function loadClass($class)
{
if ($file = $this->findFile($class)) {
includeFile($file);
return true;
}
}
/**
* Finds the path to the file where the class is defined.
*
* @param string $class The name of the class
*
* @return string|false The path if found, false otherwise
*/
public function findFile($class)
{
// class map lookup
if (isset($this->classMap[$class])) {
return $this->classMap[$class];
}
if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
return false;
/home
/loichore
/www
/kirby
/src
/Http
/Router.php
*
* @param array $routes
*/
public function __construct(array $routes = [])
{
foreach ($routes as $props) {
if (isset($props['pattern'], $props['action']) === false) {
throw new InvalidArgumentException('Invalid route parameters');
}
$methods = array_map('trim', explode('|', strtoupper($props['method'] ?? 'GET')));
$patterns = is_array($props['pattern']) === false ? [$props['pattern']] : $props['pattern'];
if ($methods === ['ALL']) {
$methods = array_keys($this->routes);
}
foreach ($methods as $method) {
foreach ($patterns as $pattern) {
$this->routes[$method][] = new Route($pattern, $method, $props['action'], $props);
}
}
}
}
/**
* Calls the Router by path and method.
* This will try to find a Route object
* and then call the Route action with
* the appropriate arguments and a Result
* object.
*
* @param string $path
* @param string $method
* @param Closure|null $callback
* @return mixed
*/
public function call(string $path = null, string $method = 'GET', Closure $callback = null)
{
$path = $path ?? '';
/home
/loichore
/www
/kirby
/src
/Cms
/App.php
/**
* Returns the Router singleton
*
* @internal
* @return \Kirby\Http\Router
*/
public function router()
{
$routes = $this->routes();
if ($this->multilang() === true) {
foreach ($routes as $index => $route) {
if (empty($route['language']) === false) {
unset($routes[$index]);
}
}
}
return $this->router = $this->router ?? new Router($routes);
}
/**
* Returns all defined routes
*
* @internal
* @return array
*/
public function routes(): array
{
if (is_array($this->routes) === true) {
return $this->routes;
}
$registry = $this->extensions('routes');
$system = (include static::$root . '/config/routes.php')($this);
$routes = array_merge($system['before'], $registry, $system['after']);
return $this->routes = $routes;
}
/home
/loichore
/www
/kirby
/src
/Cms
/App.php
foreach (glob($this->root('blueprints') . '/' . $type . '/*.yml') as $blueprint) {
$name = F::name($blueprint);
$blueprints[$name] = $name;
}
ksort($blueprints);
return array_values($blueprints);
}
/**
* Calls any Kirby route
*
* @param string $path
* @param string $method
* @return mixed
*/
public function call(string $path = null, string $method = null)
{
$router = $this->router();
$router::$beforeEach = function ($route, $path, $method) {
$this->trigger('route:before', $route, $path, $method);
};
$router::$afterEach = function ($route, $path, $method, $result) {
return $this->apply('route:after', $route, $path, $method, $result);
};
return $router->call($path ?? $this->path(), $method ?? $this->request()->method());
}
/**
* Returns a specific user-defined collection
* by name. All relevant dependencies are
* automatically injected
*
* @param string $name
* @return \Kirby\Cms\Collection|null
*/
/home
/loichore
/www
/kirby
/src
/Cms
/App.php
$scriptName = $_SERVER['SCRIPT_NAME'];
$scriptFile = basename($scriptName);
$scriptDir = dirname($scriptName);
$scriptPath = $scriptFile === 'index.php' ? $scriptDir : $scriptName;
$requestPath = preg_replace('!^' . preg_quote($scriptPath) . '!', '', $requestUri);
return $this->setPath($requestPath)->path;
}
/**
* Returns the Response object for the
* current request
*
* @param string|null $path
* @param string|null $method
* @return \Kirby\Http\Response
*/
public function render(string $path = null, string $method = null)
{
return $this->io($this->call($path, $method));
}
/**
* Returns the Request singleton
*
* @return \Kirby\Http\Request
*/
public function request()
{
return $this->request = $this->request ?? new Request();
}
/**
* Path resolver for the router
*
* @internal
* @param string $path
* @param string|null $language
* @return mixed
*/
/home
/loichore
/www
/index.php
<?php
require 'kirby/bootstrap.php';
echo (new Kirby)->render();