本文整理汇总了PHP中Symfony\Component\HttpFoundation\Request::getScriptName方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getScriptName方法的具体用法?PHP Request::getScriptName怎么用?PHP Request::getScriptName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\Request
的用法示例。
在下文中一共展示了Request::getScriptName方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: canRedirect
/**
* Determines if redirect may be performed.
*
* @param Request $request
* The current request object.
* @param string $route_name
* The current route name.
*
* @return bool
* TRUE if redirect may be performed.
*/
public function canRedirect(Request $request, $route_name = NULL)
{
$can_redirect = TRUE;
if (isset($route_name)) {
$route = $this->routeProvider->getRouteByName($route_name);
if ($this->config->get('access_check')) {
// Do not redirect if is a protected page.
$can_redirect = $this->accessManager->checkNamedRoute($route_name, [], $this->account);
}
} else {
$route = $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT);
}
if (strpos($request->getScriptName(), 'index.php') === FALSE) {
// Do not redirect if the root script is not /index.php.
$can_redirect = FALSE;
} elseif (!($request->isMethod('GET') || $request->isMethod('HEAD'))) {
// Do not redirect if this is other than GET request.
$can_redirect = FALSE;
} elseif ($this->state->get('system.maintenance_mode') || defined('MAINTENANCE_MODE')) {
// Do not redirect in offline or maintenance mode.
$can_redirect = FALSE;
} elseif ($this->config->get('ignore_admin_path') && isset($route)) {
// Do not redirect on admin paths.
$can_redirect &= !(bool) $route->getOption('_admin_route');
}
return $can_redirect;
}
示例2: start
public function start(Request $request, AuthenticationException $authException = null)
{
$scheme = $request->isSecure() ? 'http' : 'https';
if ('http' === $scheme && 80 != $this->httpPort) {
$port = ':' . $this->httpPort;
} elseif ('https' === $scheme && 443 != $this->httpPort) {
$port = ':' . $this->httpsPort;
} else {
$port = '';
}
$qs = $request->getQueryString();
if (null !== $qs) {
$qs = '?' . $qs;
}
$url = $scheme . '://' . $request->getHost() . $port . $request->getScriptName() . $request->getPathInfo() . $qs;
return new RedirectResponse($url, 301);
}
示例3: testGetScriptName
public function testGetScriptName()
{
$request = new Request();
$this->assertEquals('', $request->getScriptName());
$server = array();
$server['SCRIPT_NAME'] = '/index.php';
$request->initialize(array(), array(), array(), array(), array(), $server);
$this->assertEquals('/index.php', $request->getScriptName());
$server = array();
$server['ORIG_SCRIPT_NAME'] = '/frontend.php';
$request->initialize(array(), array(), array(), array(), array(), $server);
$this->assertEquals('/frontend.php', $request->getScriptName());
$server = array();
$server['SCRIPT_NAME'] = '/index.php';
$server['ORIG_SCRIPT_NAME'] = '/frontend.php';
$request->initialize(array(), array(), array(), array(), array(), $server);
$this->assertEquals('/index.php', $request->getScriptName());
}
示例4: logRequest
/**
* Request のログを出力する.
*
* @param Request $request
* @return string Request のログ
*/
protected function logRequest(Request $request)
{
$log = '';
$log .= $this->logKeyValuePair('REMOTE_ADDR', $request->getClientIp());
$log .= $this->logKeyValuePair('SCRIPT_NAME', $request->getScriptName());
$log .= $this->logKeyValuePair('PATH_INFO', $request->getPathInfo());
$log .= $this->logKeyValuePair('BASE_PATH', $request->getBasePath());
$log .= $this->logKeyValuePair('BASE_URL', $request->getBaseUrl());
$log .= $this->logKeyValuePair('SCHEME', $request->getScheme());
$log .= $this->logKeyValuePair('REMOTE_USER', $request->getUser());
$log .= $this->logKeyValuePair('HTTP_HOST', $request->getSchemeAndHttpHost());
$log .= $this->logKeyValuePair('REQUEST_URI', $request->getRequestUri());
$log .= $this->logKeyValuePair('METHOD', $request->getRealMethod());
$log .= $this->logKeyValuePair('LOCALE', $request->getLocale());
// $log .= $this->logArray($request->server->all(), '[server]'); // 大量にログ出力される...
$log .= $this->logArray($request->headers->all(), '[header]');
$log .= $this->logArray($request->query->all(), '[get]');
$log .= $this->logArray($request->request->all(), '[post]');
$log .= $this->logArray($request->attributes->all(), '[attributes]');
$log .= $this->logArray($request->cookies->all(), '[cookie]');
$log .= $this->logArray($request->files->all(), '[files]');
return $log;
}
示例5: isCleanUrl
/**
* Returns whether the request is using a clean URL.
*
* A clean URL is one that does not include the script name. For example,
* - http://example.com/node/1 is a clean URL.
* - http://example.com/index.php/node/1 is not a clean URL.
*
* Unclean URLs are required on sites hosted by web servers that cannot be
* configured to implicitly route URLs to index.php.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The request.
*
* @return bool
* TRUE if the request is using a clean URL.
*/
public static function isCleanUrl(Request $request)
{
$base_url = $request->getBaseUrl();
return empty($base_url) || strpos($base_url, $request->getScriptName()) === FALSE;
}
示例6: setCiPaths
/**
* Initialize CodeIgniter system paths and defines
*
* @param Request $request
*
* @throws \UnexpectedValueException
*/
public function setCiPaths(Request $request = null)
{
if (!$this->isConfigValid()) {
throw new \UnexpectedValueException('Bundle configuration is not valid. You need to specify application_path and system_path in config.yml');
}
if ($this->pathsInitialized === false) {
$scriptFile = $request !== null ? '.' . $request->getBasePath() . $request->getScriptName() : __FILE__;
$rootPath = realpath($this->kernel->getRootDir() . '/..');
if ($rootPath === false) {
throw new \LogicException('Nercury CI bundle was expecting to find kernel root dir in /app directory.');
}
$systemPath = $this->getSystemPath() . '/';
$applicationFolder = $this->getAppPath() . '/';
if ($scriptFile === __FILE__) {
$scriptFile = $rootPath . '/app.php';
$rootPath = realpath($rootPath . '/' . $systemPath) . '/';
$applicationFolder = realpath($rootPath . '/' . $applicationFolder);
}
$environment = $this->kernel->getEnvironment();
$environmentMap = array('dev' => 'development', 'test' => 'testing', 'prod' => 'production');
if (array_key_exists($environment, $environmentMap)) {
$environment = $environmentMap[$environment];
}
define('ENVIRONMENT', $environment);
/*
* -------------------------------------------------------------------
* Now that we know the path, set the main path constants
* -------------------------------------------------------------------
*/
// The name of THIS file
define('SELF', pathinfo($scriptFile, PATHINFO_BASENAME));
// The PHP file extension
// this global constant is deprecated.
define('EXT', '.php');
// Path to the system folder
define('BASEPATH', str_replace("\\", "/", $systemPath));
// Name of the "system folder"
define('SYSDIR', trim(strrchr(trim(BASEPATH, '/'), '/'), '/'));
define('APPPATH', $applicationFolder . '/');
// Path to the front controller (this file)
define('FCPATH', $applicationFolder . '../');
// if (!defined('APPPATH')) {
// // The path to the "application" folder
// if (is_dir($application_folder)) {
// define('APPPATH', $application_folder . '/');
// } else {
// if (!is_dir(BASEPATH . $application_folder . '/')) {
// exit("Your application folder path does not appear to be set correctly. Please open the following file and correct this: " . SELF);
// }
//
// define('APPPATH', BASEPATH . $application_folder . '/');
// }
// }
$this->pathsInitialized = true;
}
}
示例7: setCiPaths
/**
* Initialize code igniter system paths and defines
*
* @param Request $request
* @throws Exception
*/
public function setCiPaths(Request $request = null)
{
if (!$this->isConfigValid()) {
throw new \Exception('Code Igniter configuration is not valid.');
}
if ($this->paths_initalized === false) {
$script_file = $request !== null ? '.' . $request->getBasePath() . $request->getScriptName() : __FILE__;
$root_path = realpath($this->kernel->getRootDir() . '/..');
if ($root_path === false) {
throw new \LogicException('Nercury CI bundle was expecting to find kernel root dir in /app directory.');
}
$system_path = $this->getRelativePath($root_path, $this->getSystemPath()) . '/';
$application_folder = $this->getRelativePath($root_path, $this->getAppPath());
if ($script_file === __FILE__) {
$script_file = $root_path . '/app.php';
$system_path = realpath($root_path . '/' . $system_path) . '/';
$application_folder = realpath($root_path . '/' . $application_folder);
}
/*
* -------------------------------------------------------------------
* Now that we know the path, set the main path constants
* -------------------------------------------------------------------
*/
// The name of THIS file
define('SELF', pathinfo($script_file, PATHINFO_BASENAME));
// The PHP file extension
// this global constant is deprecated.
define('EXT', '.php');
// Path to the system folder
define('BASEPATH', str_replace("\\", "/", $system_path));
// Path to the front controller (this file)
define('FCPATH', str_replace(SELF, '', __FILE__));
// Name of the "system folder"
define('SYSDIR', trim(strrchr(trim(BASEPATH, '/'), '/'), '/'));
// The path to the "application" folder
if (is_dir($application_folder)) {
define('APPPATH', $application_folder . '/');
} else {
if (!is_dir(BASEPATH . $application_folder . '/')) {
exit("Your application folder path does not appear to be set correctly. Please open the following file and correct this: " . SELF);
}
define('APPPATH', BASEPATH . $application_folder . '/');
}
$this->paths_initalized = true;
}
}
示例8: addRequestInfo
private function addRequestInfo(Request $request, PrettyPageHandler $handler)
{
$handler->addDataTable('Request', array('URI' => $request->getUri(), 'Request URI' => $request->getRequestUri(), 'Path Info' => $request->getPathInfo(), 'Query String' => $request->getQueryString() ?: '<none>', 'HTTP Method' => $request->getMethod(), 'Script Name' => $request->getScriptName(), 'Base Path' => $request->getBasePath(), 'Base URL' => $request->getBaseUrl(), 'Scheme' => $request->getScheme(), 'Port' => $request->getPort(), 'Host' => $request->getHost()));
}