本文整理汇总了PHP中Psr\Http\Message\ServerRequestInterface::getParsedBody方法的典型用法代码示例。如果您正苦于以下问题:PHP ServerRequestInterface::getParsedBody方法的具体用法?PHP ServerRequestInterface::getParsedBody怎么用?PHP ServerRequestInterface::getParsedBody使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Psr\Http\Message\ServerRequestInterface
的用法示例。
在下文中一共展示了ServerRequestInterface::getParsedBody方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: mainAction
/**
* Process add media request
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @return ResponseInterface
*/
public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
{
$files = $request->getParsedBody()['file'];
$newMedia = [];
if (isset($files['newMedia'])) {
$newMedia = (array) $files['newMedia'];
}
foreach ($newMedia as $media) {
if (!empty($media['url']) && !empty($media['target'])) {
$allowed = !empty($media['allowed']) ? GeneralUtility::trimExplode(',', $media['allowed']) : [];
$file = $this->addMediaFromUrl($media['url'], $media['target'], $allowed);
if ($file !== null) {
$flashMessage = GeneralUtility::makeInstance(FlashMessage::class, $file->getName(), $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:online_media.new_media.added'), FlashMessage::OK, true);
} else {
$flashMessage = GeneralUtility::makeInstance(FlashMessage::class, $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:online_media.error.invalid_url'), $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:online_media.error.new_media.failed'), FlashMessage::ERROR, true);
}
$this->addFlashMessage($flashMessage);
}
}
$redirect = isset($request->getParsedBody()['redirect']) ? $request->getParsedBody()['redirect'] : $request->getQueryParams()['redirect'];
$redirect = GeneralUtility::sanitizeLocalUrl($redirect);
if ($redirect) {
$response = $response->withHeader('Location', GeneralUtility::locationHeaderUrl($redirect))->withStatus(303);
}
return $response;
}
示例2: __invoke
/**
* @param Request $request
* @param Response $response
* @param callable $next
* @return \Psr\Http\Message\MessageInterface|HtmlResponse
* @throws Exception
*/
public function __invoke(Request $request, Response $response, callable $next)
{
//$form = new LoginForm('Login', []);
//$form->get('submit')->setValue('Login');
if ($request->getMethod() == 'POST') {
$auth = new AuthenticationService();
$query = $request->getParsedBody();
$authAdapter = new AuthAdapter($query['login'], $query['password'], $this->authConfig);
$result = $auth->authenticate($authAdapter);
if (!$result->isValid()) {
//$response->getBody()->write("Not valid authentication\n");
//return $response->withStatus(403)->withHeader("Content-type", 'text/html');
throw new Exception("Not valid authentication\n", 403);
} else {
if ($request->getUri()->getPath() === '/auth') {
$render = $this->template->render('app::homepage');
$query = $request->getParsedBody();
$query['view']['render'] = $render;
$query['view']['code'] = 200;
$request = $request->withParsedBody($query);
}
return $next($request, $response);
}
} else {
$render = $this->template->render('app::login', ['error' => null]);
$query = $request->getParsedBody();
$query['view']['render'] = $render;
$query['view']['code'] = 200;
$request = $request->withParsedBody($query);
return $next($request, $response);
}
}
示例3: index
/**
* Index action shows install tool / step installer or redirect to action to enable install tool
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @return ResponseInterface
*/
public function index(ServerRequestInterface $request, ResponseInterface $response)
{
/** @var EnableFileService $enableFileService */
$enableFileService = GeneralUtility::makeInstance(EnableFileService::class);
/** @var AbstractFormProtection $formProtection */
$formProtection = FormProtectionFactory::get();
if ($enableFileService->checkInstallToolEnableFile()) {
// Install tool is open and valid, redirect to it
$response = $response->withStatus(303)->withHeader('Location', 'sysext/install/Start/Install.php?install[context]=backend');
} elseif ($request->getMethod() === 'POST' && $request->getParsedBody()['action'] === 'enableInstallTool') {
// Request to open the install tool
$installToolEnableToken = $request->getParsedBody()['installToolEnableToken'];
if (!$formProtection->validateToken($installToolEnableToken, 'installTool')) {
throw new \RuntimeException('Given form token was not valid', 1369161225);
}
$enableFileService->createInstallToolEnableFile();
// Install tool is open and valid, redirect to it
$response = $response->withStatus(303)->withHeader('Location', 'sysext/install/Start/Install.php?install[context]=backend');
} else {
// Show the "create enable install tool" button
/** @var StandaloneView $view */
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:install/Resources/Private/Templates/BackendModule/ShowEnableInstallToolButton.html'));
$token = $formProtection->generateToken('installTool');
$view->assign('installToolEnableToken', $token);
/** @var ModuleTemplate $moduleTemplate */
$moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
$cssFile = 'EXT:install/Resources/Public/Css/BackendModule/ShowEnableInstallToolButton.css';
$cssFile = GeneralUtility::getFileAbsFileName($cssFile);
$moduleTemplate->getPageRenderer()->addCssFile(PathUtility::getAbsoluteWebPath($cssFile));
$moduleTemplate->setContent($view->render());
$response->getBody()->write($moduleTemplate->renderContent());
}
return $response;
}
示例4: handle
/**
* @param Request $request
* @return JsonResponse|EmptyResponse
*/
public function handle(Request $request)
{
$actor = $request->getAttribute('actor');
$Referer = $request->getHeader('Referer');
$params = array_only($request->getParsedBody(), ['identification', 'password']);
$response = $this->apiClient->send(TokenController::class, $actor, [], $params);
if ($response->getStatusCode() === 200) {
$data = json_decode($response->getBody());
$session = $request->getAttribute('session');
$this->authenticator->logIn($session, $data->userId);
$token = AccessToken::find($data->token);
event(new UserLoggedIn($this->users->findOrFail($data->userId), $token));
$response = FigResponseCookies::set($response, SetCookie::create("lastLoginName")->withValue($request->getParsedBody()['identification'])->withPath('/'));
$response = $this->rememberer->remember($response, $token);
} elseif ($response->getStatusCode() === 401) {
$responseNew = $this->apiClient->send(PingxxTokenController::class, $actor, [], $params);
if ($responseNew->getStatusCode() === 200) {
$data = json_decode($responseNew->getBody());
$session = $request->getAttribute('session');
$this->authenticator->logIn($session, $data->userId);
$token = AccessToken::find($data->token);
event(new UserLoggedIn($this->users->findOrFail($data->userId), $token));
$responseNew = FigResponseCookies::set($responseNew, SetCookie::create("lastLoginName")->withValue($request->getParsedBody()['identification'])->withPath('/')->withDomain('dashboard.pingxx.com'));
$responseNew = $this->rememberer->remember($responseNew, $token);
return $responseNew;
} else {
return $response;
}
}
return $response;
}
示例5: isValid
/**
* @param string $name
* @param array $options
*
* @return bool
*/
public function isValid($name, array $options = [])
{
$options += ['referer' => null, 'token' => null];
if (null === $options['token']) {
$params = $this->request->getParsedBody();
if (!isset($params[$name])) {
$this->invalidate();
return false;
} else {
$options['token'] = $params[$name];
}
}
$error = false;
$name .= $options['token'];
$config = array_get([self::TOKEN_KEY, $name], $this->storage, []);
$time = isset($config['expire']) ? $config['expire'] : 0;
if (time() > $time) {
$error = true;
}
if (!$error && null !== $options['referer']) {
$params = $this->request->getServerParams();
if (!isset($params['HTTP_REFERER']) || $params['HTTP_REFERER'] !== $options['referer']) {
$error = true;
}
}
$regenerate = array_key_exists('regenerate', $config) ? $config['regenerate'] : false;
if ($error || !$regenerate) {
array_remove([self::TOKEN_KEY, $name], $this->storage);
} elseif ($regenerate) {
$config['expire'] = time() + $config['time'];
array_set([self::TOKEN_KEY, $name], $config, $this->storage);
}
$this->invalidate();
return !$error;
}
示例6: convertRequestFromPsr7
/**
* Converts a PSR-7 request into an OAuth2 request.
*
* @param ServerRequestInterface $psrRequest
* @return Request
*/
public static function convertRequestFromPsr7(ServerRequestInterface $psrRequest)
{
$headers = [];
foreach ($psrRequest->getHeaders() as $header => $value) {
$headers[$header] = implode(';', $value);
}
return new Request($psrRequest->getQueryParams(), is_array($psrRequest->getParsedBody()) ? $psrRequest->getParsedBody() : [], $psrRequest->getAttributes(), $psrRequest->getCookieParams(), self::getFiles($psrRequest->getUploadedFiles()), $psrRequest->getServerParams(), $psrRequest->getBody()->__toString(), $headers);
}
示例7: __construct
/**
* @param ServerRequestInterface $request
* @param RouterInterface $router
*/
public function __construct(ServerRequestInterface $request, RouterInterface $router)
{
$this->request = $request;
parent::__construct($this);
$this->parameters = $this->parseIncomingParams();
$this->parameters = array_merge($this->parameters, $this->request->getParsedBody(), $this->getParsedAttributes($request, $router), $this->getQueryParams(), $this->request->getUploadedFiles());
$this->parsedBody = array_merge(parent::getParsedBody(), $this->parameters);
}
示例8: data
/**
* Get the data to be serialized and assigned to the response document.
*
* @param ServerRequestInterface $request
* @param Document $document
* @return mixed
*/
protected function data(ServerRequestInterface $request, Document $document)
{
$title = Arr::get($request->getParsedBody(), 'title');
$start_post_id = Arr::get($request->getParsedBody(), 'start_post_id');
$end_post_id = Arr::get($request->getParsedBody(), 'end_post_id');
$actor = $request->getAttribute('actor');
return $this->bus->dispatch(new SplitDiscussion($title, $start_post_id, $end_post_id, $actor));
}
示例9: getHelpAction
/**
* The main dispatcher function. Collect data and prepare HTML output.
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @return ResponseInterface
*/
public function getHelpAction(ServerRequestInterface $request, ResponseInterface $response)
{
$params = isset($request->getParsedBody()['params']) ? $request->getParsedBody()['params'] : $request->getQueryParams()['params'];
if ($params['action'] === 'getContextHelp') {
$result = $this->getContextHelp($params['table'], $params['field']);
$response->getBody()->write(json_encode(['title' => $result['title'], 'content' => $result['description'], 'link' => $result['moreInfo']]));
}
return $response;
}
示例10: processRequest
/**
* Renders/Echoes the ajax output
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @return ResponseInterface|NULL
* @throws \InvalidArgumentException
*/
public function processRequest(ServerRequestInterface $request, ResponseInterface $response)
{
$action = isset($request->getParsedBody()['action']) ? $request->getParsedBody()['action'] : (isset($request->getQueryParams()['action']) ? $request->getQueryParams()['action'] : '');
if (!in_array($action, array('route', 'getAPI'), true)) {
return null;
}
$this->routeAction($action);
return $this->ajaxObject->render();
}
示例11: validateCsrfToken
/**
* Validates CSRF token in given PSR-7 Request instance.
*
* @param ServerRequestInterface $request PSR-7 Request instance.
*
* @throws \Students\Exception\BadRequestException If CSRF check failed.
*
* @return boolean True if CSRF check was successful.
*/
public function validateCsrfToken(ServerRequestInterface $request)
{
$formToken = isset($request->getParsedBody()['csrf']) ? strval($request->getParsedBody()['csrf']) : '';
$cookie = FigRequestCookies::get($request, 'csrf');
if ($cookie->getValue() !== $formToken) {
throw new BadRequestException($request);
}
return true;
}
示例12: validate
/**
* Validates the request
* @param ServerRequestInterface $requestInterface
* @return bool|ValidationResult
*/
public function validate(ServerRequestInterface $requestInterface)
{
$this->decoratedRequest = new RequestValidator($requestInterface, $this->router);
$validatorProvider = $this->getValidatorObject($this->decoratedRequest);
if ($validatorProvider == null) {
return true;
} else {
return new ValidationResult($this->decoratedRequest->getParsedBody(), $validatorProvider, $this->entityManagerInterface, $this->decoratedRequest);
}
}
示例13: __construct
public function __construct(ServerRequestInterface $request)
{
$this->request = $request;
if ($request->getParsedBody()) {
$this->data = json_decode(json_encode($request->getParsedBody()), true);
} else {
$this->data = json_decode($request->getBody(), true);
}
$this->validateSchema();
}
示例14: logoutAction
/**
* Injects the request object for the current request or subrequest
* As this controller goes only through the main() method, it is rather simple for now
* This will be split up in an abstract controller once proper routing/dispatcher is in place.
*
* @param ServerRequestInterface $request the current request
* @param ResponseInterface $response
* @return ResponseInterface the response with the content
*/
public function logoutAction(ServerRequestInterface $request, ResponseInterface $response)
{
$this->logout();
$redirectUrl = isset($request->getParsedBody()['redirect']) ? $request->getParsedBody()['redirect'] : $request->getQueryParams()['redirect'];
$redirectUrl = GeneralUtility::sanitizeLocalUrl($redirectUrl);
if (empty($redirectUrl)) {
/** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
$uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
$redirectUrl = (string) $uriBuilder->buildUriFromRoute('login', array(), $uriBuilder::ABSOLUTE_URL);
}
return $response->withStatus(303)->withHeader('Location', GeneralUtility::locationHeaderUrl($redirectUrl));
}
示例15: saveSortingState
/**
* Saves the sorting order of tasks in the backend user's uc
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @return ResponseInterface
*/
public function saveSortingState(ServerRequestInterface $request, ResponseInterface $response)
{
$sort = array();
$data = isset($request->getParsedBody()['data']) ? $request->getParsedBody()['data'] : $request->getQueryParams()['data'];
$items = explode('&', $data);
foreach ($items as $item) {
$sort[] = substr($item, 12);
}
$this->getBackendUserAuthentication()->uc['taskcenter']['sorting'] = serialize($sort);
$this->getBackendUserAuthentication()->writeUC();
return $response;
}