當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。