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


PHP Request::getPort方法代码示例

本文整理汇总了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);
 }
开发者ID:renyunhuang,项目名称:nodephp,代码行数:7,代码来源:NodeCore.php

示例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'));
     }
 }
开发者ID:nickescobedo,项目名称:webapp,代码行数:35,代码来源:AuthController.php

示例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);
 }
开发者ID:laubosslink,项目名称:lab,代码行数:9,代码来源:RequestContext.php

示例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());
     }
 }
开发者ID:abhijitroy07,项目名称:mibew,代码行数:16,代码来源:UrlGenerator.php

示例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', ''));
 }
开发者ID:kchhainarong,项目名称:chantuchP,代码行数:16,代码来源:RequestContext.php

示例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);
     }
 }
开发者ID:nickaggarwal,项目名称:sample-symfony2,代码行数:35,代码来源:RequestListener.php

示例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();
     }
 }
开发者ID:yashb,项目名称:generator,代码行数:14,代码来源:UrlGenerator.php

示例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();
     }
 }
开发者ID:ningcaichen,项目名称:laravel-4.1-quick-start-cn,代码行数:14,代码来源:UrlGenerator.php

示例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;
 }
开发者ID:Maksold,项目名称:platform,代码行数:17,代码来源:UrlExtension.php

示例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;
 }
开发者ID:Hexanet,项目名称:MonologExtraBundle,代码行数:12,代码来源:RequestLogger.php

示例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;
 }
开发者ID:leloulight,项目名称:laravel_latest,代码行数:55,代码来源:MAC.php

示例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);
 }
开发者ID:caxy,项目名称:drupal-console-logging-middleware,代码行数:13,代码来源:RequestLoggingMiddleware.php

示例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);
 }
开发者ID:Tecnocreaciones,项目名称:ImagineService,代码行数:19,代码来源:WebPathResolver.php

示例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;
 }
开发者ID:Hariador,项目名称:oauth2-server,代码行数:46,代码来源:Mac.php

示例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()));
     }
 }
开发者ID:faridos,项目名称:ServerGroveLiveChat,代码行数:24,代码来源:RequestListener.php


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