PageRenderTime 51ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/src/application/libraries/Zend/View/Helper/ServerUrl.php

https://bitbucket.org/masnug/grc276-blog-laravel
PHP | 148 lines | 60 code | 11 blank | 77 comment | 24 complexity | 3c27a383561c5f01b3fbb141f3fe6474 MD5 | raw file
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_View
  17. * @subpackage Helper
  18. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: ServerUrl.php 23953 2011-05-03 05:47:39Z ralph $
  21. */
  22. /**
  23. * Helper for returning the current server URL (optionally with request URI)
  24. *
  25. * @category Zend
  26. * @package Zend_View
  27. * @subpackage Helper
  28. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. */
  31. class Zend_View_Helper_ServerUrl
  32. {
  33. /**
  34. * Scheme
  35. *
  36. * @var string
  37. */
  38. protected $_scheme;
  39. /**
  40. * Host (including port)
  41. *
  42. * @var string
  43. */
  44. protected $_host;
  45. /**
  46. * Constructor
  47. *
  48. * @return void
  49. */
  50. public function __construct()
  51. {
  52. switch (true) {
  53. case (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] === true)):
  54. case (isset($_SERVER['HTTP_SCHEME']) && ($_SERVER['HTTP_SCHEME'] == 'https')):
  55. case (isset($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] == 443)):
  56. $scheme = 'https';
  57. break;
  58. default:
  59. $scheme = 'http';
  60. }
  61. $this->setScheme($scheme);
  62. if (isset($_SERVER['HTTP_HOST']) && !empty($_SERVER['HTTP_HOST'])) {
  63. $this->setHost($_SERVER['HTTP_HOST']);
  64. } else if (isset($_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT'])) {
  65. $name = $_SERVER['SERVER_NAME'];
  66. $port = $_SERVER['SERVER_PORT'];
  67. if (($scheme == 'http' && $port == 80) ||
  68. ($scheme == 'https' && $port == 443)) {
  69. $this->setHost($name);
  70. } else {
  71. $this->setHost($name . ':' . $port);
  72. }
  73. }
  74. }
  75. /**
  76. * View helper entry point:
  77. * Returns the current host's URL like http://site.com
  78. *
  79. * @param string|boolean $requestUri [optional] if true, the request URI
  80. * found in $_SERVER will be appended
  81. * as a path. If a string is given, it
  82. * will be appended as a path. Default
  83. * is to not append any path.
  84. * @return string server url
  85. */
  86. public function serverUrl($requestUri = null)
  87. {
  88. if ($requestUri === true) {
  89. $path = $_SERVER['REQUEST_URI'];
  90. } else if (is_string($requestUri)) {
  91. $path = $requestUri;
  92. } else {
  93. $path = '';
  94. }
  95. return $this->getScheme() . '://' . $this->getHost() . $path;
  96. }
  97. /**
  98. * Returns host
  99. *
  100. * @return string host
  101. */
  102. public function getHost()
  103. {
  104. return $this->_host;
  105. }
  106. /**
  107. * Sets host
  108. *
  109. * @param string $host new host
  110. * @return Zend_View_Helper_ServerUrl fluent interface, returns self
  111. */
  112. public function setHost($host)
  113. {
  114. $this->_host = $host;
  115. return $this;
  116. }
  117. /**
  118. * Returns scheme (typically http or https)
  119. *
  120. * @return string scheme (typically http or https)
  121. */
  122. public function getScheme()
  123. {
  124. return $this->_scheme;
  125. }
  126. /**
  127. * Sets scheme (typically http or https)
  128. *
  129. * @param string $scheme new scheme (typically http or https)
  130. * @return Zend_View_Helper_ServerUrl fluent interface, returns self
  131. */
  132. public function setScheme($scheme)
  133. {
  134. $this->_scheme = $scheme;
  135. return $this;
  136. }
  137. }