本文整理汇总了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);
}
示例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;
}
示例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']))));
}
示例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;
}
示例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;
}
示例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);
}
示例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)))));
}
}
示例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));
}
示例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;
}
示例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);
}
示例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);
}
示例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();
}
示例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);
}
示例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);
}
}
示例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);
}