File tree 2 files changed +27
-0
lines changed
2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -381,6 +381,25 @@ public function removeQueryParameterByKey($key)
381
381
return $ this ;
382
382
}
383
383
384
+ /**
385
+ * @param string $key
386
+ * @return bool
387
+ */
388
+ public function hasQueryParameterWithKey ($ key )
389
+ {
390
+ if (!is_string ($ key )) {
391
+ $ argumentType = (is_object ($ key )) ? get_class ($ key ) : gettype ($ key );
392
+ throw new \InvalidArgumentException ('Expected query parameter key as string; got ' . $ argumentType );
393
+ }
394
+ $ queryParameterCount = $ this ->countQueryParameters ();
395
+ for ($ i = 0 ; $ i < $ queryParameterCount ; $ i ++) {
396
+ if ($ this ->queryParameters [$ i ]->getKey () === $ key ) {
397
+ return true ;
398
+ }
399
+ }
400
+ return false ;
401
+ }
402
+
384
403
/**
385
404
* @return $this
386
405
*/
Original file line number Diff line number Diff line change @@ -98,6 +98,13 @@ public function testInvalidArgument15()
98
98
$ url ->setFragment (array ());
99
99
}
100
100
101
+ public function testInvalidArgument16 ()
102
+ {
103
+ $ this ->setExpectedException (get_class (new \InvalidArgumentException ()));
104
+ $ url =
new Url (
'https://john:[email protected] :8443/path/to/resource ' );
105
+ $ url ->hasQueryParameterWithKey (array ());
106
+ }
107
+
101
108
public function testParser ()
102
109
{
103
110
$ url =
new Url (
'https://john:[email protected] :8443/path/to/resource ' );
@@ -108,6 +115,7 @@ public function testParser()
108
115
$ this ->assertTrue ($ url ->hasScheme ());
109
116
$ this ->assertTrue ($ url ->hasHostname ());
110
117
$ this ->assertTrue ($ url ->hasPath ());
118
+ $ this ->assertTrue ($ url ->hasQueryParameterWithKey ('arg1 ' ));
111
119
112
120
$ this ->assertEquals (2 , $ url ->countQueryParameters ());
113
121
You can’t perform that action at this time.
0 commit comments