當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Url::getBaseUrl方法代碼示例

本文整理匯總了PHP中Nette\Http\Url::getBaseUrl方法的典型用法代碼示例。如果您正苦於以下問題:PHP Url::getBaseUrl方法的具體用法?PHP Url::getBaseUrl怎麽用?PHP Url::getBaseUrl使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Nette\Http\Url的用法示例。


在下文中一共展示了Url::getBaseUrl方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: constructUrl

 public function constructUrl(Request $appRequest, Url $refUrl)
 {
     // Module prefix not match.
     if ($this->module && !Strings::startsWith($appRequest->getPresenterName(), $this->module)) {
         return null;
     }
     $params = $appRequest->getParameters();
     $urlStack = [];
     // Module prefix
     $moduleFrags = explode(":", Strings::lower($appRequest->getPresenterName()));
     $resourceName = array_pop($moduleFrags);
     $urlStack += $moduleFrags;
     // Resource
     $urlStack[] = Strings::lower($resourceName);
     // Id
     if (isset($params['id']) && is_scalar($params['id'])) {
         $urlStack[] = $params['id'];
         unset($params['id']);
     }
     // Set custom action
     if (isset($params['action']) && $this->_isApiAction($params['action'])) {
         unset($params['action']);
     }
     $url = $refUrl->getBaseUrl() . implode('/', $urlStack);
     // Add query parameters
     if (!empty($params)) {
         $url .= "?" . http_build_query($params);
     }
     return $url;
 }
開發者ID:bauer01,項目名稱:unimapper-nette,代碼行數:30,代碼來源:Route.php

示例2: constructUrl

 /**
  * Constructs absolute URL from Request object.
  *
  * @return string|NULL
  */
 public function constructUrl(AppRequest $appRequest, Url $refUrl)
 {
     if ($this->flags & self::ONE_WAY) {
         return NULL;
     }
     $params = $appRequest->getParameters();
     if (!isset($params['action']) || !is_string($params['action'])) {
         return NULL;
     }
     $key = $appRequest->getPresenterName() . ':' . $params['action'];
     if (!isset($this->tableOut[$key])) {
         return NULL;
     }
     if ($this->lastRefUrl !== $refUrl) {
         $this->lastBaseUrl = $refUrl->getBaseUrl();
         $this->lastRefUrl = $refUrl;
     }
     unset($params['action']);
     $slug = $this->tableOut[$key];
     $query = ($tmp = http_build_query($params)) ? '?' . $tmp : '';
     $url = $this->lastBaseUrl . $slug . $query;
     return $url;
 }
開發者ID:nextras,項目名稱:static-router,代碼行數:28,代碼來源:StaticRouter.php

示例3: constructUrl

 /**
  * Constructs absolute URL from Request object.
  *
  * @param \Nette\Application\Request $appRequest
  * @param \Nette\Http\Url $refUrl
  * @throws \Nette\InvalidStateException
  * @return string|NULL
  */
 public function constructUrl(Request $appRequest, Url $refUrl)
 {
     // Module prefix not match.
     if ($this->module && !Strings::startsWith($appRequest->getPresenterName(), $this->module)) {
         return null;
     }
     $parameters = $appRequest->getParameters();
     $urlStack = array();
     // Module prefix.
     $moduleFrags = explode(":", $appRequest->getPresenterName());
     if (count($moduleFrags)) {
         foreach ($moduleFrags as &$fragment) {
             $fragment = $this->presenter2path($fragment);
         }
     }
     $resourceName = array_pop($moduleFrags);
     $urlStack += $moduleFrags;
     if (isset($parameters['associations']) && is_array($parameters['associations'])) {
         $associations =& $parameters['associations'];
         foreach ($associations as $key => $value) {
             $urlStack[] = $key;
             $urlStack[] = $value;
         }
     }
     $urlStack[] = $resourceName;
     if (isset($parameters['specific_action']) && $parameters['specific_action']) {
         $urlStack[] = $this->action2path($parameters['specific_action']);
     }
     if (isset($parameters['id']) && is_scalar($parameters['id'])) {
         $urlStack[] = $parameters['id'];
     }
     $url = $q = $refUrl->getBaseUrl() . implode('/', $urlStack);
     if (isset($parameters['query']) && count($parameters['query'])) {
         $sep = ini_get('arg_separator.input');
         $query = http_build_query($parameters['query'], '', $sep ? $sep[0] : '&');
         $url .= '?' . $query;
     }
     return $url;
 }
開發者ID:Budry,項目名稱:TinyREST,代碼行數:47,代碼來源:RestRoute.php

示例4: constructUrl

 /**
  * Constructs absolute URL from Request object.
  * @param \Nette\Application\Request $appRequest
  * @param \Nette\Http\Url $refUrl
  * @throws \Nette\InvalidStateException
  * @return string|NULL
  */
 public function constructUrl(Request $appRequest, Url $refUrl)
 {
     // Module prefix not match.
     if ($this->module && !Strings::startsWith($appRequest->getPresenterName(), $this->module)) {
         return NULL;
     }
     $parameters = $appRequest->getParameters();
     $url = $refUrl->getBaseUrl();
     $urlStack = [];
     // Module prefix.
     $moduleFrags = explode(":", $appRequest->getPresenterName());
     $moduleFrags = array_map('\\AdamStipak\\Support\\Inflector::spinalCase', $moduleFrags);
     $resourceName = array_pop($moduleFrags);
     $urlStack += $moduleFrags;
     // Associations.
     if (isset($parameters['associations']) && Validators::is($parameters['associations'], 'array')) {
         $associations = $parameters['associations'];
         unset($parameters['associations']);
         foreach ($associations as $key => $value) {
             $urlStack[] = $key;
             $urlStack[] = $value;
         }
     }
     // Resource.
     $urlStack[] = $resourceName;
     // Id.
     if (isset($parameters['id']) && Validators::is($parameters['id'], 'scalar')) {
         $urlStack[] = $parameters['id'];
         unset($parameters['id']);
     }
     $url = $url . implode('/', $urlStack);
     $sep = ini_get('arg_separator.input');
     if (isset($parameters['query'])) {
         $query = http_build_query($parameters['query'], '', $sep ? $sep[0] : '&');
         if ($query != '') {
             $url .= '?' . $query;
         }
     }
     return $url;
 }
開發者ID:newPOPE,項目名稱:Nette-RestRoute,代碼行數:47,代碼來源:RestRoute.php

示例5: constructUrl

 /**
  * Constructs absolute URL from Request object.
  * @param \Nette\Application\Request $appRequest
  * @param \Nette\Http\Url $refUrl
  * @throws \Nette\InvalidStateException
  * @return string|NULL
  */
 public function constructUrl(Request $appRequest, Url $refUrl)
 {
     // Module prefix not match.
     if ($this->module && !Strings::startsWith($appRequest->getPresenterName(), $this->module)) {
         return NULL;
     }
     $parameters = $appRequest->getParameters();
     $url = $refUrl->getBaseUrl();
     $urlStack = array();
     // Module prefix.
     $moduleFrags = explode(":", Strings::lower($appRequest->getPresenterName()));
     $resourceName = array_pop($moduleFrags);
     $urlStack += $moduleFrags;
     // Associations.
     if (isset($parameters['associations']) && Validators::is($parameters['associations'], 'array')) {
         $associations =& $parameters['associations'];
         if (count($associations) % 2 !== 0) {
             throw new InvalidStateException("Number of associations is not even");
         }
         foreach ($associations as $key => $value) {
             $urlStack[] = $key;
             $urlStack[] = $value;
         }
     }
     // Resource.
     $urlStack[] = Strings::lower($resourceName);
     // Id.
     if (isset($parameters['id']) && Validators::is($parameters['id'], 'scalar')) {
         $urlStack[] = $parameters['id'];
     }
     return $url . implode('/', $urlStack);
 }
開發者ID:dansilovsky,項目名稱:calendar,代碼行數:39,代碼來源:AdamRestRoute.php

示例6: constructUrl

 /**
  * Constructs absolute URL from Request object.
  * @return string|NULL
  */
 public function constructUrl(Request $request, Nette\Http\Url $url)
 {
     if ($this->presenter != $request->getPresenterName()) {
         return NULL;
     }
     $base_url = $url->getBaseUrl();
     $action = $request->getParameter('action');
     $parameters = $request->getParameters();
     unset($parameters['action']);
     $path = ltrim($this->getPath(), '/');
     if (FALSE === array_search($action, $this->actions)) {
         return NULL;
     }
     foreach ($parameters as $name => $value) {
         if (strpos($path, "<{$name}>") !== FALSE && $value !== NULL) {
             $path = str_replace("<{$name}>", $value, $path);
             unset($parameters[$name]);
         }
     }
     $path = preg_replace_callback('/\\[.+?\\]/', function ($item) {
         if (strpos(end($item), '<')) {
             return '';
         }
         return end($item);
     }, $path);
     /**
      * There are still some required parameters in url mask
      */
     if (preg_match('/<\\w+>/', $path)) {
         return NULL;
     }
     $path = str_replace(['[', ']'], '', $path);
     $query = http_build_query($parameters);
     return $base_url . $path . ($query ? '?' . $query : '');
 }
開發者ID:ublaboo,項目名稱:api-router,代碼行數:39,代碼來源:ApiRoute.php


注:本文中的Nette\Http\Url::getBaseUrl方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。