/var/www/html/kirby/src/Http/Response.php
* @codeCoverageIgnore
* @todo Change return type to `never` once support for PHP 8.0 is dropped
*/
public static function go(string $url = '/', int $code = 302): void
{
die(static::redirect($url, $code));
}
/**
* Ensures that the callback does not produce the first body output
* (used to show when loading a file creates side effects)
*/
public static function guardAgainstOutput(Closure $callback, ...$args): mixed
{
$before = headers_sent();
$result = $callback(...$args);
$after = headers_sent($file, $line);
if ($before === false && $after === true) {
throw new LogicException("Disallowed output from file $file:$line, possible accidental whitespace?");
}
return $result;
}
/**
* Getter for single headers
*
* @param string $key Name of the header
*/
public function header(string $key): string|null
{
return $this->headers[$key] ?? null;
}
/**
* Getter for all headers
*/
public function headers(): array
{
/var/www/html/kirby/src/Filesystem/F.php
public static function load(
string $file,
mixed $fallback = null,
array $data = [],
bool $allowOutput = true
) {
if (is_file($file) === false) {
return $fallback;
}
// we use the loadIsolated() method here to prevent the included
// file from overwriting our $fallback in this variable scope; see
// https://www.php.net/manual/en/function.include.php#example-124
$callback = fn () => static::loadIsolated($file, $data);
// if the loaded file should not produce any output,
// call the loaidIsolated method from the Response class
// which checks for unintended ouput and throws an error if detected
if ($allowOutput === false) {
$result = Response::guardAgainstOutput($callback);
} else {
$result = $callback();
}
if (
$fallback !== null &&
gettype($result) !== gettype($fallback)
) {
return $fallback;
}
return $result;
}
/**
* A super simple class autoloader
* @since 3.7.0
*/
public static function loadClasses(
array $classmap,
/var/www/html/kirby/src/Http/Environment.php
return true;
}
/**
* Loads and returns options from environment-specific
* PHP files (by host name and server IP address)
*
* @param string $root Root directory to load configs from
*/
public function options(string $root): array
{
$configHost = [];
$configAddr = [];
$host = $this->host();
$addr = $this->ip();
// load the config for the host
if (empty($host) === false) {
$configHost = F::load(
file: $root . '/config.' . $host . '.php',
fallback: [],
allowOutput: false
);
}
// load the config for the server IP
if (empty($addr) === false) {
$configAddr = F::load(
file: $root . '/config.' . $addr . '.php',
fallback: [],
allowOutput: false
);
}
return array_replace_recursive($configHost, $configAddr);
}
/**
* Returns the detected path
/var/www/html/kirby/src/Cms/App.php
protected function optionsFromEnvironment(array $props = []): array
{
$root = $this->root('config');
// first load `config/env.php` to access its `url` option
$envOptions = F::load($root . '/env.php', [], allowOutput: false);
// use the option from the main `config.php`,
// but allow the `env.php` to override it
$globalUrl = $envOptions['url'] ?? $this->options['url'] ?? null;
// create the URL setup based on hostname and server IP address
$this->environment = new Environment([
'allowed' => $globalUrl,
'cli' => $props['cli'] ?? null,
], $props['server'] ?? null);
// merge into one clean options array;
// the `env.php` options always override everything else
$hostAddrOptions = $this->environment()->options($root);
$this->options = array_replace_recursive($this->options, $hostAddrOptions, $envOptions);
// reload the environment if the host/address config has overridden
// the `url` option; this ensures that the base URL is correct
$envUrl = $this->options['url'] ?? null;
if ($envUrl !== $globalUrl) {
$this->environment->detect([
'allowed' => $envUrl,
'cli' => $props['cli'] ?? null
], $props['server'] ?? null);
}
return $this->options;
}
/**
* Inject options from Kirby instance props
*
* @param array $options
* @return array
/var/www/html/kirby/src/Cms/App.php
protected $visitor;
/**
* Creates a new App instance
*
* @param array $props
* @param bool $setInstance If false, the instance won't be set globally
*/
public function __construct(array $props = [], bool $setInstance = true)
{
$this->core = new Core($this);
// register all roots to be able to load stuff afterwards
$this->bakeRoots($props['roots'] ?? []);
try {
// stuff from config and additional options
$this->optionsFromConfig();
$this->optionsFromProps($props['options'] ?? []);
$this->optionsFromEnvironment($props);
} finally {
// register the Whoops error handler inside of a
// try-finally block to ensure it's still registered
// even if there is a problem loading the configurations
$this->handleErrors();
}
// a custom request setup must come before defining the path
$this->setRequest($props['request'] ?? null);
// set the path to make it available for the url bakery
$this->setPath($props['path'] ?? null);
// create all urls after the config, so possible
// options can be taken into account
$this->bakeUrls($props['urls'] ?? []);
// configurable properties
$this->setOptionalProperties($props, [
'languages',
/var/www/html/index.php
<?php
require __DIR__ . '/kirby/bootstrap.php';
echo (new Kirby)->render();