本文整理汇总了PHP中Symfony\Component\HttpFoundation\Request::getPort方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getPort方法的具体用法?PHP Request::getPort怎么用?PHP Request::getPort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\Request
的用法示例。
在下文中一共展示了Request::getPort方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __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);
}
示例2: 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'));
}
}
示例3: 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);
}
示例4: 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());
}
}
示例5: fromRequest
/**
* Updates the RequestContext info based on a HttpFoundation Request.
*
* @param Request $request A Request instance
*/
public function fromRequest(Request $request)
{
$this->setBaseUrl($request->getBaseUrl());
$this->setPathInfo($request->getPathInfo());
$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);
$this->setQueryString($request->server->get('QUERY_STRING', ''));
}
示例6: 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);
}
}
示例7: addPortToDomain
/**
* Add the port to the domain if necessary.
*
* @param string $domain
* @return string
*/
protected function addPortToDomain($domain)
{
if ($this->request->getPort() == '80') {
return $domain;
} else {
return $domain .= ':' . $this->request->getPort();
}
}
示例8: addPortToDomain
/**
* Add the port to the domain if necessary.
*
* @param string $domain
* @return string
*/
protected function addPortToDomain($domain)
{
if (in_array($this->request->getPort(), array('80', '443'))) {
return $domain;
} else {
return $domain .= ':' . $this->request->getPort();
}
}
示例9: isUrlLocal
public function isUrlLocal($link)
{
if (!$this->request) {
return false;
}
$parts = parse_url($link);
$isLocal = true;
if (!empty($parts['host']) && $parts['host'] !== $this->request->getHost()) {
$isLocal = false;
} elseif (!empty($parts['port']) && $parts['port'] !== $this->request->getPort()) {
$isLocal = false;
} elseif (!empty($parts['scheme']) && $this->request->isSecure() && $parts['scheme'] !== 'https') {
// going out from secure connection to insecure page on same domain is not local
$isLocal = false;
}
return $isLocal;
}
示例10: createContexts
public function createContexts(Request $request)
{
$map = array('request_method' => $request->getMethod(), 'request_uri' => $request->getRequestUri(), 'request_route' => $request->attributes->get('_route'), 'request_host' => $request->getHost(), 'request_port' => $request->getPort(), 'request_scheme' => $request->getScheme(), 'request_client_ip' => $request->getClientIp(), 'request_content_type' => $request->getContentType(), 'request_acceptable_content_types' => $request->getAcceptableContentTypes(), 'request_etags' => $request->getETags(), 'request_charsets' => $request->getCharsets(), 'request_languages' => $request->getLanguages(), 'request_locale' => $request->getLocale(), 'request_auth_user' => $request->getUser(), 'request_auth_has_password' => !is_null($request->getPassword()));
// Attributes from newer versions.
if (method_exists($request, 'getEncodings')) {
$map['request_encodings'] = $request->getEncodings();
}
if (method_exists($request, 'getClientIps')) {
$map['request_client_ips'] = $request->getClientIps();
}
return $map;
}
示例11: determineAccessTokenInHeader
/**
* {@inheritdoc}
*/
public function determineAccessTokenInHeader(Request $request)
{
if ($request->headers->has('Authorization') === false) {
return;
}
$header = $request->headers->get('Authorization');
if (substr($header, 0, 4) !== 'MAC ') {
return;
}
// Find all the parameters expressed in the header
$paramsRaw = explode(',', substr($header, 4));
$params = new ParameterBag();
array_map(function ($param) use(&$params) {
$param = trim($param);
preg_match_all('/([a-zA-Z]*)="([\\w=]*)"/', $param, $matches);
// @codeCoverageIgnoreStart
if (count($matches) !== 3) {
return;
}
// @codeCoverageIgnoreEnd
$key = reset($matches[1]);
$value = trim(reset($matches[2]));
if (empty($value)) {
return;
}
$params->set($key, $value);
}, $paramsRaw);
// Validate parameters
if ($params->has('id') === false || $params->has('ts') === false || $params->has('nonce') === false || $params->has('mac') === false) {
return;
}
if ((int) $params->get('ts') !== time()) {
return;
}
$accessToken = $params->get('id');
$timestamp = (int) $params->get('ts');
$nonce = $params->get('nonce');
$signature = $params->get('mac');
// Try to find the MAC key for the access token
$macKey = $this->server->getMacStorage()->getByAccessToken($accessToken);
if ($macKey === null) {
return;
}
// Calculate and compare the signature
$calculatedSignatureParts = [$timestamp, $nonce, strtoupper($request->getMethod()), $request->getUri(), $request->getHost(), $request->getPort()];
if ($params->has('ext')) {
$calculatedSignatureParts[] = $params->get('ext');
}
$calculatedSignature = base64_encode(hash_hmac('sha256', implode("\n", $calculatedSignatureParts), $macKey));
// Return the access token if the signature matches
return $this->hash_equals($calculatedSignature, $signature) ? $accessToken : null;
}
示例12: logRequest
protected function logRequest(Request $request)
{
$msg = 'Request "{request_method} {request_uri}"';
$map = array('request_method' => $request->getMethod(), 'request_uri' => $request->getRequestUri(), 'request_host' => $request->getHost(), 'request_port' => $request->getPort(), 'request_scheme' => $request->getScheme(), 'request_client_ip' => $request->getClientIp(), 'request_content_type' => $request->getContentType(), 'request_acceptable_content_types' => $request->getAcceptableContentTypes(), 'request_etags' => $request->getETags(), 'request_charsets' => $request->getCharsets(), 'request_languages' => $request->getLanguages(), 'request_locale' => $request->getLocale(), 'request_auth_user' => $request->getUser(), 'request_auth_has_password' => !is_null($request->getPassword()));
// Attributes from newer versions.
if (method_exists($request, 'getEncodings')) {
$map['request_encodings'] = $request->getEncodings();
}
if (method_exists($request, 'getClientIps')) {
$map['request_client_ips'] = $request->getClientIps();
}
$this->logger->log($this->logLevel, $msg, $map);
}
示例13: getBaseUrl
/**
* @return string
*/
protected function getBaseUrl()
{
$port = '';
if ('https' == $this->request->getScheme() && $this->request->getPort() != 443) {
$port = ":{$this->request->getPort()}";
}
if ('http' == $this->request->getScheme() && $this->request->getPort() != 80) {
$port = ":{$this->request->getPort()}";
}
$baseUrl = $this->request->getBaseUrl();
if ('.php' == substr($this->request->getBaseUrl(), -4)) {
$baseUrl = pathinfo($this->request->getBaseurl(), PATHINFO_DIRNAME);
}
$baseUrl = rtrim($baseUrl, '/\\');
return sprintf('%s://%s%s%s', $this->request->getScheme(), $this->request->getHost(), $port, $baseUrl);
}
示例14: determineAccessTokenInHeader
/**
* {@inheritdoc}
*/
public function determineAccessTokenInHeader(Request $request)
{
if ($authorizationHeader = substr($request->headers->get('Authorization'), 0, 4) !== 'MAC ') {
return false;
}
// Find all the parameters expressed in the header
$params = [];
foreach (explode(',', substr($authorizationHeader, 4)) as $param) {
$param = trim($param);
preg_match_all('/([a-zA-Z]*)="([\\w=]*)"/', $param, $matches);
// @codeCoverageIgnoreStart
if (count($matches) !== 3) {
continue;
}
// @codeCoverageIgnoreEnd
$key = reset($matches[1]);
$value = trim(reset($matches[2]));
if (empty($value)) {
continue;
}
if ($key == 'ts') {
$value = (int) $value;
}
$params[$key] = $value;
}
if (empty($params['id']) || empty($params['ts']) || empty($params['nonce']) || empty($params['mac'])) {
return false;
}
if ($params['ts'] !== time()) {
return false;
}
if (!($macKey = $this->macTokenRepository->findByAccessTokenId($params['id']))) {
return false;
}
// Calculate and compare the signature
$calculatedSignatureParts = [$params['timestamp'], $params['nonce'], strtoupper($request->getMethod()), $request->getUri(), $request->getHost(), $request->getPort()];
if (!empty($params['ext'])) {
$calculatedSignatureParts[] = $params['ext'];
}
$calculatedSignature = base64_encode(hash_hmac('sha256', implode("\n", $calculatedSignatureParts), $macKey));
// Return the access token if the signature matches
return $this->hashEquals($calculatedSignature, $params['mac']) ? $params['id'] : null;
}
示例15: 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)
if (false !== ($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);
}
} elseif (null !== $this->logger) {
$this->logger->err(sprintf('No route found for %s', $request->getPathInfo()));
}
}