本文整理匯總了PHP中Centreon\Internal\Di::set方法的典型用法代碼示例。如果您正苦於以下問題:PHP Di::set方法的具體用法?PHP Di::set怎麽用?PHP Di::set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Centreon\Internal\Di
的用法示例。
在下文中一共展示了Di::set方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testGetBadServiceType
public function testGetBadServiceType()
{
$di = new Di();
$di->set('badservice', array());
$this->setExpectedException('\\Centreon\\Internal\\Exception', "Bad type of service");
$di->get('badservice');
}
示例2: initRoutes
/**
* Init routes
*/
private function initRoutes()
{
$this->di->set('router', function () {
$router = new Router();
/* Add middleroute for CSRF token */
$router->respond(function ($request, $response, $service, $app) {
/* Get the token */
$headers = $request->headers();
$tokenValue = '';
foreach (Csrf::getHeaderNames() as $headerName) {
if ($headers->exists($headerName)) {
$tokenValue = $headers[$headerName];
break;
}
}
$toSend = false;
/*
* Test if must test the token
* @todo better management with middleware global implementation
*/
$excludeRoute = array('/api');
$matchingRoute = array_filter($excludeRoute, function ($route) use($request) {
$route = rtrim(Di::getDefault()->get('config')->get('global', 'base_url'), '/') . $route;
if ($route == substr($request->pathname(), 0, strlen($route))) {
return true;
}
return false;
});
if (count($matchingRoute) == 0) {
if (false === Csrf::checkToken($tokenValue, $request->method())) {
$toSend = true;
$response->code(403)->json(array("message" => "CSRF Token is no valid"));
$response->send();
// @todo Exception
exit;
} else {
if (Csrf::mustBeGenerate($request->method())) {
/* Generate and send a new csrf cookie */
$response->cookie(Csrf::getCookieName(), Csrf::generateToken(), 0);
$response->sendCookies(true);
}
}
}
});
/* Parsing route */
$router->parseRoutes();
return $router;
});
}