Skip to content

Commit 4f67f21

Browse files
committed
Allow to pass options to info providers
1 parent cf34de6 commit 4f67f21

17 files changed

Lines changed: 55 additions & 46 deletions

src/Services/InfoProviderSystem/Providers/AIInfoExtractor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function isActive(): bool
8686
return $this->settings->platform !== null && $this->settings->model !== null && $this->settings->model !== '';
8787
}
8888

89-
public function searchByKeyword(string $keyword): array
89+
public function searchByKeyword(string $keyword, array $options = []): array
9090
{
9191
try {
9292
return [
@@ -96,7 +96,7 @@ public function searchByKeyword(string $keyword): array
9696
}
9797
}
9898

99-
public function getDetails(string $id): PartDetailDTO
99+
public function getDetails(string $id, array $options = []): PartDetailDTO
100100
{
101101
$url = $this->fixAndValidateURL($id);
102102

src/Services/InfoProviderSystem/Providers/BatchInfoProviderInterface.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ interface BatchInfoProviderInterface extends InfoProviderInterface
3434
* Search for multiple keywords in a single batch operation and return the results, ordered by the keywords.
3535
* This allows for a more efficient search compared to running multiple single searches.
3636
* @param string[] $keywords
37+
* @param array<string, mixed> $options An associative array of options which can be used to modify the search behavior. The supported options depend on the provider and should be documented in the provider's documentation.
3738
* @return array<string, SearchResultDTO[]> An associative array where the key is the keyword and the value is the search results for that keyword
3839
*/
39-
public function searchByKeywordsBatch(array $keywords): array;
40+
public function searchByKeywordsBatch(array $keywords, array $options = []): array;
4041
}

src/Services/InfoProviderSystem/Providers/BuerklinProvider.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -461,9 +461,11 @@ private function attributesToParameters(array $features, ?string $group = null):
461461
}
462462

463463
/**
464+
* @param string $keyword
465+
* @param array $options
464466
* @return PartDetailDTO[]
465467
*/
466-
public function searchByKeyword(string $keyword): array
468+
public function searchByKeyword(string $keyword, array $options = []): array
467469
{
468470
$keyword = strtoupper(trim($keyword));
469471
if ($keyword === '') {
@@ -493,7 +495,7 @@ public function searchByKeyword(string $keyword): array
493495
}
494496
}
495497

496-
public function getDetails(string $id): PartDetailDTO
498+
public function getDetails(string $id, array $options = []): PartDetailDTO
497499
{
498500
// Detail endpoint is /products/{code}/
499501
$response = $this->getProduct($id);
@@ -588,10 +590,11 @@ private function complianceToParameters(array $product, ?string $group = 'Compli
588590
}
589591

590592
/**
591-
* @param string[] $keywords
593+
* @param array $keywords
594+
* @param array $options
592595
* @return array<string, SearchResultDTO[]>
593596
*/
594-
public function searchByKeywordsBatch(array $keywords): array
597+
public function searchByKeywordsBatch(array $keywords, array $options = []): array
595598
{
596599
/** @var array<string, SearchResultDTO[]> $results */
597600
$results = [];
@@ -643,27 +646,27 @@ public function getHandledDomains(): array
643646

644647
public function getIDFromURL(string $url): ?string
645648
{
646-
//Inputs:
647-
//https://www.buerklin.com/de/p/bkl-electronic/niedervoltsteckverbinder/072341-l/40F1332/
649+
//Inputs:
650+
//https://www.buerklin.com/de/p/bkl-electronic/niedervoltsteckverbinder/072341-l/40F1332/
648651
//https://www.buerklin.com/de/p/40F1332/
649652
//https://www.buerklin.com/en/p/bkl-electronic/dc-connectors/072341-l/40F1332/
650653
//https://www.buerklin.com/en/p/40F1332/
651654
//The ID is the last part after the manufacturer/category/mpn segment and before the final slash
652655
//https://www.buerklin.com/de/p/bkl-electronic/niedervoltsteckverbinder/072341-l/40F1332/#download should also work
653-
656+
654657
$path = parse_url($url, PHP_URL_PATH);
655-
658+
656659
if (!$path) {
657660
return null;
658661
}
659-
662+
660663
// Ensure it's actually a product URL
661664
if (strpos($path, '/p/') === false) {
662665
return null;
663666
}
664-
667+
665668
$id = basename(rtrim($path, '/'));
666-
669+
667670
return $id !== '' && $id !== 'p' ? $id : null;
668671
}
669672

src/Services/InfoProviderSystem/Providers/CanopyProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ private function getFromCache(string $id): ?PartDetailDTO
111111
return null;
112112
}
113113

114-
public function searchByKeyword(string $keyword): array
114+
public function searchByKeyword(string $keyword, array $options = []): array
115115
{
116116
$response = $this->httpClient->request('GET', self::SEARCH_API_URL, [
117117
'query' => [
@@ -177,7 +177,7 @@ private function priceToPurchaseInfo(?array $price, string $asin): PurchaseInfoD
177177
return new PurchaseInfoDTO(self::DISTRIBUTOR_NAME, order_number: $asin, prices: $priceDtos, product_url: $this->productPageFromASIN($asin));
178178
}
179179

180-
public function getDetails(string $id): PartDetailDTO
180+
public function getDetails(string $id, array $options = []): PartDetailDTO
181181
{
182182
//Check that the id is a valid ASIN (10 characters, letters and numbers)
183183
if (!preg_match('/^[A-Z0-9]{10}$/', $id)) {

src/Services/InfoProviderSystem/Providers/ConradProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ private function getFootprintFromTechnicalDetails(array $technicalDetails): ?str
8888
return null;
8989
}
9090

91-
public function searchByKeyword(string $keyword): array
91+
public function searchByKeyword(string $keyword, array $options = []): array
9292
{
9393
$url = $this->settings->shopID->getAPIRoot() . self::SEARCH_ENDPOINT . '/'
9494
. $this->settings->shopID->getDomainEnd() . '/' . $this->settings->shopID->getLanguage()
@@ -279,7 +279,7 @@ private function queryPrices(string $productId): PurchaseInfoDTO
279279
);
280280
}
281281

282-
public function getDetails(string $id): PartDetailDTO
282+
public function getDetails(string $id, array $options = []): PartDetailDTO
283283
{
284284
$productInfoURL = $this->settings->shopID->getAPIRoot() . '/product/1/service/' . $this->settings->shopID->getShopID()
285285
. '/product/' . $id;

src/Services/InfoProviderSystem/Providers/DigikeyProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function isActive(): bool
106106
return $this->settings->clientId !== null && $this->settings->clientId !== '' && $this->authTokenManager->hasToken(self::OAUTH_APP_NAME);
107107
}
108108

109-
public function searchByKeyword(string $keyword): array
109+
public function searchByKeyword(string $keyword, array $options = []): array
110110
{
111111
$request = [
112112
'Keywords' => $keyword,
@@ -159,7 +159,7 @@ public function searchByKeyword(string $keyword): array
159159
return $result;
160160
}
161161

162-
public function getDetails(string $id): PartDetailDTO
162+
public function getDetails(string $id, array $options = []): PartDetailDTO
163163
{
164164
try {
165165
$response = $this->digikeyClient->request('GET', '/products/v4/search/' . urlencode($id) . '/productdetails', [

src/Services/InfoProviderSystem/Providers/Element14Provider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,12 @@ private function releaseStatusCodeToManufacturingStatus(?int $releaseStatusCode)
282282
};
283283
}
284284

285-
public function searchByKeyword(string $keyword): array
285+
public function searchByKeyword(string $keyword, array $options = []): array
286286
{
287287
return $this->queryByTerm('any:' . $keyword);
288288
}
289289

290-
public function getDetails(string $id): PartDetailDTO
290+
public function getDetails(string $id, array $options = []): PartDetailDTO
291291
{
292292
$tmp = $this->queryByTerm('id:' . $id);
293293
if (count($tmp) === 0) {

src/Services/InfoProviderSystem/Providers/EmptyProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function isActive(): bool
5454
return true;
5555
}
5656

57-
public function searchByKeyword(string $keyword): array
57+
public function searchByKeyword(string $keyword, array $options = []): array
5858
{
5959
return [
6060

@@ -69,7 +69,7 @@ public function getCapabilities(): array
6969
];
7070
}
7171

72-
public function getDetails(string $id): PartDetailDTO
72+
public function getDetails(string $id, array $options = []): PartDetailDTO
7373
{
7474
throw new \RuntimeException('No part details available');
7575
}

src/Services/InfoProviderSystem/Providers/GenericWebProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function isActive(): bool
8787
return $this->settings->enabled;
8888
}
8989

90-
public function searchByKeyword(string $keyword): array
90+
public function searchByKeyword(string $keyword, array $options = []): array
9191
{
9292
$url = $this->fixAndValidateURL($keyword);
9393

src/Services/InfoProviderSystem/Providers/InfoProviderInterface.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,18 @@ public function isActive(): bool;
6161
/**
6262
* Searches for a keyword and returns a list of search results
6363
* @param string $keyword The keyword to search for
64+
* @param array $options An associative array of options for the search, which can be used to pass additional parameters to the provider (e.g. filters, pagination, etc.). The content of this array is provider specific and not defined by the interface
6465
* @return SearchResultDTO[] A list of search results
6566
*/
66-
public function searchByKeyword(string $keyword): array;
67+
public function searchByKeyword(string $keyword, array $options = []): array;
6768

6869
/**
6970
* Returns detailed information about the part with the given id
7071
* @param string $id
72+
* @param array $options An associative array of options for the search, which can be used to pass additional parameters to the provider (e.g. filters, pagination, etc.). The content of this array is provider specific and not defined by the interface
7173
* @return PartDetailDTO
7274
*/
73-
public function getDetails(string $id): PartDetailDTO;
75+
public function getDetails(string $id, array $options = []): PartDetailDTO;
7476

7577
/**
7678
* A list of capabilities this provider supports (which kind of data it can provide).

0 commit comments

Comments
 (0)