Skip to content

Commit 07216c7

Browse files
committed
Avoid to build the request twice
1 parent dd526db commit 07216c7

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/WaterPipe/Routing/Router.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class Router
4949
*/
5050
private $_request;
5151

52+
private $_built = false;
53+
5254
private function __construct()
5355
{
5456
$this->_request =& Request::getInstance();
@@ -65,8 +67,12 @@ public static function &getInstance()
6567

6668
public function build()
6769
{
68-
$this->_detectUri();
69-
$this->_detectMethod();
70+
if (!$this->_built) {
71+
$this->_detectUri();
72+
$this->_detectMethod();
73+
74+
$this->_built = true;
75+
}
7076

7177
return $this;
7278
}
@@ -142,6 +148,14 @@ private function _detectMethod()
142148
}
143149
}
144150

151+
/**
152+
* @return bool
153+
*/
154+
public function isBuilt(): bool
155+
{
156+
return $this->_built;
157+
}
158+
145159
/**
146160
* @return Request
147161
*/

0 commit comments

Comments
 (0)