本文整理汇总了PHP中FOS\RestBundle\Request\ParamFetcherInterface::all方法的典型用法代码示例。如果您正苦于以下问题:PHP ParamFetcherInterface::all方法的具体用法?PHP ParamFetcherInterface::all怎么用?PHP ParamFetcherInterface::all使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FOS\RestBundle\Request\ParamFetcherInterface
的用法示例。
在下文中一共展示了ParamFetcherInterface::all方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testAction
/**
* @QueryParam(name="foo", default="invalid")
* @RequestParam(name="bar", default="foo")
*/
public function testAction(Request $request, ParamFetcherInterface $fetcher)
{
$paramsBefore = $fetcher->all();
$newRequest = new Request();
$newRequest->query = $request->query;
$newRequest->request = $request->request;
$newRequest->attributes->set('_controller', sprintf('%s::paramsAction', __CLASS__));
$response = $this->container->get('http_kernel')->handle($newRequest, HttpKernelInterface::SUB_REQUEST, false);
$paramsAfter = $fetcher->all(false);
return new JsonResponse(array('before' => $paramsBefore, 'during' => json_decode($response->getContent(), true), 'after' => $paramsAfter));
}
示例2: getMovieCommentsAction
/**
* Returns collection of movie comments
*
* @ApiDoc(
* views={"default", "movie-comment"},
* section="MovieComment API",
* statusCodes={
* 200="Returned when successful",
* 206="Returned when successful",
* 400="Returned when an error has occurred"
* },
* responseMap={
* 200 = {"class": null, "options": {"data_schema": "movie_comment.schema.yml"}}
* }
* )
*
* @Route("movie-comments", name="api_movie_comment_get_movie_comments", requirements={
* "_scope": "[\w,]+",
* "_oprs": "\d+",
* "_sort": "ASC|DESC",
* "_offset": "\d+",
* "_limit": "\d+"
* }, defaults={"_format": "json"}, methods={"GET"})
*
* @RestExtra\Scope(name="list", path="movie_comment/list.yml")
*
* @Rest\QueryParam(name="body", nullable=true, description="Body")
* @Rest\QueryParam(name="publish", nullable=true, description="Publish")
* @Rest\QueryParam(name="createdAt", nullable=true, description="Created at")
*
* @param ParamFetcherInterface $paramFetcher
* @param ScopeFetcherInterface $scopeFetcher
* @param Request $request
* @return MovieComment[]
*/
public function getMovieCommentsAction(ParamFetcherInterface $paramFetcher, ScopeFetcherInterface $scopeFetcher, Request $request)
{
// Define datagrid builder
$datagridBuilder = $this->get('glavweb_datagrid.doctrine_datagrid_builder');
$datagridBuilder->setEntityClassName(MovieComment::class)->setFirstResult($request->get('_offset'))->setMaxResults(min($request->get('_limit', 100), 1000))->setOrderings($request->get('_sort'))->setOperators($request->get('_oprs', []))->setDataSchema('movie_comment.schema.yml', $scopeFetcher->getAvailable($request->get('_scope'), 'movie_comment/list.yml'));
// Define filters
$datagridBuilder->addFilter('body')->addFilter('publish')->addFilter('createdAt');
$datagrid = $datagridBuilder->build($paramFetcher->all());
return $this->createListViewByDatagrid($datagrid);
}
示例3: getObjectsAction
/**
* Récupère les objets
*
* @Annotations\QueryParam(name="offset", requirements="\d+", nullable=true, description="Offset from which to start listing objects.")
* @Annotations\QueryParam(name="limit", requirements="\d+", default="10", description="How many objects to return.")
* @Annotations\QueryParam(name="sort_field", requirements="\w+", description="Field to use for sorting.", nullable=true)
* @Annotations\QueryParam(name="sort_order", requirements="^asc|desc$", description="Order of the sort.", nullable=true)
*
* @param Request $request the request object
* @param ParamFetcherInterface $paramFetcher param fetcher service
*
* @ApiDoc()
*/
protected function getObjectsAction(Request $request, ParamFetcherInterface $paramFetcher, $serialize_groups = array())
{
$params = $paramFetcher->all();
list($limit, $offset, $filters, $sort) = $this->getParamsAndFilters($params);
$count = $this->getServiceHandler()->count($filters);
$result = $this->getServiceHandler()->all($limit, $offset, $filters, $sort);
$view = $this->view(array('count' => $count, 'results' => $result));
$default_serialize_groups = array('Default');
$serialize_groups = array_merge($default_serialize_groups, $serialize_groups);
$view->setSerializationContext(SerializationContext::create()->enableMaxDepthChecks()->setGroups($serialize_groups));
return $this->handleView($view);
}
示例4: validatesParameters
/**
* @param ParamFetcherInterface $paramFetcher
*
* @return array
*/
public function validatesParameters(ParamFetcherInterface $paramFetcher)
{
$params = $paramFetcher->all();
$page = $this->validateParameter($params, 'page');
$limit = $this->validateParameter($params, 'limit');
$itemsPerPage = $this->container->getParameter('api_wtw_repositories_items_per_page');
if ($page > 1) {
$offset = $page * $itemsPerPage;
} else {
$offset = 0;
}
return array_merge($params, array('limit' => $limit, 'offset' => $offset));
}
示例5: getGalleriesAction
/**
* Retrieves the list of galleries (paginated)
*
* @ApiDoc(
* resource=true,
* output={"class"="Sonata\MediaBundle\Model\Gallery", "groups"="sonata_api_read"}
* )
*
* @QueryParam(name="page", requirements="\d+", default="1", description="Page for gallery list pagination")
* @QueryParam(name="count", requirements="\d+", default="10", description="Number of galleries by page")
* @QueryParam(name="enabled", requirements="0|1", nullable=true, strict=true, description="Enabled/Disabled galleries filter")
* @QueryParam(name="orderBy", array=true, requirements="ASC|DESC", nullable=true, strict=true, description="Order by array (key is field, value is direction)")
*
* @View(serializerGroups="sonata_api_read", serializerEnableMaxDepthChecks=true)
*
* @param ParamFetcherInterface $paramFetcher
*
* @return Gallery[]
*/
public function getGalleriesAction(ParamFetcherInterface $paramFetcher)
{
$page = $paramFetcher->get('page');
$count = $paramFetcher->get('count');
$orderBy = $paramFetcher->get('orderBy');
$criteria = $paramFetcher->all();
unset($criteria['page'], $criteria['count'], $criteria['orderBy']);
foreach ($criteria as $key => $crit) {
if (null === $crit) {
unset($criteria[$key]);
}
}
return $this->getGalleryManager()->findBy($criteria, $orderBy, $count, $page);
}
示例6: getEntitiesAction
/**
* Returns collection of entities
*
* @ApiDoc(
* section="Entity API"
* statusCodes={
* 200="Returned when successful",
* 500="Returned when an error has occurred"
* }
* )
*
* @Security("is_granted('ROLE_ENTITY_LIST')")
* @Route("entities.{_format}", name="api_entity_list", methods={"GET"}, defaults={"_format"="json"}, requirements={"_format"="json|xml"})
*
* @Rest\Route(requirements={"_format"="json|xml"})
*
* @Rest\QueryParam(name="name", nullable=true, description="Name of entity")
* @Rest\QueryParam(name="q", nullable=true, description="Query of customer name, customer phone, street")
* @Rest\QueryParam(name="_sort", array=true, requirements="ASC|DESC", nullable=true, description="Sort (key is field, order is direction")
* @Rest\QueryParam(name="_limit", requirements="\d+", nullable=true, strict=true, description="Limit")
* @Rest\QueryParam(name="_offset", requirements="\d+", nullable=true, strict=true, description="Offset")
*
* @Rest\View(serializerEnableMaxDepthChecks=true, serializerGroups={"entity_list"})
*
* @param ParamFetcherInterface $paramFetcher
* @return Entity[]
*/
public function getEntitiesAction(ParamFetcherInterface $paramFetcher)
{
$repository = $this->getRepository('OrderBundle:Order');
$q = $paramFetcher->get('q');
$fields = $paramFetcher->all();
unset($fields['q']);
return $this->matching($repository, $fields, function ($criteria) use($q) {
/** @var Criteria $criteria */
$expr = $criteria->expr();
if ($q) {
$criteria->andWhere($expr->orX($expr->contains('name', $q), $expr->contains('address', $q)));
}
});
}
示例7: getInvoicesAction
/**
* Returns a paginated list of invoices.
*
* @ApiDoc(
* resource=true,
* output={"class"="Sonata\Component\Invoice\InvoiceInterface", "groups"="sonata_api_read"}
* )
*
* @QueryParam(name="page", requirements="\d+", default="1", description="Page for invoices list pagination (1-indexed)")
* @QueryParam(name="count", requirements="\d+", default="10", description="Number of invoices by page")
* @QueryParam(name="orderBy", array=true, requirements="ASC|DESC", nullable=true, strict=true, description="Query invoices invoice by clause (key is field, value is direction")
* @QueryParam(name="status", requirements="\d+", nullable=true, strict=true, description="Filter on invoice statuses")
*
* @View(serializerGroups="sonata_api_read", serializerEnableMaxDepthChecks=true)
*
* @param ParamFetcherInterface $paramFetcher
*
* @return InvoiceInterface[]
*/
public function getInvoicesAction(ParamFetcherInterface $paramFetcher)
{
$supportedFilters = array('status' => "");
$page = $paramFetcher->get('page') - 1;
$count = $paramFetcher->get('count');
$orderBy = $paramFetcher->get('orderBy');
$filters = array_intersect_key($paramFetcher->all(), $supportedFilters);
foreach ($filters as $key => $value) {
if (null === $value) {
unset($filters[$key]);
}
}
return $this->invoiceManager->findBy($filters, $orderBy, $count, $page);
}
示例8: getSitesAction
/**
* Retrieves the list of sites (paginated)
*
* @ApiDoc(
* resource=true,
* output={"class"="Sonata\DatagridBundle\Pager\PagerInterface", "groups"="sonata_api_read"}
* )
*
* @QueryParam(name="page", requirements="\d+", default="1", description="Page for site list pagination")
* @QueryParam(name="count", requirements="\d+", default="10", description="Maximum number of sites per page")
* @QueryParam(name="enabled", requirements="0|1", nullable=true, strict=true, description="Enabled/Disabled sites filter")
* @QueryParam(name="is_default", requirements="0|1", nullable=true, strict=true, description="Default sites filter")
*
* @View(serializerGroups="sonata_api_read", serializerEnableMaxDepthChecks=true)
*
* @param ParamFetcherInterface $paramFetcher
*
* @return PagerInterface
*/
public function getSitesAction(ParamFetcherInterface $paramFetcher)
{
$supportedFilters = array('enabled' => '', 'is_default' => '');
$page = $paramFetcher->get('page');
$count = $paramFetcher->get('count');
$filters = array_intersect_key($paramFetcher->all(), $supportedFilters);
foreach ($filters as $key => $value) {
if (null === $value) {
unset($filters[$key]);
}
}
$pager = $this->siteManager->getPager($filters, $page, $count);
return $pager;
}
示例9: paramFetcherOnKernelController
/**
* Core controller handler.
*
* @param FilterControllerEvent $event
*
* @throws \InvalidArgumentException
*/
public function paramFetcherOnKernelController(FilterControllerEvent $event)
{
$request = $event->getRequest();
if (!$request->attributes->get(FOSRestBundle::ZONE_ATTRIBUTE, true)) {
return;
}
$controller = $event->getController();
if (is_callable($controller) && method_exists($controller, '__invoke')) {
$controller = [$controller, '__invoke'];
}
$this->paramFetcher->setController($controller);
$attributeName = $this->getAttributeName($controller);
$request->attributes->set($attributeName, $this->paramFetcher);
if ($this->setParamsAsAttributes) {
$params = $this->paramFetcher->all();
foreach ($params as $name => $param) {
if ($request->attributes->has($name) && null !== $request->attributes->get($name)) {
$msg = sprintf("ParamFetcher parameter conflicts with a path parameter '{$name}' for route '%s'", $request->attributes->get('_route'));
throw new \InvalidArgumentException($msg);
}
$request->attributes->set($name, $param);
}
}
}
示例10: getBasketsAction
/**
* Returns a paginated list of baskets.
*
* @ApiDoc(
* resource=true,
* output={"class"="Sonata\Component\Basket\BasketInterface", "groups"="sonata_api_read"}
* )
*
* @QueryParam(name="page", requirements="\d+", default="1", description="Page for baskets list pagination (1-indexed)")
* @QueryParam(name="count", requirements="\d+", default="10", description="Number of baskets by page")
* @QueryParam(name="orderBy", array=true, requirements="ASC|DESC", nullable=true, strict=true, description="Query baskets basket by clause (key is field, value is direction")
*
* @View(serializerGroups="sonata_api_read", serializerEnableMaxDepthChecks=true)
*
* @param ParamFetcherInterface $paramFetcher
*
* @return BasketInterface[]
*/
public function getBasketsAction(ParamFetcherInterface $paramFetcher)
{
// No filters implemented as of right now
$supportedFilters = array();
$page = $paramFetcher->get('page') - 1;
$count = $paramFetcher->get('count');
$orderBy = $paramFetcher->get('orderBy');
$filters = array_intersect_key($paramFetcher->all(), $supportedFilters);
foreach ($filters as $key => $value) {
if (null === $value) {
unset($filters[$key]);
}
}
return $this->basketManager->findBy($filters, $orderBy, $count, $page);
}
示例11: getGroupsAction
/**
* Returns a paginated list of groups.
*
* @ApiDoc(
* resource=true,
* output={"class"="Sonata\DatagridBundle\Pager\PagerInterface", "groups"="sonata_api_read"}
* )
*
* @QueryParam(name="page", requirements="\d+", default="1", description="Page for groups list pagination (1-indexed)")
* @QueryParam(name="count", requirements="\d+", default="10", description="Number of groups by page")
* @QueryParam(name="orderBy", array=true, requirements="ASC|DESC", nullable=true, strict=true, description="Query groups order by clause (key is field, value is direction")
* @QueryParam(name="enabled", requirements="0|1", nullable=true, strict=true, description="Enabled/disabled groups only?")
*
* @View(serializerGroups="sonata_api_read", serializerEnableMaxDepthChecks=true)
*
* @param ParamFetcherInterface $paramFetcher
*
* @return PagerInterface
*/
public function getGroupsAction(ParamFetcherInterface $paramFetcher)
{
$supportedFilters = array('enabled' => '');
$page = $paramFetcher->get('page');
$limit = $paramFetcher->get('count');
$sort = $paramFetcher->get('orderBy');
$criteria = array_intersect_key($paramFetcher->all(), $supportedFilters);
foreach ($criteria as $key => $value) {
if (null === $value) {
unset($criteria[$key]);
}
}
if (!$sort) {
$sort = array();
} elseif (!is_array($sort)) {
$sort = array($sort, 'asc');
}
return $this->groupManager->getPager($criteria, $page, $limit, $sort);
}
示例12: getAddressesAction
/**
* Returns a paginated list of addresses.
*
* @ApiDoc(
* resource=true,
* output={"class"="Sonata\DatagridBundle\Pager\PagerInterface", "groups"="sonata_api_read"}
* )
*
* @QueryParam(name="page", requirements="\d+", default="1", description="Page for addresses list pagination (1-indexed)")
* @QueryParam(name="count", requirements="\d+", default="10", description="Number of addresses by page")
* @QueryParam(name="orderBy", array=true, requirements="ASC|DESC", nullable=true, strict=true, description="Query orders addresses by clause (key is field, value is direction")
* @QueryParam(name="customer", requirements="\d+", nullable=true, strict=true, description="Filter on customer id")
*
* @View(serializerGroups="sonata_api_read", serializerEnableMaxDepthChecks=true)
*
* @param ParamFetcherInterface $paramFetcher
*
* @return Sonata\DatagridBundle\Pager\PagerInterface
*/
public function getAddressesAction(ParamFetcherInterface $paramFetcher)
{
$supportedCriteria = array('customer' => "");
$page = $paramFetcher->get('page');
$limit = $paramFetcher->get('count');
$sort = $paramFetcher->get('orderBy');
$criteria = array_intersect_key($paramFetcher->all(), $supportedCriteria);
foreach ($criteria as $key => $value) {
if (null === $value) {
unset($criteria[$key]);
}
}
if (!$sort) {
$sort = array();
} elseif (!is_array($sort)) {
$sort = array($sort => 'asc');
}
return $this->addressManager->getPager($criteria, $page, $limit, $sort);
}
示例13: getSnapshotsAction
/**
* Retrieves the list of snapshots (paginated).
*
* @ApiDoc(
* resource=true,
* output={"class"="Sonata\DatagridBundle\Pager\PagerInterface", "groups"="sonata_api_read"}
* )
*
* @QueryParam(name="page", requirements="\d+", default="1", description="Page for snapshots list pagination")
* @QueryParam(name="count", requirements="\d+", default="10", description="Maximum number of snapshots per page")
* @QueryParam(name="site", requirements="\d+", nullable=true, strict=true, description="Filter snapshots for a specific site's id")
* @QueryParam(name="page_id", requirements="\d+", nullable=true, strict=true, description="Filter snapshots for a specific page's id")
* @QueryParam(name="root", requirements="0|1", nullable=true, strict=true, description="Filter snapshots having no parent id")
* @QueryParam(name="parent", requirements="\d+", nullable=true, strict=true, description="Get snapshots being child of given snapshots id")
* @QueryParam(name="enabled", requirements="0|1", nullable=true, strict=true, description="Enabled/Disabled snapshots filter")
* @QueryParam(name="orderBy", requirements="ASC|DESC", array=true, nullable=true, strict=true, description="Order by array (key is field, value is direction)")
*
* @View(serializerGroups="sonata_api_read", serializerEnableMaxDepthChecks=true)
*
* @param ParamFetcherInterface $paramFetcher
*
* @return PagerInterface
*/
public function getSnapshotsAction(ParamFetcherInterface $paramFetcher)
{
$supportedCriteria = array('enabled' => '', 'site' => '', 'page_id' => '', 'root' => '', 'parent' => '');
$page = $paramFetcher->get('page');
$limit = $paramFetcher->get('count');
$sort = $paramFetcher->get('orderBy');
$criteria = array_intersect_key($paramFetcher->all(), $supportedCriteria);
foreach ($criteria as $key => $value) {
if (null === $value) {
unset($criteria[$key]);
}
}
if (!$sort) {
$sort = array();
} elseif (!is_array($sort)) {
$sort = array($sort => 'asc');
}
$pager = $this->snapshotManager->getPager($criteria, $page, $limit, $sort);
return $pager;
}
示例14: getBasketsAction
/**
* Returns a paginated list of baskets.
*
* @ApiDoc(
* resource=true,
* output={"class"="Sonata\DatagridBundle\Pager\PagerInterface", "groups"="sonata_api_read"}
* )
*
* @QueryParam(name="page", requirements="\d+", default="1", description="Page for baskets list pagination (1-indexed)")
* @QueryParam(name="count", requirements="\d+", default="10", description="Number of baskets by page")
* @QueryParam(name="orderBy", array=true, requirements="ASC|DESC", nullable=true, strict=true, description="Query baskets basket by clause (key is field, value is direction")
*
* @View(serializerGroups="sonata_api_read", serializerEnableMaxDepthChecks=true)
*
* @param ParamFetcherInterface $paramFetcher
*
* @return Sonata\DatagridBundle\Pager\PagerInterface[]
*/
public function getBasketsAction(ParamFetcherInterface $paramFetcher)
{
// No filters implemented as of right now
$supportedCriteria = array();
$page = $paramFetcher->get('page');
$limit = $paramFetcher->get('count');
$sort = $paramFetcher->get('orderBy');
$criteria = array_intersect_key($paramFetcher->all(), $supportedCriteria);
foreach ($criteria as $key => $value) {
if (null === $value) {
unset($criteria[$key]);
}
}
if (!$sort) {
$sort = array();
} elseif (!is_array($sort)) {
$sort = array($sort => 'asc');
}
return $this->basketManager->getPager($criteria, $page, $limit, $sort);
}
示例15: filterCriteria
/**
* Filters criteria from $paramFetcher to be compatible with the Pager criteria.
*
* @param ParamFetcherInterface $paramFetcher
*
* @return array The filtered criteria
*/
protected function filterCriteria(ParamFetcherInterface $paramFetcher)
{
$criteria = $paramFetcher->all();
unset($criteria['page'], $criteria['count']);
foreach ($criteria as $key => $value) {
if (null === $value) {
unset($criteria[$key]);
}
}
return $criteria;
}