本文整理汇总了PHP中Symfony\Component\HttpFoundation\Request::getUriForPath方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getUriForPath方法的具体用法?PHP Request::getUriForPath怎么用?PHP Request::getUriForPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\Request
的用法示例。
在下文中一共展示了Request::getUriForPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: uploadFilesAction
/**
* @Route("uploadFile", name="pic.upload.file")
* @param Request $request
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
public function uploadFilesAction(Request $request)
{
$this->get("logger")->debug("Entramos al subidor de imágenes");
$em = $this->getDoctrine()->getManager();
$files = $request->files;
$this->get("logger")->debug("Despues de sacar las imagenes del request");
$this->get("logger")->debug(sprintf("Conteo de los archivos a subir: %s", count($files)));
$data = array();
if (count($files) > 0) {
foreach ($files as $file) {
$md5 = md5_file($file);
$result = $em->createQuery("select p from PicboardBundle:ThePicture p where p.md5 = :md5 " . " and p.deletedAt = null")->setParameter("md5", $md5)->getOneOrNullResult();
if (is_null($result)) {
$ext = strtolower($file->getClientOriginalExtension());
$fileName = $md5 . "." . $ext;
$file->move('pictures/', $fileName);
$this->get("logger")->debug(sprintf("El nombre del archivo es: %s", $fileName));
$picture = new ThePicture();
$picture->setMd5($md5);
$picture->setPath($fileName);
$em->persist($picture);
$em->flush();
$url = $request->getUriForPath("/pictures/" . $picture->getPath());
$content = array('url' => $url);
array_push($data, $content);
} else {
$url = $request->getUriForPath("/pictures/" . $result->getPath());
$content = array('url' => $url);
array_push($data, $content);
}
}
return new JsonResponse($data);
}
throw new InvalidArgumentException("No se pueden subir imagenes si no existen");
}
示例2: start
/**
* {@inheritdoc}
*/
public function start(EventInterface $event, Request $request, AuthenticationException $authException = null)
{
if ($this->useForward) {
return $event->getSubject()->handle(Request::create($this->loginPath), HttpKernelInterface::SUB_REQUEST);
}
return new RedirectResponse(0 !== strpos($this->loginPath, 'http') ? $request->getUriForPath($this->loginPath) : $this->loginPath, 302);
}
示例3: showFormAction
/**
* Builds a page with login form.
*
* @param Request $request Incoming request.
* @return string Rendered page content.
*/
public function showFormAction(Request $request)
{
// Check if the operator already logged in
if ($this->getOperator()) {
// Redirect the operator to home page.
// TODO: Use a route for URI generation.
return $this->redirect($request->getUriForPath('/operator'));
}
$page = array('formisRemember' => true, 'version' => MIBEW_VERSION, 'errors' => $request->attributes->get('errors', array()));
// Try to get login from the request.
if ($request->request->has('login')) {
$page['formlogin'] = $request->request->get('login');
} elseif ($request->query->has('login')) {
$login = $request->query->get('login');
if (preg_match("/^(\\w{1,15})\$/", $login)) {
$page['formlogin'] = $login;
}
}
$page['localeLinks'] = get_locale_links();
$page['title'] = getlocal('Login');
$page['headertitle'] = getlocal('Mibew Messenger');
$page['show_small_login'] = false;
$page['fixedwrap'] = true;
return $this->render('login', $page);
}
示例4: sliderCreateAction
/**
* @Route("/slider/create", name="picture_slider_create")
* @param Request $request
* @return JsonResponse
*/
public function sliderCreateAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$postId = $request->get("postId");
$files = $request->files;
$picture = new Picture();
$result = array();
$post = $em->createQuery("select p from IndexBundle:Post p where p.id=:id")->setParameter("id", $postId)->getOneOrNullResult();
if (is_null($post)) {
throw new InvalidArgumentException("No existe publicacion asociada a id");
}
foreach ($files as $file) {
$uid = uniqid();
$md5 = md5($uid);
$ext = strtolower($file->getClientOriginalExtension());
$fileName = $md5 . "." . $ext;
$file->move(__DIR__ . "/../../../web/pictures/", $fileName);
$picture->setMd5($md5);
$picture->setPath($fileName);
$picture->setSection("slider");
$em->persist($picture);
$em->flush();
$this->persistAndFlushSlider($picture, $post);
$url = $request->getUriForPath("/pictures/" . $fileName);
$data = array('url' => $url);
array_push($result, $data);
}
return new JsonResponse($result);
}
示例5: getBySeedAction
/**
* @Route("/{_locale}/get/seed/{seed}", name="get_by_seed_locale")
* @Route("/get/seed/{seed}", name="get_by_seed")
*/
public function getBySeedAction(Request $request, $seed)
{
$return = array('status' => 1, 'message' => '', 'data' => null);
// retorno padrão
$router = $this->container->get('router');
$translator = $this->get('translator');
// da uma limpada
$seed = md5($seed . $this->container->getParameter('secret'));
// extrai um numero de 0~9
$seed = substr(base_convert(md5($seed), 16, 10), -1);
srand($seed);
// usa pro rand
// image path
$image_path = $request->getUriForPath('/image/cenouro.png');
$message = '';
// são tão poucas opções que nem vale a pena criar DB
// balanceia as chances um pouco
switch (rand(1, 4)) {
case 1:
$message = 'Yes!';
break;
case 2:
$message = 'No!';
break;
default:
switch (rand(1, 6)) {
case 1:
$message = 'Maybe.';
break;
case 2:
$message = 'Sure!';
break;
case 3:
$message = "I really don't care.";
break;
case 4:
$message = "Of course not.";
break;
case 5:
$message = "Ask again.";
break;
case 6:
$message = "Screw you!";
break;
}
break;
}
// traduz, se precisar
$message = $translator->trans($message);
// responde
$data = array('message' => $message, 'image' => $image_path);
$return['data'] = $data;
$response = new JsonResponse($return);
// cache
$response->setPublic();
$response->setSharedMaxAge(600000);
$response->headers->addCacheControlDirective('must-revalidate', true);
return $response;
}
示例6: absoluteUrl
/**
* Convert the given URL to an absolute URL, using base URL from the given Request if the URL is not already \
* absolute (including network URLs).
*
* @param string $url A URL, either absolute or relative.
* @param Request $request An absolute URL, the site base URL.
*
* @return string Absolute URL.
*/
public static function absoluteUrl($url, Request $request)
{
// Check for an absolute URL or a network URL, these get returned directly.
if (preg_match('/^https?:/i', $url) || substr($url, 0, 2) === '//') {
return $url;
}
return $request->getUriForPath('/' . ltrim($url, '/'));
}
示例7: attemptAuthentication
protected function attemptAuthentication(Request $request)
{
$manager = $this->factory->getManager($this->options['manager'], $request->getUriForPath($this->options['check_path']));
if (!$manager->getProtocol()->isValidationRequest($request)) {
return null;
}
return $this->authenticationManager->authenticate($manager->createToken($request));
}
示例8: create
/**
* {@inheritdoc}
*/
public function create()
{
if (null === $this->request) {
return null;
}
$http = new Http($this->request->getUriForPath($this->request->getPathInfo()), $this->request->getMethod());
$queryString = $this->request->getQueryString();
if (strlen($queryString) > 0) {
$http->setQueryString($queryString);
}
$http->setData($this->request->request->all());
$http->setCookies($this->request->cookies->all());
$http->setHeaders(array_map(function (array $values) {
return count($values) === 1 ? reset($values) : $values;
}, $this->request->headers->all()));
$http->setEnv($this->request->server->all());
return $http;
}
示例9: start
/**
* @param Request $request
* @param null|AuthenticationException $authException
* @return Response
*/
public function start(Request $request, AuthenticationException $authException = null)
{
$action = $this->config['login_action'];
$manager = $this->factory->getManager($this->config['manager'], $request->getUriForPath($this->config['check_path']));
if ($action) {
return $this->httpKernel->forward($action, array('manager' => $manager, 'request' => $request, 'exception' => $authException));
}
return new RedirectResponse($manager->getServer()->getLoginUrl());
}
示例10: onLogoutSuccess
/**
* @param Request $request
* @param null|AuthenticationException $authException
*
* @return Response
*/
public function onLogoutSuccess(Request $request)
{
$action = $this->config['logout_action'];
$manager = $this->factory->getManager($this->config['manager'], $request->getUriForPath($this->config['check_path']));
if ($action) {
return $this->httpKernel->forward($action, array('manager' => $manager, 'request' => $request));
}
return new RedirectResponse($manager->getServer()->getLogoutUrl());
}
示例11: generateProxyUri
/**
* Generates a proxy URI for a given controller.
*
* @param ControllerReference $reference A ControllerReference instance
* @param Request $request A Request instance
*
* @return string A proxy URI
*/
protected function generateProxyUri(ControllerReference $reference, Request $request)
{
if (!isset($reference->attributes['_format'])) {
$reference->attributes['_format'] = $request->getRequestFormat();
}
$reference->attributes['_controller'] = $reference->controller;
$reference->query['_path'] = http_build_query($reference->attributes, '', '&');
return $request->getUriForPath($this->proxyPath . '?' . http_build_query($reference->query, '', '&'));
}
示例12: createRedirectResponse
/**
* Creates a redirect Response.
*
* @param Request $request A Request instance
* @param string $path A path (an absolute path (/foo), an absolute URL (http://...), or a route name (foo))
* @param integer $status The status code
*
* @return Response A RedirectResponse instance
*/
public function createRedirectResponse(Request $request, $path, $status = 302)
{
if (0 === strpos($path, '/')) {
$path = $request->getUriForPath($path);
} elseif (0 !== strpos($path, 'http')) {
$path = $this->generateUrl($path, true);
}
return new RedirectResponse($path, 302);
}
示例13: getVCard
/**
* Returns a vcard for a profile
* @param $profile
* @param $includePhoto
* @return VCard
*/
public function getVCard($profile, $includePhoto)
{
$vcard = new VCard();
$vcard->addName($profile['lastName'], $profile['firstName'])->addCompany($profile['company'])->addAddress('', '', $profile['address']['street'], $profile['address']['city'], $profile['address']['region'], $profile['address']['zip'], $profile['address']['country'])->addEmail($profile['email'])->addURL($profile['url'])->addPhoneNumber($profile['phone']['work'], 'WORK')->addPhoneNumber($profile['phone']['mobile'], 'CELL')->addJobtitle($profile['jobTitle']);
// Add photo
if ($profile['photo'] != null) {
$photoUri = null;
if ($includePhoto) {
// Generate filesystem URI
$webDir = $this->kernelRootDir . '/../web/';
$photoUri = $webDir . $profile['photo'];
} else {
// Generate absolute public URI
$photoUri = $this->request->getUriForPath('/' . $profile['photo']);
}
$vcard->addPhoto($photoUri, $includePhoto);
}
return $vcard;
}
示例14: open
public function open($args = false, $hidden = [])
{
if ($args === false) {
$args = ['action' => $this->request->getUri()];
} else {
if (is_string($args)) {
$args = '/' . ltrim($args, '/');
$args = ['action' => $this->request->getUriForPath($args)];
}
}
if (!isset($args['method'])) {
$args['method'] = 'POST';
}
$s = '<form' . $this->expandArgs($args) . '>';
foreach ($hidden as $name => $value) {
$s .= '<input type="hidden" name="' . htmlentities($name) . '" value="' . htmlentities($value) . '">';
}
return $s;
}
示例15: start
/**
* @param Request $request
* @param null|AuthenticationException $authException
* @return Response
*/
public function start(Request $request, AuthenticationException $authException = null)
{
$action = $this->config['login_action'];
$manager = $this->factory->getManager($this->config['manager'], $request->getUriForPath($this->config['check_path']));
if ($action) {
$subRequest = $request->duplicate(null, null, array('_controller' => $action, 'manager' => $manager, 'request' => $request, 'exception' => $authException));
return $this->httpKernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
}
return new RedirectResponse($manager->getServer()->getLoginUrl());
}