本文整理匯總了PHP中Slim\App::process方法的典型用法代碼示例。如果您正苦於以下問題:PHP App::process方法的具體用法?PHP App::process怎麽用?PHP App::process使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Slim\App
的用法示例。
在下文中一共展示了App::process方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: runApp
/**
* Process the application given a request method and URI
*
* @param string $requestMethod the request method (e.g. GET, POST, etc.)
* @param string $requestUri the request URI
* @param array|object|null $requestData the request data
* @return \Slim\Http\Response
*/
public function runApp($requestMethod, $requestUri, $requestData = null)
{
// Create a mock environment for testing with
$environment = Environment::mock(['REQUEST_METHOD' => $requestMethod, 'REQUEST_URI' => $requestUri]);
// Set up a request object based on the environment
$request = Request::createFromEnvironment($environment);
// Add request data, if it exists
if (isset($requestData)) {
$request = $request->withParsedBody($requestData);
}
// Set up a response object
$response = new Response();
// Use the application settings
$settings = (require __DIR__ . '/../../src/settings.php');
// Instantiate the application
$app = new App($settings);
// Set up dependencies
require __DIR__ . '/../../src/dependencies.php';
// Register middleware
if ($this->withMiddleware) {
require __DIR__ . '/../../src/middleware.php';
}
// Register routes
require __DIR__ . '/../../src/routes.php';
// Process the application
$response = $app->process($request, $response);
// Return the response
return $response;
}
示例2: getCallbacks
/**
* Returns the two callbacks which will process the HTTP call
*
* @param \Slim\App $app Slim application instance
*
* @return callable
*/
private function getCallbacks(\Slim\App $app)
{
$server = $this;
return function (\React\Http\Request $request, \React\Http\Response $response) use($app, $server) {
$request->on('data', function ($body) use($request, $response, $app, $server) {
$slRequest = SlimRequest::createFromReactRequest($request, $body);
$boundary = SlimRequest::checkPartialUpload($slRequest);
$slResponse = SlimResponse::createResponse();
if ($boundary !== false) {
if (isset($server->partials[$boundary]) === false) {
$server->partials[$boundary]['boundary'] = $boundary;
}
$continue = SlimRequest::parseBody($body, $server->partials[$boundary]);
if ($continue === false) {
$filesArr = SlimRequest::getSlimFilesArray($server->partials[$boundary]);
$lastRequest = $slRequest->withUploadedFiles($filesArr)->withParsedBody($server->partials[$boundary]['fields']);
$slResponse = $app->process($lastRequest, $slResponse);
SlimResponse::setReactResponse($response, $slResponse, true);
}
} else {
$slResponse = $app->process($slRequest, $slResponse);
SlimResponse::setReactResponse($response, $slResponse, true);
}
});
};
}