当前位置: 首页>>代码示例>>PHP>>正文


PHP Request::getBaseUrl方法代码示例

本文整理汇总了PHP中Symfony\Component\HttpFoundation\Request::getBaseUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getBaseUrl方法的具体用法?PHP Request::getBaseUrl怎么用?PHP Request::getBaseUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\HttpFoundation\Request的用法示例。


在下文中一共展示了Request::getBaseUrl方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: generateUrlCanonical

 /**
  * @param CanonicalUrlEvent $event
  */
 public function generateUrlCanonical(CanonicalUrlEvent $event)
 {
     if ($event->getUrl() !== null) {
         return;
     }
     $parseUrlByCurrentLocale = $this->getParsedUrlByCurrentLocale();
     if (empty($parseUrlByCurrentLocale['host'])) {
         return;
     }
     // Be sure to use the proper domain name
     $canonicalUrl = $parseUrlByCurrentLocale['scheme'] . '://' . $parseUrlByCurrentLocale['host'];
     // preserving a potential subdirectory, e.g. http://somehost.com/mydir/index.php/...
     $canonicalUrl .= $this->request->getBaseUrl();
     // Remove script name from path, e.g. http://somehost.com/index.php/...
     $canonicalUrl = preg_replace("!/index(_dev)?\\.php!", '', $canonicalUrl);
     $path = $this->request->getPathInfo();
     if (!empty($path) && $path != "/") {
         $canonicalUrl .= $path;
         $canonicalUrl = rtrim($canonicalUrl, '/');
     } else {
         $queryString = $this->request->getQueryString();
         if (!empty($queryString)) {
             $canonicalUrl .= '/?' . $queryString;
         }
     }
     $event->setUrl($canonicalUrl);
 }
开发者ID:thelia-modules,项目名称:CanonicalUrl,代码行数:30,代码来源:CanonicalUrlListener.php

示例2: format

 /**
  * Format a collection of documentation data.
  *
  * @param  array        $collection
  * @param  null         $resource
  * @internal param $array [ApiDoc] $collection
  * @return string|array
  */
 public function format(array $collection, $resource = null)
 {
     $result = $this->formatter->format($collection, $resource);
     if ($resource !== null) {
         $result['basePath'] = $this->request->getBaseUrl() . $result['basePath'];
     }
     return $result;
 }
开发者ID:ABD-dev,项目名称:NelmioApiDocBundle,代码行数:16,代码来源:RequestAwareSwaggerFormatter.php

示例3: startJsApplication

 /**
  * Generates JavaScript code that starts client side application.
  *
  * @param Request $request Incoming request.
  * @param array $operator Current operator.
  * @return string JavaScript code that starts "users" client side
  *   application.
  */
 protected function startJsApplication(Request $request, $operator)
 {
     // Load dialogs style options
     $chat_style = new ChatStyle(ChatStyle::getCurrentStyle());
     $chat_style_config = $style_config = $chat_style->getConfigurations();
     // Load page style options
     $page_style_config = $style_config = $this->getStyle()->getConfigurations();
     return sprintf('jQuery(document).ready(function() {Mibew.Application.start(%s);});', json_encode(array('server' => array('url' => $this->generateUrl('users_update'), 'requestsFrequency' => Settings::get('updatefrequency_operator')), 'agent' => array('id' => $operator['operatorid']), 'page' => array('mibewBasePath' => $request->getBasePath(), 'mibewBaseUrl' => $request->getBaseUrl(), 'showOnlineOperators' => Settings::get('showonlineoperators') == '1', 'showVisitors' => Settings::get('enabletracking') == '1', 'showPopup' => Settings::get('enablepopupnotification') == '1', 'threadTag' => $page_style_config['users']['thread_tag'], 'visitorTag' => $page_style_config['users']['visitor_tag'], 'agentLink' => $request->getBaseUrl() . '/operator/chat', 'geoLink' => Settings::get('geolink'), 'trackedLink' => $request->getBaseUrl() . '/operator/history/user-track', 'banLink' => $request->getBaseUrl() . '/operator/ban', 'inviteLink' => $request->getBaseUrl() . '/operator/invite', 'chatWindowParams' => $chat_style_config['chat']['window'], 'geoWindowParams' => Settings::get('geolinkparams'), 'trackedUserWindowParams' => $page_style_config['tracked']['user_window'], 'trackedVisitorWindowParams' => $page_style_config['tracked']['visitor_window'], 'banWindowParams' => $page_style_config['ban']['window'], 'inviteWindowParams' => $chat_style_config['chat']['window']))));
 }
开发者ID:abhijitroy07,项目名称:mibew,代码行数:17,代码来源:UsersController.php

示例4: getRedirectUrl

 public function getRedirectUrl()
 {
     $redirectUrl = $this->map->getUrlTo();
     if (!$this->isAbsoluteUrl($redirectUrl) && ($baseUrl = $this->request->getBaseUrl())) {
         $redirectUrl = $baseUrl . $redirectUrl;
     }
     $redirectUrl = $this->applyReplacements($redirectUrl);
     return $redirectUrl;
 }
开发者ID:byteworks-ch,项目名称:AstinaRedirectManagerBundle,代码行数:9,代码来源:Redirect.php

示例5: matchItem

 /**
  * @param ItemInterface $item
  *
  * @return bool
  */
 public function matchItem(ItemInterface $item)
 {
     $requestUri = $this->request->getRequestUri();
     $baseUrl = $this->request->getBaseUrl() . '/';
     $uri = $item->getUri();
     if ($uri === $requestUri) {
         return true;
     } else {
         if ($uri !== $baseUrl && substr($requestUri, 0, strlen($uri)) === $uri) {
             return true;
         }
     }
     return null;
 }
开发者ID:RamosBruno,项目名称:facebookQuizz,代码行数:19,代码来源:RequestVoter.php

示例6: handle

 public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
 {
     $pathInfo = rawurldecode($request->getPathInfo());
     foreach ($this->map as $path => $app) {
         if (0 === strpos($pathInfo, $path)) {
             $server = $request->server->all();
             $server['SCRIPT_FILENAME'] = $server['SCRIPT_NAME'] = $server['PHP_SELF'] = $request->getBaseUrl() . $path;
             $attributes = $request->attributes->all();
             $attributes[static::ATTR_PREFIX] = $request->getBaseUrl() . $path;
             $newRequest = $request->duplicate(null, null, $attributes, null, null, $server);
             return $app->handle($newRequest, $type, $catch);
         }
     }
     return $this->app->handle($request, $type, $catch);
 }
开发者ID:digitalkaoz,项目名称:url-map,代码行数:15,代码来源:UrlMap.php

示例7: 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)))));
     }
 }
开发者ID:Codixis,项目名称:CSBill,代码行数:20,代码来源:SystemInformationForm.php

示例8: indexAction

 public function indexAction(Request $request, $slug)
 {
     //echo '<pre>';print_r($slug);die;
     $page = new Page();
     $page->setUrl($request->getRequestUri());
     $page->setTitle('Homepage');
     $page->setSlug($slug);
     $site = new Site();
     $site->setBaseurl($request->getBaseUrl());
     $github = new \stdClass();
     $github->user = 'symfony-bundle';
     $github->repo = 'bootstrap-bundle';
     $site->setGithub($github);
     $data = $site->getData();
     $data['showcase'] = Yaml::parse(__DIR__ . '/../Resources/data/showcase.yml');
     $data['translations'] = Yaml::parse(__DIR__ . '/../Resources/data/translations.yml');
     $site->setData($data);
     $site->setDownload(array('dist' => 'https://github.com/twbs/bootstrap/releases/download/v3.2.0/bootstrap-3.2.0-dist.zip', 'source' => 'https://github.com/twbs/bootstrap/archive/v3.2.0.zip', 'sass' => 'https://github.com/twbs/bootstrap-sass/archive/v3.2.0.tar.gz'));
     $site->setCdn(array('css' => 'https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css', 'css_theme' => 'https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css', 'js' => 'https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js'));
     $site->setTime(new \DateTime());
     /*$content = $this->render(
           'BootstrapBundle:pages:' . $slug . '.html.twig',
           array(
               'site' => $site
           )
       )->getContent();*/
     if ($slug == 'index') {
         $file = 'home';
     } else {
         $file = 'default';
     }
     return $this->render('BootstrapBundle:layouts:' . $file . '.html.twig', array('page' => $page, 'site' => $site, 'slug' => $slug));
 }
开发者ID:symfony-bundle,项目名称:bootstrap-bundle,代码行数:33,代码来源:DocsController.php

示例9: fetchXmlSubRequest

 /**
  * Attempt to fetch the gallery's XML via a sub-request to another page.
  *
  * This assumes that the gallery XML has already been embedded within a normal
  * HTML page, at the given path, within a <script> block.
  *
  * @param string $path
  *   The Drupal path to use for the sub-request.
  * @param string $id
  *   The id to search for within the sub-request content that will contain
  *   the embedded XML.
  * @return string
  *   The embedded XML if found or an empty string.
  */
 protected function fetchXmlSubRequest($path, $id)
 {
     $xml = '';
     // We want to pass-through all details of the master request, but for some
     // reason the sub-request may fail with a 406 if some server params unique
     // to an XMLHttpRequest are used. So we reset those to generic values by
     // just removing them from the request details passed-through.
     $server = $this->request->server;
     $server->remove('HTTP_ACCEPT');
     $server->remove('HTTP_X_REQUESTED_WITH');
     $subRequest = Request::create($this->request->getBaseUrl() . '/' . $path, 'GET', $this->request->query->all(), $this->request->cookies->all(), $this->request->files->all(), $server->all());
     // @todo: See if this session check is needed.
     $session = $this->request->getSession();
     if ($session) {
         $subRequest->setSession($session);
     }
     $subResponse = $this->httpKernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
     // Search for the XML within the sub-request markup. We could parse the
     // DOM for this with DOMDocument, but a regex lookup is more lightweight.
     $matches = array();
     preg_match('/<script[^>]*id=\\"' . $id . '\\"[^>]*>(.*)<\\/script>/simU', $subResponse->getContent(), $matches);
     if (!empty($matches[1]) && strpos($matches[1], '<?xml') === 0) {
         $xml = $matches[1];
         // Set the cache tags directly from the sub-request response.
         if ($subResponse instanceof CacheableResponseInterface) {
             $response_cacheability = $subResponse->getCacheableMetadata();
             $this->cacheTags = Cache::mergeTags($this->cacheTags, $response_cacheability->getCacheTags());
         }
     }
     return $xml;
 }
开发者ID:pulibrary,项目名称:recap,代码行数:45,代码来源:JuiceboxXmlControllerBase.php

示例10: handle

 /**
  * {@inheritdoc}
  */
 public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
 {
     if (strpos($request->getRequestUri(), 'installer') !== false || !$this->isInstalled()) {
         define('MAUTIC_INSTALLER', 1);
     }
     if (defined('MAUTIC_INSTALLER')) {
         $uri = $request->getRequestUri();
         if (strpos($uri, 'installer') === false) {
             $base = $request->getBaseUrl();
             //check to see if the .htaccess file exists or if not running under apache
             if (strpos(strtolower($_SERVER['SERVER_SOFTWARE']), 'apache') === false || !file_exists(__DIR__ . '../.htaccess') && strpos($base, 'index') === false) {
                 $base .= '/index.php';
             }
             return new RedirectResponse($base . '/installer');
         }
     }
     if (false === $this->booted) {
         $this->boot();
     }
     // Check for an an active db connection and die with error if unable to connect
     if (!defined('MAUTIC_INSTALLER')) {
         $db = $this->getContainer()->get('database_connection');
         try {
             $db->connect();
         } catch (\Exception $e) {
             error_log($e);
             throw new \Mautic\CoreBundle\Exception\DatabaseConnectionException($this->getContainer()->get('translator')->trans('mautic.core.db.connection.error', ['%code%' => $e->getCode()]));
         }
     }
     return parent::handle($request, $type, $catch);
 }
开发者ID:dongilbert,项目名称:mautic,代码行数:34,代码来源:AppKernel.php

示例11: checkShorturlAction

 public function checkShorturlAction(Application $app, Request $request)
 {
     $enabledExtentions = $app['extensions']->getEnabled();
     $config = $enabledExtentions['shorturl']->config;
     $shorturl = $request->query->get('shorturl');
     $recordId = $request->query->get('recordId');
     $response = new \stdClass();
     $response->status = 'ok';
     $url = $app['paths']['hosturl'] . $request->getBaseUrl() . '/' . ($config['prefix'] ? $config['prefix'] . '/' : '') . $shorturl;
     $response->msg = 'This record will be accessible via <a href="' . $url . '" target="_blank">' . $url . '</a>.';
     // Check length & chars
     if (!preg_match('/[a-zA-Z0-9\\-_.]{2,' . $config['maxlength'] . '}$/', $shorturl)) {
         $response->status = 'error';
         $response->msg = 'Shorturl must at least have two characters and can only contain a-z, A-Z, 0-9, ".", "-" and "_".';
     }
     // check if unique
     $contentTypes = $app['config']->get('contenttypes');
     foreach ($contentTypes as $name => $contentType) {
         foreach ($contentType['fields'] as $key => $field) {
             if ($field['type'] === 'shorturl') {
                 $contentTypeContent = $app['storage']->getContent($name, array());
                 foreach ($contentTypeContent as $content) {
                     if ($content['id'] !== $recordId && !empty($content[$key]) && $content[$key] == $shorturl) {
                         $response->status = 'error';
                         $response->msg = 'Shorturl already exists.';
                         break;
                     }
                 }
             }
         }
     }
     return $app->json($response);
 }
开发者ID:AnimalDesign,项目名称:bolt-shorturl,代码行数:33,代码来源:AsyncController.php

示例12: checkRequestPath

 /**
  * Checks that a given path matches the Request.
  *
  * @param Request $request A Request instance
  * @param string  $path    A path (an absolute path (/foo), an absolute URL (http://...), or a route name (foo))
  *
  * @return Boolean true if the path is the same as the one from the Request, false otherwise
  */
 public function checkRequestPath(Request $request, $path)
 {
     if ('/' !== $path[0]) {
         $path = preg_replace('#' . preg_quote($request->getBaseUrl(), '#') . '#', '', $this->generateUrl($path));
     }
     return $path === $request->getPathInfo();
 }
开发者ID:nightchiller,项目名称:symfony,代码行数:15,代码来源:HttpUtils.php

示例13: __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);
 }
开发者ID:renyunhuang,项目名称:nodephp,代码行数:7,代码来源:NodeCore.php

示例14: initializeRequestAttributes

 protected function initializeRequestAttributes(Request $request, $master)
 {
     if ($master) {
         // set the context even if the parsing does not need to be done
         // to have correct link generation
         $this->router->setContext(array('base_url' => $request->getBaseUrl(), 'method' => $request->getMethod(), 'host' => $request->getHost(), 'port' => $request->getPort(), 'is_secure' => $request->isSecure()));
     }
     if ($request->attributes->has('_controller')) {
         // routing is already done
         return;
     }
     // add attributes based on the path info (routing)
     try {
         $parameters = $this->router->match($request->getPathInfo());
         if (null !== $this->logger) {
             $this->logger->info(sprintf('Matched route "%s" (parameters: %s)', $parameters['_route'], json_encode($parameters)));
         }
         $request->attributes->add($parameters);
         if ($locale = $request->attributes->get('_locale')) {
             $request->getSession()->setLocale($locale);
         }
     } catch (NotFoundException $e) {
         $message = sprintf('No route found for "%s %s"', $request->getMethod(), $request->getPathInfo());
         if (null !== $this->logger) {
             $this->logger->err($message);
         }
         throw new NotFoundHttpException($message, $e);
     } catch (MethodNotAllowedException $e) {
         $message = sprintf('No route found for "%s %s": Method Not Allowed (Allow: %s)', $request->getMethod(), $request->getPathInfo(), strtoupper(implode(', ', $e->getAllowedMethods())));
         if (null !== $this->logger) {
             $this->logger->err($message);
         }
         throw new MethodNotAllowedHttpException($e->getAllowedMethods(), $message, $e);
     }
 }
开发者ID:nickaggarwal,项目名称:sample-symfony2,代码行数:35,代码来源:RequestListener.php

示例15: getRefererParams

 /**
  * @param Request $request
  * @return mixed
  */
 private function getRefererParams(Request $request)
 {
     $referer = $request->headers->get('referer');
     $baseUrl = $request->getBaseUrl();
     $lastPath = substr($referer, strpos($referer, $baseUrl) + strlen($baseUrl));
     return $this->get('router')->getMatcher()->match($lastPath);
 }
开发者ID:jahller,项目名称:streetartlas,代码行数:11,代码来源:PieceController.php


注:本文中的Symfony\Component\HttpFoundation\Request::getBaseUrl方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。