本文整理汇总了PHP中Symfony\Component\HttpFoundation\Request::getContent方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getContent方法的具体用法?PHP Request::getContent怎么用?PHP Request::getContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\Request
的用法示例。
在下文中一共展示了Request::getContent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postAction
public function postAction(Request $request)
{
$repo = $this->get('tekstove.user.repository');
/* @var $repo \Tekstove\ApiBundle\Model\User\UserRepository */
$recaptchaSecret = $this->container->getParameter('tekstove_api.recaptcha.secret');
$requestData = \json_decode($request->getContent(), true);
$userData = $requestData['user'];
$recaptchaData = $requestData['recaptcha'];
$user = new User();
try {
$recaptcha = new \ReCaptcha\ReCaptcha($recaptchaSecret);
$recaptchaResponse = $recaptcha->verify($recaptchaData['g-recaptcha-response']);
if (!$recaptchaResponse->isSuccess()) {
$recaptchaException = new UserHumanReadableException("Recaptcha validation failed");
$recaptchaException->addError("recaptcha", "Validation failed");
throw $recaptchaException;
}
$user->setUsername($userData['username']);
$user->setMail($userData['mail']);
$user->setPassword($this->hashPassword($userData['password']));
$user->setapiKey(sha1(str_shuffle(uniqid())));
$repo->save($user);
} catch (UserHumanReadableException $e) {
$view = $this->handleData($request, $e->getErrors());
$view->setStatusCode(400);
return $view;
}
}
示例2: postAction
/**
* Writes a new Entry to the database
*
* @param Request $request Current http request
*
* @return \Symfony\Component\HttpFoundation\Response $response Result of action with data (if successful)
*/
public function postAction(Request $request)
{
$response = $this->getResponse();
$entityClass = $this->getModel()->getEntityClass();
$record = new $entityClass();
// Insert the new record
$record = $this->getModel()->insertRecord($record);
// store id of new record so we dont need to reparse body later when needed
$request->attributes->set('id', $record->getId());
$file = $this->saveFile($record->getId(), $request->getContent());
// update record with file metadata
$meta = new FileMetadata();
$meta->setSize((int) $file->getSize())->setMime($request->headers->get('Content-Type'))->setCreatedate(new \DateTime());
$record->setMetadata($meta);
$record = $this->getModel()->updateRecord($record->getId(), $record);
// Set status code and content
$response->setStatusCode(Response::HTTP_CREATED);
$routeName = $request->get('_route');
$routeParts = explode('.', $routeName);
$routeType = end($routeParts);
if ($routeType == 'post') {
$routeName = substr($routeName, 0, -4) . 'get';
}
$response->headers->set('Location', $this->getRouter()->generate($routeName, array('id' => $record->getId())));
return $response;
}
示例3: postChannelProgramsAction
/**
* @Silex\Route(
* @Silex\Request(method="POST", uri="channels/{channel}/programs"),
* @Silex\Convert(variable="channel", callback="entity.provider:convertChannel")
* )
*
* Todo: Handle error cases
*/
public function postChannelProgramsAction(Request $request, Channel $channel)
{
$program = $this->serializer->deserialize($request->getContent(), ProgramController::PROGRAM_ENTITY, 'json');
$program->setChannel($channel);
$channel->addProgram($program);
$program->generateUniqueId();
$eliminateDuplicates = function ($person) {
$found = $this->em->getRepository('Domora\\TvGuide\\Data\\Person')->findOneByName($person->getName());
return $found ?: $person;
};
// Eliminate credits duplicates
$credits = $program->getCredits();
if ($credits) {
$credits->replacePresenters($eliminateDuplicates);
$credits->replaceDirectors($eliminateDuplicates);
$credits->replaceWriters($eliminateDuplicates);
$credits->replaceActors($eliminateDuplicates);
$credits->replaceComposers($eliminateDuplicates);
$credits->replaceGuests($eliminateDuplicates);
}
// Import image if necessary
$data = json_decode($request->getContent(), true);
if (isset($data['image'])) {
$program->importImageFromUrl($data['image']);
}
try {
$this->em->persist($program);
$this->em->flush();
} catch (UniqueConstraintViolationException $e) {
throw new Error(409, 'PROGRAM_CONFLICT');
}
return new Success(200, 'PROGRAM_CREATED', $program);
}
示例4: postAction
/**
* Set the current configuration
*
* @AclAncestor("oro_config_system")
*
* @return JsonResponse
*/
public function postAction(Request $request)
{
$this->configManager->save(json_decode($request->getContent(), true));
$data = json_decode($request->getContent(), true);
file_put_contents($this->getMessagesFilePath(), $data['pim_ui___loading_messages']['value']);
return $this->getAction();
}
示例5: process
/**
* @param Request $request
*
* @throws ValidationException
* @throws MalformedContentException
*/
public function process(Request $request)
{
if (!$request->attributes->has(RequestMeta::ATTRIBUTE_URI)) {
throw new \UnexpectedValueException("Missing document URI");
}
$description = $this->repository->get($request->attributes->get(RequestMeta::ATTRIBUTE_URI));
$operation = $description->getPath($request->attributes->get(RequestMeta::ATTRIBUTE_PATH))->getOperation($request->getMethod());
$body = null;
if ($request->getContent()) {
$body = json_decode($request->getContent());
if (json_last_error() !== JSON_ERROR_NONE) {
throw new MalformedContentException(json_last_error_msg());
}
}
$result = $this->validator->validate($operation->getRequestSchema(), $coercedParams = $this->parametersAssembler->assemble($operation, $request->query->all(), $request->attributes->all(), $request->headers->all(), $body));
foreach ($coercedParams as $attribute => $value) {
/** @var ScalarSchema $schema*/
if (($schema = $operation->getParameter($attribute)->getSchema()) instanceof ScalarSchema) {
if ($schema->isDateTime()) {
$value = $this->dateTimeSerializer->deserialize($value, $schema);
}
}
$request->attributes->set($attribute, $value);
}
if ($this->hydrator && ($bodyParam = $description->getRequestBodyParameter($operation->getPath(), $operation->getMethod()))) {
$body = $this->hydrator->hydrate($body, $bodyParam->getSchema());
$request->attributes->set($bodyParam->getName(), $body);
}
$request->attributes->set(RequestMeta::ATTRIBUTE, new RequestMeta($description, $operation));
if (!$result->isValid()) {
throw new ValidationException($result->getErrorMessages());
}
}
示例6: __construct
/**
* @param LoggerInterface $logger
* @param Request $request
* @param array $options
*/
public function __construct(LoggerInterface $logger, Request $request, array $options = array())
{
$this->logger = $logger;
$this->options = $this->configureOptions($options);
$this->request = $request;
$this->logger->debug('Create call with params ' . json_encode($this->options));
$this->logger->debug('Request server values: ' . json_encode($this->request->server));
$this->host = $this->request->getClientIp();
$queryBag = $this->request->query;
$this->securityCode = $queryBag->has('securityCodeFieldName') ? $queryBag->get('securityCodeFieldName') : '';
$body = $this->request->getContent();
if (!$body) {
$this->logger->error('Event content is null');
$this->valid = false;
return;
}
$this->logger->debug('Event content: ' . $body);
try {
$json = json_decode($body, true);
} catch (\Exception $e) {
$this->logger->error('Exception on decode json text');
$this->valid = false;
}
if (!isset($json['ref'])) {
$this->valid = false;
return;
}
$count = count($json['commits']) - 1;
$this->author = $json['commits'][$count]['author']['email'];
$this->authorName = $json['commits'][$count]['author']['name'];
$this->message = $json['commits'][$count]['message'];
$this->timestamp = $json['commits'][$count]['timestamp'];
$this->repository = $json['repository'][$this->options['repositoryFieldName']];
$this->branch = substr($json['ref'], strrpos($json['ref'], '/') + 1);
}
示例7: generateFromRequest
public function generateFromRequest(Request $originalRequest)
{
$this->requestParser->fromXmlString($originalRequest->getContent());
$request = Request::create($this->getRoutePath($this->requestParser), "POST", (array) $this->getParameters($this->requestParser), $originalRequest->cookies->all(), array(), $originalRequest->server->all(), $originalRequest->getContent());
$request->attributes->set('xmlrpc_methodName', $this->requestParser->getMethodName());
return $request;
}
示例8: decodeRequest
/**
* Attempts to decode the incoming request's content as JSON.
*
* @param \Symfony\Component\HttpFoundation\Request $request
*
* @return mixed
*
* @throws \Drupal\panels_ipe\Exception\EmptyRequestContentException
*/
protected static function decodeRequest(Request $request)
{
if (empty($request->getContent())) {
throw new EmptyRequestContentException();
}
return Json::decode($request->getContent());
}
示例9: getRequestPayload
/**
* @return array
*/
protected function getRequestPayload()
{
if ($this->request->headers->get('Content-Type') === 'application/json') {
return json_decode($this->request->getContent(), true);
}
return $this->request->request->all();
}
示例10: prepareOptions
/**
* @param Request $request
* @return array
*/
private function prepareOptions(Request $request)
{
$options = array(CURLOPT_POST => 1, CURLOPT_HEADER => 0, CURLOPT_URL => $request->getSchemeAndHttpHost() . $request->getRequestUri(), CURLOPT_FRESH_CONNECT => 1, CURLOPT_RETURNTRANSFER => 1, CURLOPT_FORBID_REUSE => 1, CURLOPT_TIMEOUT => 20, CURLOPT_POSTFIELDS => $request->getContent(), CURLOPT_SSL_VERIFYHOST => false, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_HTTPHEADER => array('Content-Type: ' . $request->getContentType(), 'Content-Length: ' . strlen($request->getContent())));
foreach ($this->options as $key => $value) {
$options[$key] = $value;
}
return $options;
}
示例11: getPostData
/**
* @return array
*/
public function getPostData()
{
if ('json' === $this->_internalRequest->getContentType()) {
return (array) json_decode($this->_internalRequest->getContent(), true);
} else {
return $this->_internalRequest->request->all();
}
}
示例12: getStreamParams
/**
* @return ArrayCollection
*/
private function getStreamParams()
{
// get parameters from stream
$request = $this->request->getContent();
$requestArray = json_decode($request, true);
$streamParams = $requestArray === null ? new ArrayCollection() : new ArrayCollection($requestArray);
return $streamParams;
}
示例13: parseRequest
/**
* Parses a request
*
* @return \AppBundle\Events\Github
*/
protected function parseRequest()
{
$content = $this->request->getContent();
$this->request_content = json_decode($content, TRUE);
if (!$this->request_content) {
//@todo -> throw exception
}
$this->headers = apache_request_headers();
return $this;
}
示例14: initAction
/**
* @see GameControllerTest::unsuccessfulInitAction
* @see GameControllerTest::successfulInitAction_JSON
* @see GameControllerTest::successfulInitAction_XML
*
* @ApiDoc(
* section = "Game:: Mechanics",
* description = "Creates a new game from the submitted data",
* input = "EM\GameBundle\Request\GameInitiationRequest",
* responseMap = {
* 201 = "EM\GameBundle\Response\GameInitiationResponse"
* },
* statusCodes = {
* 400 = "invalid request"
* }
* )
*
* @param Request $request
*
* @return Response
* @throws \Exception
*/
public function initAction(Request $request) : Response
{
if (!$this->get('battleship_game.validator.game_initiation_request')->validate($request->getContent())) {
throw new HttpException(Response::HTTP_BAD_REQUEST, 'request validation failed, please check documentation');
}
$game = $this->get('battleship_game.service.game_builder')->buildGame(new GameInitiationRequest($request->getContent()));
$om = $this->getDoctrine()->getManager();
$om->persist($game);
$om->flush();
return $this->prepareSerializedResponse(new GameInitiationResponse($game->getBattlefields()), Response::HTTP_CREATED);
}
示例15: createFromRequest
/**
* @param string $collectorName
*
* @return RequestObject
*/
public function createFromRequest($collectorName)
{
$requestObject = new RequestObject();
$requestObject->setHeaders($this->request->headers->all());
$requestObject->setPostParameters($this->request->request->all());
$requestObject->setQueryParameters($this->request->query->all());
$requestObject->setContent($this->request->getContent());
$requestObject->setCollector($collectorName);
$requestObject->setUri($this->request->getUri());
$requestObject->setMethod($this->request->getMethod());
return $requestObject;
}