Skip to content

Commit cf9d69f

Browse files
committed
Allow set custom search engines in the constructor
1 parent ffb3b8d commit cf9d69f

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/SearchEngines.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,16 @@ class SearchEngines
4646
*
4747
* @param string|null $current Set the current search engine name or null to
4848
* use the default
49+
* @param array<string,string> $engines Custom search engines
4950
*/
50-
public function __construct(?string $current = null)
51+
public function __construct(?string $current = null, array $engines = [])
5152
{
5253
if (isset($current)) {
5354
$this->setCurrent($current);
5455
}
56+
if ($engines) {
57+
$this->setEngines($engines);
58+
}
5559
}
5660

5761
/**

tests/SearchEnginesTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ public function testConstructor() : void
3030
{
3131
$searchEngines = new SearchEngines('bing');
3232
self::assertSame('bing', $searchEngines->getCurrent());
33+
self::assertArrayNotHasKey('foo', $searchEngines->getEngines());
34+
$searchEngines = new SearchEngines(engines: ['foo' => 'https://foo.com']);
35+
self::assertSame('google', $searchEngines->getCurrent());
36+
self::assertArrayHasKey('foo', $searchEngines->getEngines());
3337
}
3438

3539
public function testGetEngines() : void

0 commit comments

Comments
 (0)