当前位置: 首页>>代码示例>>PHP>>正文


PHP Request::getContent方法代码示例

本文整理汇总了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;
     }
 }
开发者ID:Tekstove,项目名称:Tekstove-api,代码行数:28,代码来源:RegisterController.php

示例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;
 }
开发者ID:smoskalenko,项目名称:graviton,代码行数:33,代码来源:FileController.php

示例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);
 }
开发者ID:nawrasg,项目名称:tvguide,代码行数:41,代码来源:ChannelController.php

示例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();
 }
开发者ID:a2xchip,项目名称:pim-community-dev,代码行数:14,代码来源:ConfigurationController.php

示例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());
     }
 }
开发者ID:kleijnweb,项目名称:swagger-bundle,代码行数:39,代码来源:RequestProcessor.php

示例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);
 }
开发者ID:amaxlab,项目名称:git-web-hook,代码行数:40,代码来源:Event.php

示例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;
 }
开发者ID:bdunogier,项目名称:xmlrpcbundle,代码行数:7,代码来源:RequestGenerator.php

示例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());
 }
开发者ID:nB-MDSO,项目名称:mdso-d8blog,代码行数:16,代码来源:RequestHandlerBase.php

示例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();
 }
开发者ID:pmill,项目名称:doctrine-rest-api,代码行数:10,代码来源:RequestHelperTrait.php

示例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;
 }
开发者ID:avanderree,项目名称:symfony-rpc-bundle,代码行数:12,代码来源:TransportCurl.php

示例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();
     }
 }
开发者ID:codespot,项目名称:wrestler,代码行数:11,代码来源:Request.php

示例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;
 }
开发者ID:danrevah,项目名称:sandbox-bundle,代码行数:11,代码来源:SandboxListener.php

示例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;
 }
开发者ID:andou,项目名称:gancin,代码行数:15,代码来源:Github.php

示例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);
 }
开发者ID:eugene-matvejev,项目名称:battleship-game-api,代码行数:33,代码来源:GameController.php

示例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;
 }
开发者ID:deuzu,项目名称:request-collector-bundle,代码行数:17,代码来源:RequestObjectProvider.php


注:本文中的Symfony\Component\HttpFoundation\Request::getContent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。