本文整理汇总了PHP中Symfony\Component\HttpFoundation\Request::getScheme方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getScheme方法的具体用法?PHP Request::getScheme怎么用?PHP Request::getScheme使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\Request
的用法示例。
在下文中一共展示了Request::getScheme方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: serialize
public function serialize(JsonSerializationVisitor $visitor, OwnerData $owner, array $type)
{
$scheme = $this->request->getScheme() . '://' . $this->request->getHttpHost();
$data = $owner->getData();
if ($owner->getAvatarFileName()) {
$data['avatar_file_path'] = $this->uh->asset($owner, 'avatar');
} else {
$data['avatar_file_path'] = $scheme . $owner->getDefaultAvatar();
}
return $data;
}
示例2: __construct
public function __construct($routes, Request $request, EventDispatcher $dispatcher, ControllerResolver $resolver)
{
$this->deflRes = new NodeResponse();
$this->context = new RequestContext($request->getBaseUrl(), $request->getMethod(), $request->getHost(), $request->getScheme(), $request->getPort(), $request->getPort());
$this->matcher = new UrlMatcher($routes, $this->context);
parent::__construct($dispatcher, $resolver);
}
示例3: handle
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
{
$data = ['request-id' => $request->headers->get('X-Request-Id'), 'datetime' => date('Y-m-d H:i:s'), 'method' => $request->getMethod(), 'scheme' => $request->getScheme(), 'host' => $request->getHttpHost(), 'uri' => $request->getRequestUri(), 'route' => $request->get('_route')];
/*
if (isset($this['current_user'])) {
$data['username'] = $this['current_user']->getName();
}
*/
$data['address'] = $request->getClientIp();
if ($request->getSession()) {
$data['session-id'] = $request->getSession()->getId();
}
if ($request->headers->has('User-Agent')) {
$data['agent'] = $request->headers->get('User-Agent');
}
if ($request->headers->has('referer')) {
$data['referer'] = $request->headers->get('referer');
}
$this->log($data);
$response = $this->app->handle($request, $type, $catch);
/*
// response details
$data['status'] = $response->getStatusCode();
if ($response->headers->has('Content-Type')) {
$data['content-type'] = $response->headers->get('content-type');
}
*/
return $response;
}
示例4: switchAction
/**
* Action for locale switch
*
* @param Request $request
*
* @throws \InvalidArgumentException
* @return RedirectResponse
*/
public function switchAction(Request $request)
{
$_locale = $request->attributes->get('_locale', $request->getLocale());
$statusCode = $request->attributes->get('statusCode', $this->statusCode);
$useReferrer = $request->attributes->get('useReferrer', $this->useReferrer);
$redirectToRoute = $request->attributes->get('route', $this->redirectToRoute);
$metaValidator = $this->metaValidator;
if (!$metaValidator->isAllowed($_locale)) {
throw new \InvalidArgumentException(sprintf('Not allowed to switch to locale %s', $_locale));
}
// Redirect the User
if ($useReferrer && $request->headers->has('referer')) {
$response = new RedirectResponse($request->headers->get('referer'), $statusCode);
} elseif ($this->router && $redirectToRoute) {
$target = $this->router->generate($redirectToRoute, array('_locale' => $_locale));
if ($request->getQueryString()) {
if (!strpos($target, '?')) {
$target .= '?';
}
$target .= $request->getQueryString();
}
$response = new RedirectResponse($target, $statusCode);
} else {
// TODO: this seems broken, as it will not handle if the site runs in a subdir
// TODO: also it doesn't handle the locale at all and can therefore lead to an infinite redirect
$response = new RedirectResponse($request->getScheme() . '://' . $request->getHttpHost() . '/', $statusCode);
}
return $response;
}
示例5: indexAction
public function indexAction(Request $request)
{
$form = $request->request->all();
$no_js = $request->query->get('no-js') || 0;
$script = $no_js == 1 ? 0 : 1;
$db_dir = $this->get('kernel')->getBundle('EUREKAG6KBundle', true)->getPath() . "/Resources/data/databases";
try {
$this->datasources = new \SimpleXMLElement($db_dir . "/DataSources.xml", LIBXML_NOWARNING, true);
$datasourcesCount = $this->datasources->DataSource->count();
} catch (\Exception $e) {
$datasourcesCount = 0;
}
$userManager = $this->get('fos_user.user_manager');
$users = $userManager->findUsers();
$finder = new Finder();
$simu_dir = $this->get('kernel')->getBundle('EUREKAG6KBundle', true)->getPath() . "/Resources/data/simulators";
$finder->depth('== 0')->files()->name('*.xml')->in($simu_dir);
$simulatorsCount = $finder->count();
$finder = new Finder();
$views_dir = $this->get('kernel')->getBundle('EUREKAG6KBundle', true)->getPath() . "/Resources/views";
$finder->depth('== 0')->ignoreVCS(true)->exclude(array('admin', 'base', 'Theme'))->directories()->in($views_dir);
$viewsCount = $finder->count();
$hiddens = array();
$hiddens['script'] = $script;
$silex = new Application();
$silex->register(new MobileDetectServiceProvider());
try {
return $this->render('EUREKAG6KBundle:admin/pages:index.html.twig', array('ua' => $silex["mobile_detect"], 'path' => $request->getScheme() . '://' . $request->getHttpHost(), 'nav' => 'home', 'datasourcesCount' => $datasourcesCount, 'usersCount' => count($users), 'simulatorsCount' => $simulatorsCount, 'viewsCount' => $viewsCount, 'hiddens' => $hiddens));
} catch (\Exception $e) {
echo $e->getMessage();
throw $this->createNotFoundException($this->get('translator')->trans("This template does not exist"));
}
}
示例6: switchAction
/**
* Action for locale switch
*
* @param \Symfony\Component\HttpFoundation\Request $request
* @param $_locale The locale to set
*
* @return \Symfony\Bundle\FrameworkBundle\Controller\RedirectResponse
*
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
*/
public function switchAction(Request $request, $_locale)
{
// Check if the Language is allowed
if (!in_array(\Locale::getPrimaryLanguage($_locale), $this->allowedLanguages)) {
throw new NotFoundHttpException('This language is not available');
}
// tries to detect a Region from the user-provided locales
$providedLanguages = $request->getLanguages();
$locales = array();
foreach ($providedLanguages as $locale) {
if (strpos($locale . '_', $_locale) !== false && strlen($locale) > 2) {
$locales[] = $locale;
}
}
if (count($locales) > 0) {
$this->session->set('localeIdentified', $locales[0]);
} else {
$this->session->set('localeIdentified', $_locale);
}
// Add the listener
$this->session->set('setLocaleCookie', true);
// Redirect the User
if ($request->headers->has('referer') && true === $this->useReferrer) {
return new RedirectResponse($request->headers->get('referer'));
}
if (null !== $this->redirectToRoute) {
return new RedirectResponse($this->router->generate($this->redirectToRoute));
}
return new RedirectResponse($request->getScheme() . '://' . $request->getHttpHost() . $this->redirectToUrl);
}
示例7: lostPasswordAction
/**
* @Route("/lostPassword", name="lost_password_route")
*/
public function lostPasswordAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$reset = false;
if ($request->request->get('reset') == "true") {
$reset = true;
}
if ($reset) {
$user = $em->getRepository('BackendBundle:User')->findOneByEmail($request->request->get('email'));
if (!is_null($user)) {
$rb = uniqid(rand(), true);
$random = md5($user->getEmail() . $rb);
//guardar en la base de datos
$restorer = $em->getRepository('BackendBundle:Restorer')->findOneByUser($user);
if (is_null($restorer)) {
$restorer = new Restorer();
}
$restorer->setUser($user);
$restorer->setTime(new \DateTime());
$restorer->setAuth(md5($random));
$em->persist($restorer);
$em->flush();
$baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath();
$url = $baseurl . '/resetPassword?token=' . $random;
$message = \Swift_Message::newInstance()->setSubject('Recuperación de contraseña')->setFrom('gestionIPre@ing.puc.cl')->setTo(array($user->getEmail()))->setBody('<html>' . ' <head></head>' . ' <body>' . ' Hola, usa este link para recuperar tu contraseña: ' . '<a href="' . $url . '">' . $url . '</a></br>' . ' Si no pediste recuperar contraseña omite este email. (No responda este email)</body>' . '</html>', 'text/html');
$this->get('mailer')->send($message);
}
}
return $this->render('security/lostPassword.html.twig', array('reset' => $reset));
}
示例8: githubAction
public function githubAction(Application $app, Request $request)
{
$clientID = getenv('GITHUB_API_KEY');
$clientSecret = getenv('GITHUB_API_SECRET');
$code = $request->query->get('code');
$redirectUri = $request->getScheme() . '://' . $request->getHost();
if (80 != $request->getPort()) {
$redirectUri .= ':' . $request->getPort();
}
$redirectUri .= '/auth/github';
$provider = new Github(['clientId' => $clientID, 'clientSecret' => $clientSecret, 'redirectUri' => $redirectUri, 'scopes' => ['user:email']]);
if (empty($code)) {
$authUrl = $provider->getAuthorizationUrl();
$app['session']->set('oauth2state', $provider->state);
return $app->redirect($authUrl);
} else {
$token = $provider->getAccessToken('authorization_code', ['code' => $code]);
$userDetails = $provider->getUserDetails($token);
try {
$user = $app['user.manager']->fetchUserByGithubUid($userDetails->uid);
} catch (UserNotFoundException $exception) {
$email = null;
foreach ($provider->getUserEmails($token) as $providerEmail) {
if ($providerEmail->primary) {
$email = $providerEmail->email;
break;
}
}
$user = $app['user.manager']->createUser(['email' => $email, 'roles' => ['ROLE_USER'], 'name' => $userDetails->name, 'githubUid' => $userDetails->uid]);
$app['user.manager']->saveUser($user);
}
$app['session']->set('user', $user);
return $app->redirect($app['url_generator']->generate('account.profile'));
}
}
示例9: clearAction
public function clearAction(Request $request, $env = 'prod')
{
$form = $request->request->all();
$no_js = $request->query->get('no-js') || 0;
$script = $no_js == 1 ? 0 : 1;
if (!$this->get('security.context')->isGranted('ROLE_ADMIN')) {
throw $this->AccessDeniedException($this->get('translator')->trans("Access Denied!"));
}
$cache_dir = dirname($this->get('kernel')->getCacheDir());
$this->log[] = "<b>" . $this->get('translator')->trans("cache directory : %cachedir%", array('%cachedir%' => $cache_dir)) . "</b>";
if (is_dir($cache_dir)) {
if (basename($cache_dir) == "cache") {
$this->log[] = "<br/><br/><b>" . $this->get('translator')->trans("clearing cache") . " :</b>";
$this->cc($cache_dir, $env);
$this->log[] = "<br/><br/><b>" . $this->get('translator')->trans("done !") . "</b>";
} else {
$this->log[] = "<br/> " . $this->get('translator')->trans("Error : %cachedir% is not a named cache", array('%cachedir%' => $cache_dir));
}
} else {
$this->log[] = "<br/> " . $this->get('translator')->trans("Error : %cachedir% is not a directory", array('%cachedir%' => $cache_dir));
}
$hiddens = array();
$hiddens['script'] = $script;
$silex = new Application();
$silex->register(new MobileDetectServiceProvider());
try {
return $this->render('EUREKAG6KBundle:admin/pages:cache-clear.html.twig', array('ua' => $silex["mobile_detect"], 'path' => $request->getScheme() . '://' . $request->getHttpHost(), 'nav' => 'caches', 'log' => $this->log, 'hiddens' => $hiddens));
} catch (\Exception $e) {
throw $this->createNotFoundException($this->get('translator')->trans("This template does not exist"));
}
}
示例10: getScheme
/**
* Get the scheme for a raw URL.
*
* @param bool $secure
* @return string
*/
protected function getScheme($secure)
{
if (is_null($secure)) {
return $this->request->getScheme() . '://';
} else {
return $secure ? 'https://' : 'http://';
}
}
示例11: saveAction
/**
* Save an image and resize it.
*
* @param Request $request
*
* @return Response
*
* @Route("/save", name="prh_image_save")
* @Method("POST")
*/
public function saveAction(Request $request)
{
$imageService = $this->get('prh.blog.service.image');
$path = $this->getParameter('kernel.root_dir') . '/../web/uploads/images';
/** @var \Symfony\Component\HttpFoundation\File\UploadedFile $file */
$file = $request->files->get('file');
$imageService->createResizedImages($path, $file);
return new Response(sprintf('%s://%s/uploads/images/%s', $request->getScheme(), $request->getHttpHost(), $imageService->appendSizeExt($file->getClientOriginalName(), 'b')));
}
示例12: getParameters
/**
* {@inheritdoc}
*/
public function getParameters()
{
$method = null;
$format = null;
$scheme = null;
$ajax = null;
$locale = null;
$route = null;
if (null !== $this->request) {
$method = strtolower($this->request->getMethod());
$format = $this->request->getRequestFormat();
$scheme = $this->request->getScheme();
$ajax = $this->request->isXmlHttpRequest() ? 'ajax' : 'not_ajax';
$locale = $this->request->getLocale();
$route = $this->request->attributes->get('_route');
}
return array('request_method' => $method, 'request_format' => $format, 'request_scheme' => $scheme, 'request_ajax' => $ajax, 'request_locale' => $locale, 'request_route' => $route);
}
示例13: fromRequest
public function fromRequest(Request $request)
{
$this->setBaseUrl($request->getBaseUrl());
$this->setMethod($request->getMethod());
$this->setHost($request->getHost());
$this->setScheme($request->getScheme());
$this->setHttpPort($request->isSecure() ? $this->httpPort : $request->getPort());
$this->setHttpsPort($request->isSecure() ? $request->getPort() : $this->httpsPort);
}
示例14: setRequest
/**
* Sets all needed values from the request.
*
* @param Request $request A request to get values from.
*/
public function setRequest(Request $request)
{
$this->setScheme($request->getScheme());
$this->setHost($request->getHost());
$this->setBasePath($request->getBasePath());
if ($request->isSecure()) {
$this->setHttpsPort($request->getPort());
} else {
$this->setHttpPort($request->getPort());
}
}
示例15: checkDomainsValidity
public function checkDomainsValidity(Request $request)
{
$baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath();
//var_dump($baseurl);
switch (true) {
case $baseurl == 'http://agente3w.com':
return 'core_dashboard';
break;
}
return NULL;
}