-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No PSR-18 clients found. Make sure to install a package providing "psr/http-client-implementation". Example: "php-http/guzzle6-adapter". #4
Comments
I create a new issue for it: #5
The library don't come with any PSR-18 implementation.
Here a working example of a Provider Configuration: https://github.com/MacFJA/livres/blob/master/src/Repository/ProviderConfigurationRepository.php But if the provider(s) you want to use have no particular configuration, you can simply write this: $providerConfiguration = new class implements \MacFJA\BookRetriever\ProviderConfigurationInterface {
public function getParameters(\MacFJA\BookRetriever\ProviderInterface $provider): array
{
return [];
}
public function isActive(\MacFJA\BookRetriever\ProviderInterface $provider): bool
{
return true;
}
}; The I hope that answer your question, If not don't hesitate to ask more details |
Thanks for your answer There is already the "guzzlehttp/guzzle" package when launches the composer require statement:
I tested a lot of package without success (guzzlehttp/guzzle + guzzle/guzzle6-adapter ...), now I have no more error with this composer.json: {
"require": {
"macfja/book-retriever": "^1.1",
"symfony/http-client": "^5.4",
"php-http/httplug": "^2.3",
"nyholm/psr7": "^1.5",
"symfony/var-dumper": "^5.4"
}
} Can you test in a new project your library, just the simple example please (provider AntoineOnline) ? I don't get any results with isbn: 9782253006329 $htmlGetter = new \MacFJA\BookRetriever\Helper\HtmlGetter();
$isbnTool = new \Isbn\Isbn();
$antoineOnline = new \MacFJA\BookRetriever\Provider\AntoineOnline($htmlGetter, $isbnTool);
$books = $antoineOnline->searchIsbn('9782253006329');
In your AntoinOnline.php file,
$location = $response->getHeader('location'); returns an empty array There's no key location in headers: However I noticed that there is a location key in response_headers through the library:
I don't know how to retrieve the 'location' from the stream. the second problem is that if we have a 200 response, you return an empty array (in AntoineOnline.php) if ($response->getStatusCode() < 300 || $response->getStatusCode() > 399) {
return [];
} Finally, if I don't take location into account for testing purposes, I get a result in SearchBuilder:
Here is the modified AmazonOnline.php file to override location and comment out the getStatusCode: public function searchIsbn(string $isbn): array
{
$isbn = $this->isbnTool->hyphens->removeHyphens($isbn);
// dump($isbn);
$client = $this->getHttpClient();
// dump($client);
$requestBody = sprintf(static::WEBPAGE_SEARCH_PATTERN, urlencode($isbn));
dump("$requestBody:", $requestBody);
$request = $this->createHttpRequest('POST', $requestBody)
->withAddedHeader('content-length', (string) strlen($requestBody));
dump($request);
$response = $client->sendRequest($request);
// location est dans response
dump('response:',$response);
// dump('getBody',$response->getBody()->getContents());
// echo ($response->getBody()->getContents());
dump($response->getStatusCode());
// if ($response->getStatusCode() < 300 || $response->getStatusCode() > 399) {
// return [];
// }
$url = "https://www.antoineonline.com/Livre_Vingt_Mille_Lieues_Sous_Les_Mers_Jules_Verne_9782253006329.aspx?productCode=0009782253006329";
// new NativeResponse($url,null,'',[],null,null,null,null);
// ATTENTION: à ce stade on ne RECCUPERE RIEN de getHeader('location)
$location = $response->getHeader('location');
$headers=$response->getHeaders();
dump('headers:', $headers);
dump('location:',$location);
// new StreamWrapper();
$location = reset($location);
// $xml = $this->getHtmlGetter()->getWebpageAsDom(static::WEBPAGE_BASE_URL.$location);
$xml = $this->getHtmlGetter()->getWebpageAsDom($url);
// dump('xml:',$xml);
$allMeta = $xml->getElementsByTagName('meta');
dump('allMeta:',$allMeta);
$resultDiv = $xml->getElementById('ctl00_cph1_ProductMainPage');
// $resultDiv = $xml->getElementById('ctl00_cph1_RandomNumbers');
dump('resultDiv:',$resultDiv);
if (null === $resultDiv) {
return [];
}
$allInput = $resultDiv->getElementsByTagName('input');
dump('allInput:',$allInput);
$result = ['antoineonline_link' => static::WEBPAGE_BASE_URL.$location, 'isbn' => $isbn];
$result = $this->handleNode($result, $allMeta, [$this, 'metaNodeVisitor']);
$result = $this->handleNode($result, $allInput, [$this, 'inputNodeVisitor']);
dump('searchResultBuilder:',[SearchResultBuilder::createFromArray($result)]);
return [SearchResultBuilder::createFromArray($result)];
} For the amazon provider, I think the constant: I would like to test another provider but for the moment only AntoineOnline displays a result. I would like to have examples that work with other providers, please, because I don't know what parameters to put when they are necessary |
also when i test with $provider Configuration it doesn't work: $providerConfiguration = new class implements \MacFJA\BookRetriever\ProviderConfigurationInterface {
public function getParameters(\MacFJA\BookRetriever\ProviderInterface $provider): array
{
return [];
}
public function isActive(\MacFJA\BookRetriever\ProviderInterface $provider): bool
{
return true;
}
};
$configurator = new \MacFJA\BookRetriever\ProviderConfigurator($providerConfiguration,null,null,null);
$htmlGetter = new \MacFJA\BookRetriever\Helper\HtmlGetter();
$isbn = new \Isbn\Isbn();
$opds = new \MacFJA\BookRetriever\Helper\OPDSParser();
$sru = new \MacFJA\BookRetriever\Helper\SRUParser();
$providers = [
// new \MacFJA\BookRetriever\Provider\AbeBooks($htmlGetter),
// new \MacFJA\BookRetriever\Provider\Amazon(),
new \MacFJA\BookRetriever\Provider\AntoineOnline($htmlGetter, $isbn),
// new \MacFJA\BookRetriever\Provider\ArchiveOrg($opds),
// new \MacFJA\BookRetriever\Provider\LibraryHub($sru),
// new \MacFJA\BookRetriever\Provider\DigitEyes(),
// new \MacFJA\BookRetriever\Provider\Ebay()
];
array_walk($providers, [$configurator, 'configure']);
$pool = new \MacFJA\BookRetriever\Pool($providers, $providerConfiguration);
$books = $pool->searchIsbn('9782253006329'); I get this error: <html><body>
<!--StartFragment--><font size="1">
( ! ) Warning: assert(): assert($providers instanceof Traversable) failed in C:\XAMPP\htdocs\blog\Book-Retriever\vendor\macfja\book-retriever\lib\Pool.php on line 109
--
1 | 0.0006 | 356584 | {main}( ) | ...\index.php:0
2 | 3.4582 | 731160 | MacFJA\BookRetriever\Pool->searchIsbn( $isbn = '9782253006329' ) | ...\index.php:58
3 | 3.4582 | 731160 | MacFJA\BookRetriever\Pool->getActiveProviders( ) | ...\Pool.php:71
4 | 3.4582 | 731160 | assert( $assertion = FALSE, $description = 'assert($providers instanceof Traversable)' ) | ...\Pool.php:109
</font><!--EndFragment-->
</body>
</html>( ! ) Warning: [assert](http://www.php.net/function.assert)(): assert($providers instanceof Traversable) failed in C:\XAMPP\htdocs\blog\Book-Retriever\vendor\macfja\book-retriever\lib\Pool.php on line 109
Call Stack
# Time Memory Function Location
1 0.0006 356584 {main}( ) ...\index.php:0
2 3.4582 731160 MacFJA\BookRetriever\Pool->searchIsbn( $isbn = '9782253006329' ) ...\index.php:58
3 3.4582 731160 MacFJA\BookRetriever\Pool->getActiveProviders( ) ...\Pool.php:71
4 3.4582 731160 assert( $assertion = FALSE, $description = 'assert($providers instanceof Traversable)' ) ...\Pool.php:109
( ! ) Fatal error: Uncaught TypeError: Argument 1 passed to IteratorIterator::__construct() must implement interface Traversable, array given in C:\XAMPP\htdocs\blog\Book-Retriever\vendor\macfja\book-retriever\lib\Pool.php on line 111
( ! ) TypeError: Argument 1 passed to IteratorIterator::__construct() must implement interface Traversable, array given in C:\XAMPP\htdocs\blog\Book-Retriever\vendor\macfja\book-retriever\lib\Pool.php on line 111
Call Stack
# Time Memory Function Location
1 0.0006 356584 {main}( ) ...\index.php:0
2 3.4582 731160 MacFJA\BookRetriever\Pool->searchIsbn( $isbn = '9782253006329' ) ...\index.php:58
3 3.4582 731160 MacFJA\BookRetriever\Pool->getActiveProviders( ) ...\Pool.php:71 |
I didn't updated the library for almost 2 years, so it's highly probable that some provider have changed their API or about data are displayed on their website.
I will update the Providers.md file to add more details about the required parameter of the providers that need them.
For some example you can look at the Tests/Unit directory. But I will create a full working example (other that https://github.com/MacFJA/livres) |
Hello,
I got a psr-18 error when I test your example:
No PSR-18 clients found. Make sure to install a package providing "psr/http-client-implementation". Example: "php-http/guzzle6-adapter".
I'm testing your library outside the symfony framework, just in a pure php project
Also, can you please show a complete working example. I don't know what to put in
$providerConfiguration = ...;
either in Configurable provider or Multiple providers.Finally, can you please add the Eni provider (https://www.editions-eni.fr/)?
I can't wait to test all these features which seem very complete and powerful to me!
Thanks for your help
my composer.json:
The text was updated successfully, but these errors were encountered: