Override the $serverName after the server object initialized

This commit is contained in:
huangzhhui 2019-06-18 19:26:41 +08:00
parent 528798723b
commit d99f4dde9f
2 changed files with 18 additions and 0 deletions

View File

@ -119,4 +119,18 @@ class Server implements OnRequestInterface, MiddlewareInitializerInterface
Context::set(ResponseInterface::class, $psr7Response = new Psr7Response($response));
return [$psr7Request, $psr7Response];
}
public function getServerName(): string
{
return $this->serverName;
}
/**
* @return $this
*/
public function setServerName(string $serverName)
{
$this->serverName = $serverName;
return $this;
}
}

View File

@ -187,6 +187,10 @@ class Server implements ServerInterface
$this->onRequestCallbacks[$className] = $serverName;
$class = $this->container->get($className);
if (method_exists($class, 'setServerName')) {
// Override the server name.
$class->setServerName($serverName);
}
if ($class instanceof MiddlewareInitializerInterface) {
$class->initCoreMiddleware($serverName);
}