mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-04 04:37:46 +08:00
Override the $serverName after the server object initialized
This commit is contained in:
parent
528798723b
commit
d99f4dde9f
@ -119,4 +119,18 @@ class Server implements OnRequestInterface, MiddlewareInitializerInterface
|
|||||||
Context::set(ResponseInterface::class, $psr7Response = new Psr7Response($response));
|
Context::set(ResponseInterface::class, $psr7Response = new Psr7Response($response));
|
||||||
return [$psr7Request, $psr7Response];
|
return [$psr7Request, $psr7Response];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getServerName(): string
|
||||||
|
{
|
||||||
|
return $this->serverName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setServerName(string $serverName)
|
||||||
|
{
|
||||||
|
$this->serverName = $serverName;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -187,6 +187,10 @@ class Server implements ServerInterface
|
|||||||
|
|
||||||
$this->onRequestCallbacks[$className] = $serverName;
|
$this->onRequestCallbacks[$className] = $serverName;
|
||||||
$class = $this->container->get($className);
|
$class = $this->container->get($className);
|
||||||
|
if (method_exists($class, 'setServerName')) {
|
||||||
|
// Override the server name.
|
||||||
|
$class->setServerName($serverName);
|
||||||
|
}
|
||||||
if ($class instanceof MiddlewareInitializerInterface) {
|
if ($class instanceof MiddlewareInitializerInterface) {
|
||||||
$class->initCoreMiddleware($serverName);
|
$class->initCoreMiddleware($serverName);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user