ServerOptions extends Options
Represents server-related configuration options for a website.
This class extends Options to store and manipulate key information about a website hosted on a server, such as its domain, subdomain, URL, PHP version, and document root path (htdocs).
It provides helper methods to construct a full domain name expression (with customizable ordering and separators) and to generate a complete server name suitable for server configurations (e.g., virtual hosts).
Properties
- self::$domain The website's main domain.
- self::$subdomain The website's subdomain (e.g., "www", "admin").
- self::$url The full URL of the website.
- self::$php The PHP version used by the site.
- self::$htdocs The document root path on the server.
Usage example
use oihana\commands\options\ServerOptions;
$opt = new ServerOptions();
$opt->domain = 'example.com';
$opt->subdomain = 'admin';
echo $opt->getFullDomain() . PHP_EOL; // "admin.example.com"
echo $opt->getFullDomain(true) . PHP_EOL; // "example.com.admin"
echo $opt->getFullDomain(false, '-') . PHP_EOL; // "admin-example.com"
echo $opt->getFullServerName() . PHP_EOL; // "admin.example.com"
// When subdomain is 'www'
$opt->subdomain = 'www';
echo $opt->getFullServerName() . PHP_EOL; // "example.com www.example.com"
Tags
Table of Contents
Constants
- SERVER = 'server'
- The 'server' constant.
Properties
- $domain : string|null
- The website domain.
- $htdocs : string|null
- The htdocs directory of the website on the server.
- $php : string|null
- The php version.
- $subdomain : string|null
- The website subdomain.
- $url : string|null
- The url of the website.
Methods
- __toString() : string
- Returns the string representation of the object.
- getFullDomain() : string
- Returns the full domain expression.
- getFullServerName() : string
- Returns the full servername expression.
Constants
SERVER
The 'server' constant.
public
mixed
SERVER
= 'server'
Properties
$domain
The website domain.
public
string|null
$domain
= null
$htdocs
The htdocs directory of the website on the server.
public
string|null
$htdocs
= null
$php
The php version.
public
string|null
$php
= null
$subdomain
The website subdomain.
public
string|null
$subdomain
= null
$url
The url of the website.
public
string|null
$url
= null
Methods
__toString()
Returns the string representation of the object.
public
__toString() : string
Return values
stringgetFullDomain()
Returns the full domain expression.
public
getFullDomain([bool $reverse = false ][, string $separator = Char::DOT ]) : string
Constructs the full domain name by combining the subdomain and domain properties.
If $reverse
is false (default), the order is: subdomain.domain
If $reverse
is true, the order is: domain.subdomain
Empty or null values are ignored in the final result.
Parameters
- $reverse : bool = false
-
Indicates if the domain is before the subdomain in the final expression or not.
- $separator : string = Char::DOT
-
The separator between the domain and the subdomain components (default is '.').
Tags
Return values
string —The full domain as a string.
getFullServerName()
Returns the full servername expression.
public
getFullServerName() : string