Index

MMO\core\server

MMO\core\server · 32 symbols · generated 5 Oct 2026

function

charset

server.php:696

Extract the charset=... parameter's value from a Content-Type header.

function charset(array|string $header): ?string
Namespace
MMO\core\server
$headerarray | stringa header line/value (extractContentType()), or an already-split list of them
returnsnull | stringnull if no charset parameter is present
charset('application/json; charset=utf-8'); // 'utf-8'
Call graph
function

clientIP

server.php:478

Get the client's IP address, checking a wider/differently-ordered set of headers than ip() (via \getenv() rather than $_SERVER directly -- functionally equivalent under most SAPIs). Falls back to '127.0.0.1' (and logs a warning) if nothing at all is available, e.g. running on the CLI.

function clientIP(): string
Namespace
MMO\core\server
WARNING: same spoofing caveat as [`ip()`](https://mcp.mmoframework.fr/documentation/mmo.core/php/server.md#ip) -- every header checked here except REMOTE_ADDR is client-controlled.
returnsstring
function

contentType

server.php:677

Extract just the content-type value(s) from a Content-Type header, stripping any ;charset=.../other parameters.

function contentType(array|string $header, bool $single = true): array|string
Namespace
MMO\core\server
$headerarray | stringa header line/value (extractContentType()), or an already-split list of them
$single = trueboolif true, return just the first content-type; if false, return every one found
returnsarray | string'' (or []) if $header has no usable content-type at all
contentType('application/json; charset=utf-8'); // 'application/json'
Call graph
function

date

server.php:441

Format a unix timestamp (or a parseable date string) as an RFC 7231 ("IMF-fixdate") GMT date, suitable for an HTTP header (e.g. Date, Expires, Last-Modified).

function date(string|int|null $time = null): ?string
Namespace
MMO\core\server
$time = nullstring | int | nulla unix timestamp, a string \strtotime() can parse, or null for the current time
returnsnull | stringGMT date string (e.g. 'Mon, 01 Jan 2024 00:00:00 GMT'), or null if $time is an unparseable string
date(1704067200); // 'Mon, 01 Jan 2024 00:00:00 GMT'
function

decodeRecipients

server.php:539

Decode a comma-separated recipient list of the form "Name" <email>, other@example.com, ... (as used in mail headers like To/Cc) into [email => name] pairs.

function decodeRecipients(string $recipients): array
Namespace
MMO\core\server
$recipientsstring
returnsarray[email => name] -- name is null for a recipient given as a bare email address
decodeRecipients('John Doe <john@example.com>, jane@example.com'); // ['john@example.com' => 'John Doe', 'jane@example.com' => null]
Call graph
function

defaultCharset

server.php:467

Get PHP's configured default charset (the default_charset ini directive, e.g. 'UTF-8').

function defaultCharset(): string
Namespace
MMO\core\server
returnsstring
Call graph
function

defaultLanguage

server.php:454

Guess a default language from the environment: $_SERVER['LANG'] (its part before any '.', e.g. the 'fr_FR' in 'fr_FR.UTF-8'), falling back to the TLD of $_SERVER['REMOTE_HOST'] if that's set (a weak signal at best -- most hosts don't reverse-resolve, and a TLD like '.com' says nothing about language).

function defaultLanguage(): string
Namespace
MMO\core\server
returnsstringan empty string if nothing could be determined
Call graph
function

DNSIP

server.php:367

Look up a domain's A (IPv4) or AAAA (IPv6) record.

function DNSIP(string $domain, bool $ipv6 = false): ?string
Namespace
MMO\core\server
$domainstring
$ipv6 = falseboolif true, look up the AAAA record instead of A
returnsnull | stringnull if no matching record was found
function

documentRoot

server.php:399

Get the document root the running script is resolved against: under a web server $_SERVER['DOCUMENT_ROOT'] through realpath(), on the CLI as is (normally empty).

function documentRoot(): string
Namespace
MMO\core\server
See
scriptName() builds the script's path on it, and Application::DefaultConfig takes it off that path again to find the site's url: both have to use this one value. A document root reached through a symlink -- mmo.admin's current, a shared host's web root linked onto it -- is longer or shorter than its realpath, and taking the length of the one off a path built from the other gave the site a url like https://example.com/0.0/www.
returnsstring'' when it cannot be resolved (a missing folder, an open_basedir restriction)
documentRoot(); // e.g. "/var/www/demo/releases/1.0.3/www" for a DocumentRoot /var/www/demo/current/www
Call graph
function

exitCode

server.php:566

Map an HTTP status code to a shell exit code (the EXIT_* constants), for a CLI request routed through the same Application/Route pipeline as an HTTP one (Application::run()).

function exitCode(int $http_status): int
Namespace
MMO\core\server
$http_statusint
returnsint0 for any status < 400; a specific EXIT_* code for a handful of common statuses; EXIT_GENERAL_ERROR otherwise
exitCode(200); // 0 exitCode(404); // 127 (EXIT_COMMAND_UNKNOWN) exitCode(500); // 70 (EXIT_SERVER_ERROR)
Call graph
function

extension

server.php:714

Reverse lookup: find a file extension whose MIMES entry matches a given content-type header (the first usable content-type found in $header, tried against every entry of MIMES).

function extension(array|string $header): ?string
Namespace
MMO\core\server
$headerarray | stringthe content type as an http header/value, or a list of types
returnsnull | stringthe extension (without '.'), or null if no MIMES entry matches
extension('application/json'); // 'json'
Call graph
function

extensionToContentType

server.php:753

Build a Content-Type header value for a file extension (falling back to 'txt' if $ext is unknown).

function extensionToContentType(string $ext, ?string $charset = 'utf-8'): string
Namespace
MMO\core\server
$extstringthe extension, without '.'
$charset = 'utf-8'null | stringappended as ;charset=... if given. null to omit it.
returnsstring
extensionToContentType('json'); // 'application/json;charset=utf-8'
Call graph
function

extractContentType

server.php:663

Strip a leading Content-Type: label (if present) off a header line, and split it on , into its individual content-type values (a header CAN legally list several, comma-separated).

function extractContentType(string $header): array
Namespace
MMO\core\server
$headerstringa full Content-Type: ... header line, or just its value
returnsarraya list of content type
extractContentType('Content-Type: application/json; charset=utf-8'); // ['application/json; charset=utf-8']
Call graph
function

hostname

server.php:343

Get the server's own hostname: $_SERVER['SERVER_NAME'] if set, else the system hostname.

function hostname(): string
Namespace
MMO\core\server
returnsstring'localhost.localdomain' if nothing valid could be determined
Call graph
function

httpStatus

server.php:610

Sanitize a value for use as an HTTP status code: pass it through if it is an int that isHttpStatus(), else fall back to 500. Used e.g. when turning an exception's (arbitrary, application-defined) code into a response status, httpStatus($e->getCode()): that code is not always an int -- a PDOException's is its SQLSTATE, a string such as 'HY000' or '42S02' -- and a string is never taken for a status, even a numeric one ('23000' is a SQLSTATE).

function httpStatus(mixed $status): int
Namespace
MMO\core\server
NOTE: this used to take an `int`, so such a code made the error handler itself throw a TypeError: an uncaught PDOException ended in a PHP fatal (exit 255) instead of a 500 response.
$statusmixedan HTTP status, or any exception's code
returnsint
httpStatus(404); // 404 httpStatus(999); // 500 -- not a plausible HTTP status httpStatus('HY000'); // 500 -- a PDOException's code
Call graph
function

info

server.php:851

Parses phpinfo() output and returns a structured array.

function info(int $flags = MMO\core\server\INFO_ALL): array
Namespace
MMO\core\server
Works in two modes: - HTML mode : captures the HTML output of phpinfo() and parses it with DOMDocument. - CLI mode : captures the plain-text output of phpinfo() and parses it line by line.
$flags = MMO\core\server\INFO_ALLintphpinfo() flags (default: INFO_ALL). Same constants as phpinfo().
returnsarrayAssociative array [ 'Section Name' => [ 'key' => 'value', ... ], ... ] In HTML mode, two-column rows produce 'key' => 'local_value' and three-column rows produce 'key' => ['local' => ..., 'master' => ...].
function

infoHTML

server.php:945

Capture phpinfo()'s HTML output as a standalone, embeddable fragment: styles are rescoped under #phpinfo (instead of being global) and the surrounding <html>/<head>/<body> are stripped, so this can be inserted into an existing page (e.g. an admin panel) without it clobbering that page's own styles.

function infoHTML(): string
Namespace
MMO\core\server
returnsstring
function

ip

server.php:357

Get the client's IP address, from the first of HTTP_CLIENT_IP/HTTP_X_FORWARDED_FOR/REMOTE_ADDR that's set.

function ip(): string
Namespace
MMO\core\server
WARNING: `HTTP_CLIENT_IP`/`HTTP_X_FORWARDED_FOR` are ordinary request headers -- a client can set them to whatever it wants. Only trust them if the request genuinely goes through a proxy you control that overwrites/strips them; otherwise `REMOTE_ADDR` alone is the only value that can't be spoofed by the client.
returnsstring
Call graph
function

isContentType

server.php:768

Test whether a Content-Type header matches a given file extension's MIME type(s) (extension()).

function isContentType(string $ext, string $types): bool
Namespace
MMO\core\server
ex: to test if content type is an http form, use: isContentType('http', $_SERVER['CONTENT_TYPE'])
$extstringthe extension to test against (in MIMES)
$typesstringthe content type header (can contain a charset or multiple types)
returnsbool
isContentType('json', 'application/json; charset=utf-8'); // true
Call graph

Uses (1)

Used by (1)

function

isHttpStatus

server.php:592

Tells if $status is a plausible HTTP status code (100-599).

function isHttpStatus(int $status): bool
Namespace
MMO\core\server
NOTE: this used to have no upper bound (`$status >= 200` alone was considered valid), so any large integer -- e.g. an application-defined exception code being mistakenly passed as an HTTP status by [`httpStatus()`](https://mcp.mmoframework.fr/documentation/mmo.core/php/server.md#httpstatus) -- was accepted as "valid" and passed straight through instead of being rejected.
$statusint
returnsbool
isHttpStatus(404); // true isHttpStatus(999); // false
Call graph

Used by (1)

function

isOk

server.php:622

Tells if a status is a "success" HTTP status: [200, 400).

function isOk(int $status): bool
Namespace
MMO\core\server
$statusint
returnsbool
isOk(200); // true isOk(404); // false
Call graph
function

isValidHost

server.php:321

Validate whether a string contains a valid value to use as a hostname or IP address.

function isValidHost(string $host): bool
Namespace
MMO\core\server
IPv6 addresses must include [], e.g. `[::1]`, not just `::1`.
$hoststringThe host name or IP address to check
returnsbool
Call graph

Used by (1)

function

matchAccept

server.php:820

Parse a weighted Accept-family HTTP header (sortAccept()) and find the best-matching entry in $supported: the header's options are tried highest-weight first, and the first one present as a key in $supported wins; if only a wildcard matched, the FIRST entry of $supported is returned instead.

function matchAccept(array|string $header, array $supported): ?string
Namespace
MMO\core\server
$headerarray | stringthe HTTP "Accept" header to parse
$supportedarraya list of supported values. The KEYS are compared against the header (so they must be lowercased, matching sortAccept()'s own lowercasing); the matching entry's VALUE is what's returned, so keys/values can differ (e.g. mime-type key -> short-name value)
returnsnull | stringthe matched entry's value, or null if nothing (not even a wildcard) matched
matchAccept('text/html,application/xml;q=0.9', ['application/json' => 'json', 'text/html' => 'html']); // 'html'
Call graph
function

mime

server.php:738

Get the MIME type(s) (MIMES) registered for a file extension.

function mime(string $ext, bool $single = true): array|string|null
Namespace
MMO\core\server
$extstringthe extension, without '.'
$single = trueboolif true, return only the first/canonical MIME type; if false, return every alias
returnsarray | string | nullnull if $ext isn't in MIMES
mime('json'); // 'application/json' mime('jpg', false); // ['image/jpeg', 'image/pjpeg']
Call graph
function

origin

server.php:383

Get the requesting page's url: the Referer header, falling back to the Origin header.

function origin(): ?string
Namespace
MMO\core\server
returnsnull | stringnull if neither header is set
Call graph
function

reasonPhrase

server.php:647

Turn a message into an HTTP reason phrase (the status line's text, statusText in a browser): one line, of at most 1024 bytes, in ISO-8859-1 -- the only charset a status line has, so a browser reads it that way.

function reasonPhrase(string $message): string
Namespace
MMO\core\server
NOTE: an error response's reason is its exception's message ([`Application::createErrorResponse`](https://mcp.mmoframework.fr/documentation/mmo.core/php/Application.md#application-createerrorresponse)); sent as UTF-8, its accents were shown broken (`é` as `é`), and a line break in it cut the headers short.
$messagestringUTF-8 text
returnsstringISO-8859-1 text; a character it has not becomes its nearest ascii (’ -> ') or ?.
reasonPhrase("Le modèle n’a pas été trouvé\n(dat.phtml)"); // "Le mod\xE8le n'a pas \xE9t\xE9 trouv\xE9 (dat.phtml)"
Call graph
function

scriptName

server.php:408

Get the absolute filename of the currently running script (works both under a web server and on the CLI).

function scriptName(): string
Namespace
MMO\core\server
returnsstring
Call graph
function

sortAccept

server.php:786

Parse a (comma-separated, or already split) Accept-family HTTP header (Accept, Accept-Language, ...) and sort its options by weight (the ;q= parameter), highest first. An option with no explicit weight is ranked by its position in the header (earlier = higher); a bare * or a type wildcard is ranked lowest of all (even below the lowest EXPLICIT weight) unless it has its own explicit ;q=.

function sortAccept(array|string $header): array
Namespace
MMO\core\server
$headerarray | string
returnsarrayfloat> [lowercased option => weight], sorted highest weight first
sortAccept('en-US,fr;q=0.9,de;q=0.8'); // ['en-us' => 1000, 'fr' => 0.9, 'de' => 0.8]
Call graph
function

statusMessage

server.php:634

Get the human-readable message for an HTTP status or shell exit code (MESSAGES).

function statusMessage(int $status): string
Namespace
MMO\core\server
$statusintany HTTP status or shell EXIT_* code
returnsstring
statusMessage(404); // 'Not Found' statusMessage(999); // '[unknown status]'
Call graph
function

url

server.php:419

Get the current request's full url. On the CLI, this is a file:// uri built from scriptName().

function url(bool $join = true): array|string
Namespace
MMO\core\server
$join = trueboolif true, return a joined string; if false, return the split parts array (split())
returnsarray | string
Call graph