本文整理汇总了PHP中FOS\RestBundle\View\View类的典型用法代码示例。如果您正苦于以下问题:PHP View类的具体用法?PHP View怎么用?PHP View使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了View类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createResponse
/**
* Handles response for csv-request.
*
* @param ViewHandler $handler
* @param View $view
* @param Request $request
* @param string $format
*
* @return Response
*
* @throws ObjectNotSupportedException
*/
public function createResponse(ViewHandler $handler, View $view, Request $request, $format)
{
if (!$view->getData() instanceof ListRepresentation) {
throw new ObjectNotSupportedException($view);
}
$viewData = $view->getData();
$data = new CallbackCollection($viewData->getData(), [$this, 'prepareData']);
$fileName = sprintf('%s.csv', $viewData->getRel());
$config = new ExporterConfig();
$exporter = new Exporter($config);
$data->rewind();
if ($row = $data->current()) {
$config->setColumnHeaders(array_keys($row));
}
$config->setDelimiter($this->convertValue($request->get('delimiter', ';'), self::$delimiterMap));
$config->setNewline($this->convertValue($request->get('newLine', '\\n'), self::$newLineMap));
$config->setEnclosure($request->get('enclosure', '"'));
$config->setEscape($request->get('escape', '\\'));
$response = new StreamedResponse();
$disposition = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $fileName, $fileName);
$response->headers->set('Content-Type', 'text/csv');
$response->headers->set('Content-Disposition', $disposition);
$response->setCallback(function () use($data, $exporter) {
$exporter->export('php://output', $data);
});
$response->send();
return $response;
}
示例2: showAction
public function showAction(Request $request, $exception, DebugLoggerInterface $logger = null)
{
$view = new View();
$view->setData(json_decode($exception->getMessage(), true));
$view->setFormat('json');
return $this->container->get('fos_rest.view_handler')->handle($view);
}
示例3: getStatusCode
/**
* FOSRest's ViewHandler has a private getStatusCode method. Because we cannot use it, we added
* this lightweight method (without forms support) for Hal custom handler.
*
* @param View $view view instance
*
* @return int HTTP status code
*/
private function getStatusCode(View $view)
{
if (null !== ($code = $view->getStatusCode())) {
return $code;
}
return Codes::HTTP_OK;
}
示例4: includeJSFilesAction
/**
* Render js inclusion for create.js and dependencies and bootstrap code.
*
* THe hallo editor is bundled with create.js and available automatically.
* To use aloha, you need to download the zip, as explained in step 8 of
* the README.
*
* @param string $editor the name of the editor to load, currently hallo and aloha are supported
*/
public function includeJSFilesAction($editor = 'hallo')
{
if ($this->securityContext && false === $this->securityContext->isGranted($this->requiredRole)) {
return new Response('');
}
// We could inject a list of names to template mapping for this
// to allow adding other editors without changing this bundle
$view = new View();
switch ($editor) {
case 'hallo':
if ($this->coffee) {
$view->setTemplate('SymfonyCmfCreateBundle::includecoffeefiles-hallo.html.twig');
} else {
$view->setTemplate('SymfonyCmfCreateBundle::includejsfiles-hallo.html.twig');
}
break;
case 'aloha':
$view->setTemplate('SymfonyCmfCreateBundle::includejsfiles-aloha.html.twig');
break;
default:
throw new \InvalidArgumentException("Unknown editor '{$editor}' requested");
}
$view->setData(array('cmfCreateStanbolUrl' => $this->stanbolUrl, 'cmfCreateImageUploadEnabled' => (bool) $this->imageClass));
return $this->viewHandler->handle($view);
}
示例5: createFeed
/**
* @param $data array
* @param format string, either rss or atom
*/
protected function createFeed(View $view, Request $request)
{
$feed = new Feed();
$data = $view->getData();
$item = current($data);
$annotationData = $this->reader->read($item);
if ($item && ($feedData = $annotationData->getFeed())) {
$class = get_class($item);
$feed->setTitle($feedData->getName());
$feed->setDescription($feedData->getDescription());
$feed->setLink($this->urlGen->generateCollectionUrl($class));
$feed->setFeedLink($this->urlGen->generateCollectionUrl($class, $request->getRequestFormat()), $request->getRequestFormat());
} else {
$feed->setTitle('Camdram feed');
$feed->setDescription('Camdram feed');
}
$lastModified = null;
$accessor = PropertyAccess::createPropertyAccessor();
// Add one or more entries. Note that entries must be manually added once created.
foreach ($data as $document) {
$entry = $feed->createEntry();
$entry->setTitle($accessor->getValue($document, $feedData->getTitleField()));
$entry->setLink($this->urlGen->generateUrl($document));
$entry->setDescription($this->twig->render($feedData->getTemplate(), array('entity' => $document)));
if ($accessor->isReadable($document, $feedData->getUpdatedAtField())) {
$entry->setDateModified($accessor->getValue($document, $feedData->getUpdatedAtField()));
}
$feed->addEntry($entry);
if (!$lastModified || $entry->getDateModified() > $lastModified) {
$lastModified = $entry->getDateModified();
}
}
$feed->setDateModified($lastModified);
return $feed->export($request->getRequestFormat());
}
示例6: handleExtension
/**
* @param ViewHandler $viewHandler
* @param View $view
* @param Request $request
* @param string $format
*
* @return Response
*/
public function handleExtension(ViewHandler $handler, View $view, Request $request, $format)
{
if (in_array("application/vnd.bpi.api+xml", $request->getAcceptableContentTypes())) {
$view->setHeader("Content-Type", "application/vnd.bpi.api+xml");
}
return $handler->createResponse($view, $request, "xml");
}
示例7: postAction
public function postAction()
{
$todos = $this->getDoctrine()->getRepository('AppBundle:Todo')->findAll();
$view = new View();
$view->setData($todos);
return $this->handleView($view);
}
示例8: indexAction
/**
* @Route("/")
*/
public function indexAction()
{
$view = new View();
$view->setFormat('html');
$view->setTemplate('TastdCoreBundle:Default:index.html.twig');
return $view;
}
示例9: postUserSignInAction
/**
* Sign in users by pair username:password.
*
* @ApiDoc(
* views={"default", "user"},
* section="Security API",
* resource=true,
* resourceDescription="Sign in users by pair username:password.",
* statusCodes={
* 200="Returned when successful",
* 400="Returned when an error has occurred",
* }
* )
*
* @Rest\Route("/sign-in", requirements={
* "_format": "json|xml"
* })
*
* @Rest\RequestParam(name="username", requirements="[\w\-]+", nullable=false, description="Username")
* @Rest\RequestParam(name="password", nullable=false, description="Password")
*
* @param ParamFetcherInterface $paramFetcher
* @return View
*/
public function postUserSignInAction(ParamFetcherInterface $paramFetcher)
{
$username = $paramFetcher->get('username');
$password = $paramFetcher->get('password');
/** @var EntityRepository $repository */
$repository = $this->getDoctrine()->getManager()->getRepository('UserBundle:User');
/** @var User $user */
$user = $repository->findOneBy(['username' => $username]);
if (!$user || !$this->validatePassword($user, $password)) {
return new View(array('message' => 'User not found.'), 400);
}
if (!$user->isEnabled()) {
return new View(array('message' => 'Account is disabled.'), 400);
}
if (!$user->isAccountNonLocked()) {
return new View(array('message' => 'Account is locked.'), 400);
}
if (!$user->isAccountNonExpired()) {
return new View(array('message' => 'Account is expired.'), 400);
}
if (!$user->isCredentialsNonExpired()) {
return new View(array('message' => 'Credentials is expired.'), 400);
}
$this->generateToken($user);
$this->getDoctrine()->getManager()->flush();
$headers = array('Token' => $user->getApiToken(), 'ExpireAt' => $user->getApiTokenExpireAt()->format('c'), 'Username' => $user->getUsername());
$view = new View(array_merge(array('user' => $user->getId()), $headers), 200, $headers);
$this->setAuthInfoInCookie($headers, $view->getResponse(), $user->getApiTokenExpireAt());
return $view;
}
示例10: handle
public function handle(RequestConfiguration $requestConfiguration, View $view)
{
if ($view->getResponse()->getContent()) {
return $view->getResponse();
}
return parent::handle($requestConfiguration, $view);
}
示例11: newUserAction
/**
* @ApiDoc(
* section="Admin/Users",
* description="Display the creation form of the user",
* input="AppBundle\Controller\Admin\Form\UserFormType",
* output="AppBundle\Controller\Admin\AdminUserController",
* )
*/
public function newUserAction()
{
$user = new User();
$form = $this->getUserForm($user, 'post_user', 'POST');
$view = new View($form);
$view->setTemplate('AppBundle:User:add.html.twig');
return $this->handleView($view);
}
示例12: createView
protected function createView($returnData)
{
$view = new View();
$view->setData($returnData);
$view->setStatusCode($returnData['status']);
$view->setFormat('json');
return $view;
}
示例13: createResponse
/**
* Converts the viewdata to a RSS feed. Modify to suit your datastructure.
*
* @return Response
*/
public function createResponse(ViewHandler $handler, View $view, Request $request)
{
if ($view->getData() instanceof Diary) {
return new Response($this->createFeed($view->getData()), Response::HTTP_OK, $view->getHeaders());
} else {
return new Response('Unsupported entity type', Response::HTTP_BAD_REQUEST);
}
}
示例14: getView
public function getView($msg, $code)
{
$data1 = new Response($msg, $code);
$view = new View($data1);
$view->setTemplate('AppBundle:message.html.twig');
$view->setTemplateVar('data');
return $view;
}
示例15: getCountryAction
/**
* Информация о стране по id
*
* @param Country $country
*
* @Rest\Get("countries/{id}", requirements={"id"="\d+"})
* @ParamConverter("country", class="VifeedGeoBundle:Country")
* @ApiDoc(
* section="Campaign API",
* requirements={
* {"name"="id", "dataType"="integer", "requirement"="\d+", "description"="id страны"}
* },
* output={
* "class"="Vifeed\GeoBundle\Entity\Country",
* "groups"={"default"}
* },
* statusCodes={
* 200="Returned when successful",
* 403="Returned when the user is not authorized to use this method",
* 404="Returned when campaign not found"
* }
* )
*
* @return Response
*/
public function getCountryAction(Country $country)
{
$context = new SerializationContext();
$context->setGroups(['default']);
$view = new View($country);
$view->setSerializationContext($context);
return $this->handleView($view);
}