本文整理汇总了PHP中Symfony\Component\HttpFoundation\Request::getSchemeAndHttpHost方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getSchemeAndHttpHost方法的具体用法?PHP Request::getSchemeAndHttpHost怎么用?PHP Request::getSchemeAndHttpHost使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\Request
的用法示例。
在下文中一共展示了Request::getSchemeAndHttpHost方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildSitemapLinks
/**
* @param Domain $domain
* @param Request $request
*
* @return array
*/
protected function buildSitemapLinks(Domain $domain, Request $request)
{
$links = [];
if (!$domain->hasYearSpecificDomain()) {
$links[$request->getSchemeAndHttpHost()] = $request->getSchemeAndHttpHost();
}
if ($domain->hasYearSpecificDomain()) {
foreach ($this->months as $key => $value) {
$links["{$request->getSchemeAndHttpHost()}/{$key}"] = "{$request->getSchemeAndHttpHost()}/{$key}";
}
}
return $links;
}
示例2: getRefererPath
public function getRefererPath(Request $request = null)
{
$referer = $request->headers->get('referer');
$baseUrl = $request->getSchemeAndHttpHost();
$lastPath = substr($referer, strpos($referer, $baseUrl) + strlen($baseUrl));
return $lastPath;
}
示例3: createAction
/**
* @param Request $request
*
* @return JsonResponse
*/
public function createAction($content, Request $request)
{
$rawPayment = ArrayObject::ensureArrayObject($content);
$form = $this->formFactory->create('create_payment');
$form->submit((array) $rawPayment);
if (false == $form->isValid()) {
return new JsonResponse($this->formToJsonConverter->convertInvalid($form), 400);
}
/** @var Payment $payment */
$payment = $form->getData();
$payment->setAfterUrl($payment->getAfterUrl() ?: $request->getSchemeAndHttpHost());
$payment->setNumber($payment->getNumber() ?: date('Ymd-' . mt_rand(10000, 99999)));
$payment->setDetails([]);
$storage = $this->registry->getStorage($payment);
$storage->update($payment);
$token = $this->tokenFactory->createToken($payment->getGatewayName(), $payment, 'payment_get');
$payment->setPublicId($token->getHash());
$payment->addLink('self', $token->getTargetUrl());
$payment->addLink('update', $token->getTargetUrl());
$payment->addLink('delete', $token->getTargetUrl());
$token = $this->tokenFactory->createAuthorizeToken($payment->getGatewayName(), $payment, $payment->getAfterUrl(), ['payum_token' => null]);
$payment->addLink('authorize', $token->getTargetUrl());
$token = $this->tokenFactory->createCaptureToken($payment->getGatewayName(), $payment, $payment->getAfterUrl(), ['payum_token' => null]);
$payment->addLink('capture', $token->getTargetUrl());
$token = $this->tokenFactory->createNotifyToken($payment->getGatewayName(), $payment);
$payment->addLink('notify', $token->getTargetUrl());
$storage->update($payment);
return new JsonResponse(array('payment' => $this->paymentToJsonConverter->convert($payment)), 201, array('Location' => $payment->getLink('self')));
}
示例4: buildForm
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$currencies = Intl::getCurrencyBundle()->getCurrencyNames();
if (extension_loaded('intl')) {
$builder->add('locale', 'select2', array('choices' => Intl::getLocaleBundle()->getLocaleNames(), 'constraints' => new Constraints\NotBlank(array('message' => 'Please select a locale')), 'placeholder' => '', 'choices_as_values' => false));
} else {
$builder->add('locale', null, array('data' => 'en', 'read_only' => true, 'help' => 'The only currently supported locale is "en". To choose a different locale, please install the \'intl\' extension'));
}
$builder->add('currency', 'select2', array('choices' => $currencies, 'constraints' => new Constraints\NotBlank(array('message' => 'Please select a currency')), 'placeholder' => '', 'choices_as_values' => false));
$builder->add('base_url', null, array('constraints' => new Constraints\NotBlank(array('message' => 'Please set the application base url')), 'data' => $this->request->getSchemeAndHttpHost() . $this->request->getBaseUrl()));
if (0 === $this->userCount) {
$builder->add('username', null, array('constraints' => new Constraints\NotBlank(array('message' => 'Please enter a username'))));
$builder->add('email_address', 'email', array('constraints' => array(new Constraints\NotBlank(array('message' => 'Please enter a email')), new Constraints\Email())));
$builder->add('password', 'repeated', array('type' => 'password', 'invalid_message' => 'The password fields must match.', 'options' => array('attr' => array('class' => 'password-field')), 'required' => true, 'first_options' => array('label' => 'Password'), 'second_options' => array('label' => 'Repeat Password'), 'constraints' => array(new Constraints\NotBlank(array('message' => 'You must enter a secure password')), new Constraints\Length(array('min' => 6)))));
}
}
示例5: firstRunAction
/**
* @Route("/first-run" ,name="self-advert-first-run")
*/
public function firstRunAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$url = "http://freegeoip.net/json/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
$data = json_decode($result, true);
$selfAdvert = new SelfAdvert();
if (!empty($data) || !$data) {
$selfAdvert->setIp($data["ip"]);
$selfAdvert->setLocation($data["city"]);
$selfAdvert->setZipCode($data["zip_code"]);
$ret = true;
} else {
$selfAdvert->setIp($_SERVER['REMOTE_ADDR']);
$ret = false;
}
$selfAdvert->setHost($request->getSchemeAndHttpHost());
$selfAdvert->setCreated(new \DateTime());
$em->persist($selfAdvert);
$em->flush();
return $this->redirect('/');
}
示例6: switchLocaleAction
public function switchLocaleAction(Request $request)
{
$this->guard->userIsLoggedIn();
$this->logger->notice('User requested to switch locale');
$returnUrl = $request->query->get('return-url');
// Return URLs generated by us always include a path (ie. at least a forward slash)
// @see https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/Request.php#L878
$domain = $request->getSchemeAndHttpHost() . '/';
if (strpos($returnUrl, $domain) !== 0) {
$this->logger->error(sprintf('Illegal return-url ("%s") for redirection after changing locale, aborting request', $returnUrl));
throw new BadRequestHttpException('Invalid return-url given');
}
$command = new ChangeLocaleCommand();
$form = $this->formFactory->create('profile_switch_locale', $command, [])->handleRequest($request);
$this->logger->notice(sprintf('Switching locale from "%s" to "%s"', $request->getLocale(), $command->newLocale));
if ($form->isValid()) {
$this->userService->changeLocale($command);
$this->flashBag->add('success', 'profile.locale.locale_change_success');
$this->logger->notice(sprintf('Successfully switched locale from "%s" to "%s"', $request->getLocale(), $command->newLocale));
} else {
$this->flashBag->add('error', 'profile.locale.locale_change_fail');
$this->logger->error('Locale not switched: the switch locale form contained invalid data');
}
return new RedirectResponse($returnUrl);
}
示例7: switchLocaleAction
public function switchLocaleAction(Request $request)
{
$returnUrl = $request->query->get('return-url');
$domain = $request->getSchemeAndHttpHost();
if (strpos($returnUrl, $domain) !== 0) {
$this->get('logger')->error(sprintf('Identity "%s" used illegal return-url for redirection after changing locale, aborting request', $this->getIdentity()->id));
throw new BadRequestHttpException('Invalid return-url given');
}
/** @var LoggerInterface $logger */
$logger = $this->get('logger');
$logger->info('Switching locale...');
$identity = $this->getIdentity();
if (!$identity) {
throw new AccessDeniedHttpException('Cannot switch locales when not authenticated');
}
$command = new SwitchLocaleCommand();
$command->identityId = $identity->id;
$form = $this->createForm('stepup_switch_locale', $command, ['route' => 'ra_switch_locale', 'route_parameters' => ['return_url' => $returnUrl]]);
$form->handleRequest($request);
if (!$form->isValid()) {
$this->addFlash('error', $this->get('translator')->trans('ra.flash.invalid_switch_locale_form'));
$logger->error('The switch locale form unexpectedly contained invalid data');
return $this->redirect($returnUrl);
}
$service = $this->get('ra.service.identity');
if (!$service->switchLocale($command)) {
$this->addFlash('error', $this->get('translator')->trans('ra.flash.error_while_switching_locale'));
$logger->error('An error occurred while switching locales');
return $this->redirect($returnUrl);
}
$logger->info('Successfully switched locale');
return $this->redirect($returnUrl);
}
示例8: logDuration
/**
* Logs the duration of a specific request through the application
*
* @param Request $request
* @param Response $response
* @param double $startTime
*/
protected static function logDuration(Request $request, Response $response, $startTime)
{
$duration = microtime(true) - $startTime;
$metric = self::prefix('request_time');
$tags = ["url" => $request->getSchemeAndHttpHost() . $request->getRequestUri(), "status_code" => $response->getStatusCode()];
Datadog::timing($metric, $duration, 1, $tags);
}
示例9: indexAction
public function indexAction(Request $request)
{
$configuration = [];
$authenticationType = $this->container->getParameter('ilios_authentication.type');
$configuration['type'] = $authenticationType;
if ($authenticationType == 'shibboleth') {
$loginPath = $this->container->getParameter('ilios_authentication.shibboleth.login_path');
$url = $request->getSchemeAndHttpHost();
$configuration['loginUrl'] = $url . $loginPath;
}
if ($authenticationType === 'cas') {
$cas = $this->container->get('ilios_authentication.cas.manager');
$configuration['casLoginUrl'] = $cas->getLoginUrl();
}
$configuration['locale'] = $this->container->getParameter('locale');
$ldapUrl = $this->container->getParameter('ilios_core.ldap.url');
if (!empty($ldapUrl)) {
$configuration['userSearchType'] = 'ldap';
} else {
$configuration['userSearchType'] = 'local';
}
$configuration['maxUploadSize'] = UploadedFile::getMaxFilesize();
$configuration['apiVersion'] = WebIndexFromJson::API_VERSION;
$configuration['trackingEnabled'] = $this->container->getParameter('ilios_core.enable_tracking');
if ($configuration['trackingEnabled']) {
$configuration['trackingCode'] = $this->container->getParameter('ilios_core.tracking_code');
}
return new JsonResponse(array('config' => $configuration));
}
示例10: switchAction
/**
* @param Request $request
* @param string $code
*
* @return Response
*/
public function switchAction(Request $request, $code)
{
if (!in_array($code, $this->currencyProvider->getAvailableCurrenciesCodes())) {
throw new HttpException(Response::HTTP_NOT_ACCEPTABLE, sprintf('The currency code "%s" is invalid.', $code));
}
$this->currencyChangeHandler->handle($code);
return new RedirectResponse($request->headers->get('referer', $request->getSchemeAndHttpHost()));
}
示例11: prepareOptions
/**
* @param Request $request
* @return array
*/
private function prepareOptions(Request $request)
{
$options = array(CURLOPT_POST => 1, CURLOPT_HEADER => 0, CURLOPT_URL => $request->getSchemeAndHttpHost() . $request->getRequestUri(), CURLOPT_FRESH_CONNECT => 1, CURLOPT_RETURNTRANSFER => 1, CURLOPT_FORBID_REUSE => 1, CURLOPT_TIMEOUT => 20, CURLOPT_POSTFIELDS => $request->getContent(), CURLOPT_SSL_VERIFYHOST => false, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_HTTPHEADER => array('Content-Type: ' . $request->getContentType(), 'Content-Length: ' . strlen($request->getContent())));
foreach ($this->options as $key => $value) {
$options[$key] = $value;
}
return $options;
}
示例12: installAction
/**
* Provide the install.html file.
*
* @param Request $request The request to process.
*
* @return Response
*/
public function installAction(Request $request)
{
// Special case, already setup. Redirect to index then.
if ($this->isInstalled()) {
return new RedirectResponse($request->getUri() . 'index.html');
}
return new Response(str_replace('var TENSIDEApi=window.location.href.split(\'#\')[0];', 'var TENSIDEApi=\'' . $request->getSchemeAndHttpHost() . $request->getBaseUrl() . '/\';', file_get_contents($this->getAssetsDir() . '/install.html')), 200, ['Content-Type' => 'text/html; charset=UTF-8']);
}
示例13: get_encoded_url
/**
* Gets the encoded URL that is passed to SnapSearch so that SnapSearch can scrape the encoded URL.
* If _escaped_fragment_ query parameter is used, this is converted back to a hash fragment URL.
*
* @return string URL intended for SnapSearch
*/
public function get_encoded_url()
{
if ($this->request->query->has('_escaped_fragment_')) {
$qs_and_hash = $this->get_real_qs_and_hash_fragment(true);
//the query string must be ahead of the hash, because anything after hash is never passed to the server
//and the server may require the query strings
$url = $this->request->getSchemeAndHttpHost() . $this->request->getBaseUrl() . $this->request->getPathInfo() . $qs_and_hash['qs'] . $qs_and_hash['hash'];
return $url;
} else {
//gets the rawurlencoded complete uri
return $this->request->getUri();
}
}
示例14: createNextLink
/**
* Creates a previous page link if avialiable.
* @param \Symfony\Component\HttpFoundation\Request $request
* @param int $offset
* @param int $limit
* @param int $total
* @return \Symfony\Component\HttpFoundation\Request mixed
*/
protected function createNextLink(Request $request, $offset, $limit, $total)
{
$nextLink = null;
$baseUri = $request->getSchemeAndHttpHost() . $request->getBaseUrl() . $request->getPathInfo();
if ($offset + $limit < $total) {
parse_str($request->getQueryString(), $qsArray);
$qsArray['limit'] = $limit;
$qsArray['offset'] = $limit + $offset;
$qs = Request::normalizeQueryString(http_build_query($qsArray));
$nextLink = $baseUri . '?' . $qs;
}
return $nextLink;
}
示例15: validateRequest
protected function validateRequest(Request $request)
{
// is the Request safe?
if (!$request->isMethodSafe()) {
throw new AccessDeniedHttpException();
}
// is the Request signed?
// we cannot use $request->getUri() here as we want to work with the original URI (no query string reordering)
if ($this->signer->check($request->getSchemeAndHttpHost() . $request->getBaseUrl() . $request->getPathInfo() . (null !== ($qs = $request->server->get('QUERY_STRING')) ? '?' . $qs : ''))) {
return;
}
throw new AccessDeniedHttpException();
}