File tree Expand file tree Collapse file tree 6 files changed +60
-3
lines changed
Expand file tree Collapse file tree 6 files changed +60
-3
lines changed Original file line number Diff line number Diff line change 1+ /.idea
12/vendor
23composer.phar
34composer.lock
Original file line number Diff line number Diff line change @@ -35,7 +35,12 @@ protected function matchPath(Nav $nav)
3535 }
3636
3737 $ navPath = parse_url ($ navPattern , PHP_URL_PATH );
38- $ match = strpos ($ currentPath , $ navPath ) !== false || fnmatch ($ navPath , $ currentPath );
38+
39+ if ($ nav ->patternIsMatchExact ()) {
40+ $ match = $ currentPath === $ navPath ;
41+ } else {
42+ $ match = strpos ($ currentPath , $ navPath ) !== false || fnmatch ($ navPath , $ currentPath );
43+ }
3944
4045 if ($ match ) {
4146 break ;
@@ -58,7 +63,11 @@ protected function matchQuery(Nav $nav)
5863
5964 parse_str ($ navQuery , $ navQuery );
6065
61- $ match = empty (array_diff ($ navQuery , $ expectedQuery ));
66+ if ($ nav ->patternIsMatchExact ()) {
67+ $ match = $ navQuery == $ expectedQuery ;
68+ } else {
69+ $ match = empty (array_diff ($ navQuery , $ expectedQuery ));
70+ }
6271
6372 if ($ match ) {
6473 break ;
Original file line number Diff line number Diff line change @@ -62,6 +62,11 @@ public function setChild(NavCollection $child);
6262 */
6363 public function getPattern ();
6464
65+ /**
66+ * @return bool
67+ */
68+ public function patternIsMatchExact ();
69+
6570 /**
6671 * @param Nav $nav
6772 * @return Nav
Original file line number Diff line number Diff line change @@ -15,6 +15,8 @@ abstract class NavItem implements Nav
1515
1616 protected $ patterns = [];
1717
18+ protected $ patternMatchExact = false ;
19+
1820 abstract public function getText ();
1921
2022 abstract public function getUrl ();
@@ -97,10 +99,40 @@ public function matches(array $patterns = [])
9799 return $ this ;
98100 }
99101
102+ public function matchExact ($ exact = true )
103+ {
104+ $ this ->patternMatchExact = $ exact ;
105+
106+ return $ this ;
107+ }
108+
109+ public function patternIsMatchExact ()
110+ {
111+ return $ this ->patternMatchExact ;
112+ }
113+
100114 public function getPattern ()
101115 {
102116 if (empty ($ this ->patterns )) {
103- $ this ->match (parse_url ($ this ->getUrl (), PHP_URL_PATH ));
117+ $ path = parse_url ($ this ->getUrl (), PHP_URL_PATH );
118+ $ query = parse_url ($ this ->getUrl (), PHP_URL_QUERY );
119+ $ fragment = parse_url ($ this ->getUrl (), PHP_URL_FRAGMENT );
120+
121+ $ relavtiveUrl = '' ;
122+
123+ if ($ path ) {
124+ $ relavtiveUrl = $ path ;
125+ }
126+
127+ if ($ query ) {
128+ $ relavtiveUrl .= '? ' . $ query ;
129+ }
130+
131+ if ($ fragment ) {
132+ $ relavtiveUrl .= '# ' . $ fragment ;
133+ }
134+
135+ $ this ->match ($ relavtiveUrl );
104136 }
105137
106138 return $ this ->patterns ;
Original file line number Diff line number Diff line change @@ -59,6 +59,11 @@ public function getPattern()
5959 return [];
6060 }
6161
62+ public function patternIsMatchExact ()
63+ {
64+ return false ;
65+ }
66+
6267 public function getType ()
6368 {
6469 return 'separator ' ;
Original file line number Diff line number Diff line change @@ -97,6 +97,11 @@ public function getPattern()
9797 return $ this ->nav ->getPattern ();
9898 }
9999
100+ public function patternIsMatchExact ()
101+ {
102+ return $ this ->nav ->patternIsMatchExact ();
103+ }
104+
100105 public function toArray ()
101106 {
102107 return [
You can’t perform that action at this time.
0 commit comments