Skip to content

Commit 3d3ef21

Browse files
committed
Make constructor public to allow for dependency injection. Also allow overriding of api key
1 parent a28943b commit 3d3ef21

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Diff for: src/LaravelScrapingBee.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,18 @@ final class LaravelScrapingBee
1313
protected array $params = [];
1414
protected array $headers = [];
1515

16-
public static function make(): self
16+
public static function make(?string $apiKey = null): self
1717
{
18-
return new static();
18+
return new static($apiKey);
1919
}
2020

21-
private function __construct()
21+
public function __construct(?string $apiKey = null)
2222
{
23-
$this->apiKey = config('scrapingbee.api_key');
23+
// If somebody pass '' into the constructor, we should use '' as the api key
24+
// even if it doesn't make sense.
25+
// If $apiKey is null, then we use the 1 in the config file.
26+
$this->apiKey = $apiKey ?? config('scrapingbee.api_key');
27+
2428
$this->baseUrl = config(
2529
'scrapingbee.base_url',
2630
'https://app.scrapingbee.com/api/v1/'

0 commit comments

Comments
 (0)