本文整理汇总了PHP中Handler::serve方法的典型用法代码示例。如果您正苦于以下问题:PHP Handler::serve方法的具体用法?PHP Handler::serve怎么用?PHP Handler::serve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Handler
的用法示例。
在下文中一共展示了Handler::serve方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: worker
protected function worker(Handler $handler, array $app_definition)
{
// Make sure, that we have the needed class
if (!class_exists($app_definition['class'])) {
if (empty($app_definition['file'])) {
throw new \LogicException('Class ' . $app_definition['class'] . ' can not be loaded');
}
$path = $this->cwd . '/' . $app_definition['file'];
if (!file_exists($path)) {
throw new \LogicException('File ' . $path . ' is not found');
}
require $path;
if (!class_exists($app_definition['class'])) {
throw new \LogicException('Class ' . $app_definition['class'] . ' is not found');
}
}
// Instantiate the object
if (isset($app_definition['parameters']) and count($app_definition['parameters']) > 0) {
$reflect = new \ReflectionClass($app_definition['class']);
$app = $reflect->newInstanceArgs($app_definition['parameters']);
} else {
$app = new $app_definition['class']();
}
// Instantiate the middlewares chain
foreach (array_reverse($app_definition['middlewares']) as $middleware) {
if (is_array($middleware)) {
$mw_class = $middleware['class'];
$mw_params = array_merge(array($app), $middleware['parameters']);
$reflect = new \ReflectionClass($mw_class);
$app = $reflect->newInstanceArgs($mw_params);
} else {
$mw_class = 'AiP\\Middleware\\' . $middleware;
$app = new $mw_class($app);
}
}
// Serve the app
try {
pcntl_signal(SIGUSR1, array($handler, 'graceful'), false);
$handler->serve($app);
pcntl_signal(SIGUSR1, SIG_DFL);
} catch (\Exception $e) {
}
}