diff --git a/module/VuFindSearch/src/VuFindSearch/ParamBag.php b/module/VuFindSearch/src/VuFindSearch/ParamBag.php index 2702c40e27e..2c53545c1b3 100644 --- a/module/VuFindSearch/src/VuFindSearch/ParamBag.php +++ b/module/VuFindSearch/src/VuFindSearch/ParamBag.php @@ -41,7 +41,7 @@ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link https://vufind.org */ -class ParamBag +class ParamBag implements \Countable { /** * Parameters @@ -238,4 +238,14 @@ function ($value) use ($name) { } return $request; } + + /** + * Get a count of parameters set in the bag. + * + * @return int + */ + public function count() + { + return count($this->params); + } } diff --git a/module/VuFindSearch/tests/unit-tests/src/VuFindTest/ParamBagTest.php b/module/VuFindSearch/tests/unit-tests/src/VuFindTest/ParamBagTest.php index 4b359057bf8..80a3b261601 100644 --- a/module/VuFindSearch/tests/unit-tests/src/VuFindTest/ParamBagTest.php +++ b/module/VuFindSearch/tests/unit-tests/src/VuFindTest/ParamBagTest.php @@ -97,4 +97,19 @@ public function testMergeWithAll() $bag3->mergeWithAll([$bag1, $bag2]); $this->assertEquals(['a' => [1], 'b' => [2], 'c' => [3]], $bag3->getArrayCopy()); } + + /** + * Test countability. + * + * @return void + */ + public function testCountability() + { + $bag = new ParamBag(); + $this->assertEquals(0, count($bag)); + $bag->set('foo', 'bar'); + $this->assertEquals(1, count($bag)); + $bag->set('xyzzy', 'baz'); + $this->assertEquals(2, count($bag)); + } }