Aerys\Host::name PHP Method

name() public method

A host name is only required if a server exposes more than one host. If a name is not defined the server will default to "localhost"
public name ( string $name ) : Host
$name string
return Host
    public function name(string $name) : Host
    {
        $this->name = $name;
        return $this;
    }

Usage Example

Example #1
0
        $sslCert = realpath($config['web-api']['ssl']['cert-path']);
        if (!$sslCert) {
            throw new InvalidConfigurationException('Invalid SSL certificate path');
        }
        $sslKey = null;
        if (isset($config['web-api']['ssl']['key-path']) && !($sslKey = realpath($config['web-api']['ssl']['key-path']))) {
            throw new InvalidConfigurationException('Invalid SSL key path');
        }
        $sslContext = $config['web-api']['ssl']['context'] ?? [];
        $host->encrypt($sslCert, $sslKey, $sslContext);
    }
    $bindAddr = $config['web-api']['bind-addr'] ?? '127.0.0.1';
    $bindPort = (int) ($config['web-api']['bind-port'] ?? ($sslEnabled ? 1337 : 1338));
    $host->expose($bindAddr, $bindPort);
    if (isset($config['web-api']['host'])) {
        $host->name($config['web-api']['host']);
    }
    /** @var WebAPIServer $api */
    $api = $injector->make(WebAPIServer::class);
    $host->use($api->getRouter());
    (new Bootstrapper(function () use($host) {
        return [$host];
    }))->init(new AerysLogger($injector->make(Logger::class)))->start();
}
onError(function (\Throwable $e) {
    fwrite(STDERR, "\nAn exception was not handled:\n\n{$e}\n\n");
});
try {
    run();
} catch (\Throwable $e) {
    fwrite(STDERR, "\nSomething went badly wrong:\n\n{$e}\n\n");