1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (https://nette.org)
5: * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6: */
7:
8: namespace Nette\Http;
9:
10:
11: /**
12: * Extended HTTP URL.
13: *
14: * <pre>
15: * http://nette.org/admin/script.php/pathinfo/?name=param#fragment
16: * \_______________/\________/
17: * | |
18: * scriptPath pathInfo
19: * </pre>
20: *
21: * - scriptPath: /admin/script.php (or simply /admin/ when script is directory index)
22: * - pathInfo: /pathinfo/ (additional path information)
23: *
24: * @property string $scriptPath
25: * @property-read string $pathInfo
26: */
27: class UrlScript extends Url
28: {
29: /** @var string */
30: private $scriptPath;
31:
32:
33: public function __construct($url = null, $scriptPath = '')
34: {
35: parent::__construct($url);
36: $this->setScriptPath($scriptPath);
37: }
38:
39:
40: /**
41: * Sets the script-path part of URI.
42: * @param string
43: * @return static
44: */
45: public function setScriptPath($value)
46: {
47: $this->scriptPath = (string) $value;
48: return $this;
49: }
50:
51:
52: /**
53: * Returns the script-path part of URI.
54: * @return string
55: */
56: public function getScriptPath()
57: {
58: return $this->scriptPath ?: $this->path;
59: }
60:
61:
62: /**
63: * Returns the base-path.
64: * @return string
65: */
66: public function getBasePath()
67: {
68: $pos = strrpos($this->getScriptPath(), '/');
69: return $pos === false ? '' : substr($this->getPath(), 0, $pos + 1);
70: }
71:
72:
73: /**
74: * Returns the additional path information.
75: * @return string
76: */
77: public function getPathInfo()
78: {
79: return (string) substr($this->getPath(), strlen($this->getScriptPath()));
80: }
81: }
82: