Source for file UriScript.php

Documentation is available at UriScript.php

  1. 1: <?php
  2. 2:  
  3. 3: /**
  4. 4:  * Nette Framework
  5. 5:  *
  6. 6:  * @copyright  Copyright (c) 2004, 2010 David Grudl
  7. 7:  * @license    http://nettephp.com/license  Nette license
  8. 8:  * @link       http://nettephp.com
  9. 9:  * @category   Nette
  10. 10:  * @package    Nette\Web
  11. 11:  */
  12. 12:  
  13. 13:  
  14. 14:  
  15. 15: /**
  16. 16:  * Extended HTTP URL.
  17. 17:  *
  18. 18:  * <pre>
  19. 19:  *                    basePath   relativeUri
  20. 20:  *                       |           |
  21. 21:  *                    /-----\/------------------\
  22. 22:  * http://nettephp.com/admin/script.php/pathinfo/?name=param#fragment
  23. 23:  *                    \_______________/\________/
  24. 24:  *                           |              |
  25. 25:  *                      scriptPath       pathInfo
  26. 26:  * </pre>
  27. 27:  *
  28. 28:  * - basePath:    /admin/ (everything before relative URI not including the script name)
  29. 29:  * - baseUri:     http://nettephp.com/admin/
  30. 30:  * - scriptPath:  /admin/script.php
  31. 31:  * - relativeUri: script.php/pathinfo/
  32. 32:  * - pathInfo:    /pathinfo/ (additional path information)
  33. 33:  *
  34. 34:  * @copyright  Copyright (c) 2004, 2010 David Grudl
  35. 35:  * @package    Nette\Web
  36. 36:  *
  37. 37:  * @property   string $scriptPath 
  38. 38:  * @property-read string $basePath 
  39. 39:  * @property-read string $baseUri 
  40. 40:  * @property-read string $relativeUri 
  41. 41:  * @property-read string $pathInfo 
  42. 42:  */
  43. 43: class UriScript extends Uri
  44. 44: {
  45. 45:     /** @var string */
  46. 46:     private $scriptPath '';
  47. 47:  
  48. 48:  
  49. 49:  
  50. 50:     /**
  51. 51:      * Sets the script-path part of URI.
  52. 52:      * @param  string 
  53. 53:      * @return UriScript  provides a fluent interface
  54. 54:      */
  55. 55:     public function setScriptPath($value)
  56. 56:     {
  57. 57:         $this->updating();
  58. 58:         $this->scriptPath = (string) $value;
  59. 59:         return $this;
  60. 60:     }
  61. 61:  
  62. 62:  
  63. 63:  
  64. 64:     /**
  65. 65:      * Returns the script-path part of URI.
  66. 66:      * @return string 
  67. 67:      */
  68. 68:     public function getScriptPath()
  69. 69:     {
  70. 70:         return $this->scriptPath;
  71. 71:     }
  72. 72:  
  73. 73:  
  74. 74:  
  75. 75:     /**
  76. 76:      * Returns the base-path.
  77. 77:      * @return string 
  78. 78:      */
  79. 79:     public function getBasePath()
  80. 80:     {
  81. 81:         return (string) substr($this->scriptPath0strrpos($this->scriptPath'/'1);
  82. 82:     }
  83. 83:  
  84. 84:  
  85. 85:  
  86. 86:     /**
  87. 87:      * Returns the base-URI.
  88. 88:      * @return string 
  89. 89:      */
  90. 90:     public function getBaseUri()
  91. 91:     {
  92. 92:         return $this->scheme '://' $this->getAuthority($this->getBasePath();
  93. 93:     }
  94. 94:  
  95. 95:  
  96. 96:  
  97. 97:     /**
  98. 98:      * Returns the relative-URI.
  99. 99:      * @return string 
  100. 100:      */
  101. 101:     public function getRelativeUri()
  102. 102:     {
  103. 103:         return (string) substr($this->pathstrrpos($this->scriptPath'/'1);
  104. 104:     }
  105. 105:  
  106. 106:  
  107. 107:  
  108. 108:     /**
  109. 109:      * Returns the additional path information.
  110. 110:      * @return string 
  111. 111:      */
  112. 112:     public function getPathInfo()
  113. 113:     {
  114. 114:         return (string) substr($this->pathstrlen($this->scriptPath));
  115. 115:     }
  116. 116: