File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed
Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -324,6 +324,11 @@ public function getQuery():string {
324324 return $ this ->query ?? "" ;
325325 }
326326
327+ public function getQueryValue (string $ key ):?string {
328+ parse_str ($ this ->getQuery (), $ queryVariables );
329+ return $ queryVariables [$ key ] ?? null ;
330+ }
331+
327332 /**
328333 * Retrieve the fragment component of the URI.
329334 *
Original file line number Diff line number Diff line change @@ -579,4 +579,11 @@ public function testImmutability() {
579579 $ this ->assertNotSame ($ uri , $ uri ->withQuery ('q=abc ' ));
580580 $ this ->assertNotSame ($ uri , $ uri ->withFragment ('test ' ));
581581 }
582- }
582+
583+ public function testGetQueryValue () {
584+ $ uri = new Uri ("example.com/test?name=cody&colour=orange " );
585+ self ::assertSame ("cody " , $ uri ->getQueryValue ("name " ));
586+ self ::assertSame ("orange " , $ uri ->getQueryValue ("colour " ));
587+ self ::assertNull ($ uri ->getQueryValue ("age " ));
588+ }
589+ }
You can’t perform that action at this time.
0 commit comments