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