本文整理汇总了PHP中FOS\RestBundle\Request\ParamFetcher类的典型用法代码示例。如果您正苦于以下问题:PHP ParamFetcher类的具体用法?PHP ParamFetcher怎么用?PHP ParamFetcher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ParamFetcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getAction
/**
* @FosRest\Get("/{section}")
*
* @ApiDoc(
* description = "Get the details of a section."
* )
*
* @ParamConverter("section", class="MainBundle:Section")
*
* @FosRest\QueryParam(
* name = "token",
* nullable = false,
* description = "Mobilit token."
* )
*
* @param Section $section
* @param ParamFetcher $paramFetcher
*
* @return Response
*/
public function getAction(Section $section, ParamFetcher $paramFetcher)
{
if ($this->container->getParameter('mobilit_token') != $paramFetcher->get('token')) {
return new Response(json_encode(["message" => $this->get('translator')->trans("errors.api.android.v1.token")]), Response::HTTP_FORBIDDEN);
}
return new Response($this->get('serializer')->serialize($section, 'json', SerializationContext::create()->setGroups(array('details'))));
}
示例2: getRecommendedGamesAction
/**
* @Rest\GET("/me/recommended-games")
* @QueryParam(name="lat", nullable=true)
* @QueryParam(name="long", nullable=true)
* @View(serializerEnableMaxDepthChecks=true)
*/
public function getRecommendedGamesAction(ParamFetcher $paramFetcher)
{
$dm = $this->get('doctrine.odm.mongodb.document_manager');
$user = $this->get('security.context')->getToken()->getUser();
if ($user == "anon.") {
throw new NotFoundHttpException();
}
$lat = $paramFetcher->get('lat') != null ? floatval($paramFetcher->get('lat')) : $user->getAddress()->getCoordinates()->getX();
$long = $paramFetcher->get('long') != null ? floatval($paramFetcher->get('long')) : $user->getAddress()->getCoordinates()->getY();
if (!isset($lat) || !isset($long)) {
throw new NotFoundHttpException(" Debe haber alguna localización");
}
$nearCenters = $dm->getRepository('MIWDataAccessBundle:Center')->findClosestCenters($lat, $long);
$geolocationService = $this->get('geolocation_service');
$recommendedGames = array();
$sports = $user->getSports();
$sportsKey = is_array($sports) ? array_keys($sports) : array();
foreach ($nearCenters as $center) {
$games = $dm->getRepository('MIWDataAccessBundle:Game')->findAllByCenterAndSports($center, $sportsKey);
$coordinates = $center->getAddress()->getCoordinates();
if (count($games) > 0) {
foreach ($games as $game) {
$line = array();
$line['distance'] = $geolocationService->getDistance($lat, $long, $coordinates->getX(), $coordinates->getY(), "K");
$line['game'] = $game;
$recommendedGames[] = $line;
}
}
}
return $this->view($recommendedGames, 200);
}
示例3: postCategoryAction
/**
* Create a Category from the submitted data.
*
* @ApiDoc(
* resource = true,
* description = "Creates a new category from the submitted data.",
* statusCodes = {
* 201 = "Returned when successful",
* 400 = "Returned when the form has errors"
* }
* )
*
* @param ParamFetcher $paramFetcher Paramfetcher
*
* @RequestParam(name="label", nullable=false, strict=true, description="Label.")
* @RequestParam(name="description", nullable=true, strict=true, description="Description.")
* @RequestParam(name="color", nullable=true, strict=true, description="Color.")
*
* @return View
*/
public function postCategoryAction(ParamFetcher $paramFetcher)
{
$label = filter_var($paramFetcher->get('label'), FILTER_SANITIZE_STRING);
$desc = filter_var($paramFetcher->get('description'), FILTER_SANITIZE_STRING);
$statusCode = 201;
if (isset($label) && $label != '') {
// $category = new Task();
// $category->setLabel($label);
// $category->setDescription($desc);
// $category->setDate(new \DateTime('now'));
//
// $manager = $this->getEntityManager();
// $manager->persist($category);
// $manager->flush();
// $id = $category->getId();
// if(!isset($id)) {
// $statusCode = 400;
// }
} else {
$statusCode = 400;
}
$view = View::create();
$view->setData('')->setStatusCode($statusCode);
return $view;
}
示例4: postPostulant
/**
* Ajoute un postulant à une voiture
*
* @ApiDoc(
* resource = true,
* description = "Ajoute un postulant à une voiture",
* statusCodes = {
* 201 = "Created",
* 404 = "Returned when the voiture is not found"
* }
* )
* @RequestParam(name="nomPostulant", nullable=true, strict=true, description="nom postulant.")
* @RequestParam(name="telephone", nullable=true, strict=true, description="telephone postulant.")
* @RequestParam(name="idVoiture", nullable=true,requirements="\d+", strict=true, description="id voiture postulant.")
* @Route("api/postulants",name="nicetruc_post_postulant", options={"expose"=true})
* @Method({"POST"})
*/
public function postPostulant(ParamFetcher $paramFetcher)
{
// try{
$em = $this->getDoctrine()->getManager();
$voiture = $em->getRepository('AppBundle:Voiture')->customFind($paramFetcher->get('idVoiture'));
if (!$voiture) {
return MessageResponse::message('Voiture introuvable', 'danger', 404);
}
$postulant = $em->getRepository('AppBundle:Postulant')->findBy(array('telephone' => $paramFetcher->get('telephone'), 'voiture' => $voiture));
if ($postulant) {
return MessageResponse::message('Ce numero a déjà postulé à cette annonce', 'warning', 200);
}
$postulant = new Postulant();
$postulant->setNomPostulant($paramFetcher->get('nomPostulant'));
$postulant->setTelephone($paramFetcher->get('telephone'));
$postulant->setVoiture($voiture);
$validator = $this->get('validator');
$error = $validator->validate($postulant);
if (count($error) > 0) {
$message = "";
foreach ($error as $er) {
$message = $message . $er->getMessage() . '<br>';
}
return MessageResponse::message($message, 'danger', 400);
}
$em->persist($postulant);
$em->flush();
return MessageResponse::message('Enregistrement effectué avec succes', 'success', 201);
// }catch (BadRequestHttpException $e){
// dump($e);
// return MessageResponse::message($e->getMessage(),'danger',400);
// }
}
示例5: getOffersAction
/**
* Récupère la liste des départements
* GET api/offers
* @Rest\View()
* @Rest\QueryParam(name="sort", requirements="(created|id|name)", default="created", description="search according to date, id or name")
* @Rest\QueryParam(name="dir", requirements="(asc|desc)", default="desc", description="sort search ascending or descending")
*
* @return [type] [description]
*/
public function getOffersAction(ParamFetcher $paramFetcher)
{
$sortBy = $paramFetcher->get('sort');
$sortDir = $paramFetcher->get('dir');
$offers = $this->getDoctrine()->getManager()->getRepository('RscineOfferBundle:Offer')->findBy(array(), array($sortBy => $sortDir));
return $offers;
}
示例6: paginate
/**
* Paginate query results using knp paginator bundle
*
* @param ParamFetcher $paramFetcher
* @param Query $query
* @param string $sortAlias
* @return Hal
*/
protected function paginate(ParamFetcher $paramFetcher, $query, $sortAlias)
{
$request = $this->getRequest();
$params = $paramFetcher->all() + $this->getPagingParams();
//alternative page start index support
if (!empty($params['pageStartIndex'])) {
$page = abs(round($params['pageStartIndex'] / $params['pageSize'])) + 1;
}
$aliasPrefix = $sortAlias . '.';
//paginator
$paginator = $this->get('knp_paginator');
//sort fields resource values to entity fields conversion
if (!empty($params['sortBy']) && substr($params['sortBy'], 0, 2) != $aliasPrefix) {
$_GET['sortBy'] = $aliasPrefix . $params['sortBy'];
//set default sortBy if none is set
} else {
//$_GET['sortBy'] = $aliasPrefix . 'id';
}
if (empty($params['sortOrder'])) {
//$_GET['sortOrder'] = 'asc';
}
$items = $paginator->paginate($query, $params['page'], $params['pageSize']);
$paginationData = $items->getPaginationData();
//root data
$rootArr = array('totalCount' => $paginationData['totalCount'], 'pageCount' => $paginationData['pageCount'], 'pageSize' => $paginationData['numItemsPerPage'], 'currentPage' => intval($paginationData['current']), 'currentPageItemCount' => $paginationData['currentItemCount']);
$entityName = $this->getEntityNameFromResourceObject($items);
$hal = new Hal($request->getUri(), $rootArr, $entityName);
//paging links
$this->addPagingLinks($hal, $paginationData);
//collection output
foreach ($items as $item) {
$hal->addResource($this->getResourceName(), new Hal($this->getResourceUrl($item, $params), $item));
}
return $hal;
}
示例7: getAlbumsAction
/**
* Get albums collection
* Test with GET /api/v1/albums
*
* @ApiDoc()
*
* @QueryParam(name="offset", requirements="\d+", default="0", description="Offset from which to start listing")
* @QueryParam(name="limit", requirements="\d+", default="10")
*
* @param ParamFetcher $paramFetcher
*
* @return array
*/
public function getAlbumsAction(ParamFetcher $paramFetcher)
{
$limit = $paramFetcher->get('limit');
$offset = $paramFetcher->get('offset');
$albums = $this->get('doctrine.orm.entity_manager')->getRepository('MusicAppBundle:Album')->findBy([], null, $limit, $offset);
return ['albums' => $albums];
}
示例8: updateSmoking
/**
* @param Smoking $smoking
* @param ParamFetcher $paramFetcher
* @return Questionnaire
* @throws \Exception
*/
public function updateSmoking(Smoking $smoking, ParamFetcher $paramFetcher)
{
$entityManager = $this->getEntityManager();
$smoking->setDoYouSmoke($paramFetcher->get('do_you_smoke'))->setCompletedDate(new \DateTime());
$entityManager->persist($smoking);
$entityManager->flush();
return $this->getQuestionnaireFromSmoking($smoking);
}
示例9: searchJournalUsersAction
/**
* @Rest\QueryParam(name="q", nullable=false, description="Query text")
* @Rest\QueryParam(name="page_limit", nullable=true, requirements="\d+", description="Query limit", default="10")
*
* @param ParamFetcher $paramFetcher
* @param integer $journalId
* @return Response
*
* @Rest\Get("/search/journal/{journalId}/users")
*
* @ApiDoc(
* resource = true,
* description = "Search Journal's Users",
* output = "Ojs\UserBundle\Entity\User[]",
* statusCodes = {
* "200" = "Users listed successfully",
* "403" = "Access Denied"
* }
* )
*/
public function searchJournalUsersAction(ParamFetcher $paramFetcher, $journalId)
{
$em = $this->getDoctrine()->getManager();
$defaultLimit = 20;
$limit = $paramFetcher->get('page_limit') && $defaultLimit >= $paramFetcher->get('page_limit') ? $paramFetcher->get('page_limit') : $defaultLimit;
$journalUsers = $em->getRepository('OjsUserBundle:User')->searchJournalUser($paramFetcher->get('q'), $journalId, $limit);
return $journalUsers;
}
示例10: getCatalogsAction
/**
* Get Catalogs
*
* @QueryParam(name="page", requirements="\d+", default="0", description="record offset.")
* @QueryParam(name="limit", requirements="\d+", default="100", description="number of records.")
* @QueryParam(name="orderby", requirements="[a-z]+", allowBlank=true, default="name", description="OrderBy field")
* @QueryParam(name="sort", requirements="(asc|desc)+", allowBlank=true, default="asc", description="Sorting order")
*
* @Route("/catalogs")
* @Method("GET")
*/
public function getCatalogsAction(ParamFetcher $paramFetcher)
{
$page = $paramFetcher->get('page');
$limit = $paramFetcher->get('limit');
$orderby = $paramFetcher->get('orderby');
$sort = $paramFetcher->get('sort');
return $this->handleView($this->createView($this->get('catalog_service')->getCatalogs($page, $limit, $orderby, $sort)));
}
示例11: getProductsAction
/**
* Get Products
*
* @QueryParam(name="page", requirements="\d+", default="0", description="record offset.")
* @QueryParam(name="limit", requirements="\d+", default="100", description="number of records.")
* @QueryParam(name="orderby", requirements="[a-z]+", allowBlank=true, default="name", description="OrderBy field")
* @QueryParam(name="sort", requirements="(asc|desc)+", allowBlank=true, default="asc", description="Sorting order")
*
* @Route("/products/{category_id}")
* @Method("GET")
*/
public function getProductsAction($category_id, ParamFetcher $paramFetcher)
{
$page = $paramFetcher->get('page');
$limit = $paramFetcher->get('limit');
$orderby = $paramFetcher->get('orderby');
$sort = $paramFetcher->get('sort');
return $this->handleView($this->createView($this->get('product_service')->getProductsForCategory($category_id, $page, $limit, $orderby, $sort)));
}
示例12: cgetAction
/**
* Retrieve all the project resources.
*
* @ApiDoc(
* resource=true,
* description="List all project resources",
* statusCodes={
* 200="Returned when successful",
* 403="Returned when the user is not authorized",
* 404="Returned when project does not exist"
* },
* requirements={
* { "name"="project", "dataType"="string", "required"=true, "description"="Project's slug" }
* }
* )
* @Rest\QueryParam(name="project", strict=true, nullable=false)
* @Rest\View
*/
public function cgetAction(ParamFetcher $paramFetcher)
{
$project = $this->findProjectOr404($paramFetcher->get('project'));
$resources = $this->get('openl10n.repository.resource')->findByProject($project);
return (new ArrayCollection($resources))->map(function (Resource $resource) {
return new ResourceFacade($resource);
});
}
示例13: normaliseDayDurationsToArray
/**
* @param ParamFetcher $paramFetcher
* @param string $prefix
* @return array
*/
protected function normaliseDayDurationsToArray(ParamFetcher $paramFetcher, $prefix)
{
$durationArray = array();
foreach (DayDuration::$validDays as $day) {
$durationArray[$day] = $paramFetcher->get($prefix . $day);
}
return $durationArray;
}
示例14: getAction
/**
* @FosRest\Get("/{section}")
*
* @ApiDoc(
* description = "Get the guide of a section"
* )
*
* @ParamConverter("section", class="MainBundle:Section")
*
* @FosRest\QueryParam(
* name = "token",
* nullable = false,
* description = "Mobilit token."
* )
* @param Section $section
* @param ParamFetcher $paramFetcher
*
* @return array|GuideModel
*/
public function getAction(Section $section, ParamFetcher $paramFetcher)
{
if ($this->container->getParameter('mobilit_token') != $paramFetcher->get('token')) {
return new Response(json_encode(["message" => $this->get('translator')->trans("errors.api.android.v1.token")]), Response::HTTP_FORBIDDEN);
}
$guide = $this->get('main.guide.fetcher')->getGuide($section);
$guide = $this->get('main.guide.adapter')->getModel($guide, true);
return $guide;
}
示例15: listAction
/**
* @ApiDoc(
* section="Incident",
* resource=true,
* description="Returns a collection of incidents",
* output={
* "class"="array<AppBundle\Entity\Core\Incident>",
* "groups"={"list"}
* },
*
* statusCodes={
* 200="Returned when successful",
* 401="Returned when authentication fails"
* }
* )
* @QueryParam(name="page", requirements="\d+", default="1", description="Page from which to start listing incidents.")
*
* @Route("", methods={"GET"})
* @View(serializerGroups={"Default","list"})
*
* @param Request $request
* @param ParamFetcher $paramFetcher
*
* @return array
*/
public function listAction(Request $request, ParamFetcher $paramFetcher)
{
$em = $this->getDoctrine()->getManager();
$incidentRepository = $em->getRepository('AppBundle:Core\\Incident');
$page = $paramFetcher->get('page');
$paginator = $this->get('knp_paginator');
$pagination = $paginator->paginate($incidentRepository->findAllIncidents(), $page, Incident::MAX_INCIDENT);
return new PagerRepresentation($pagination);
}