laminas / laminas-feed

Consume and generate Atom and RSS feeds, and interact with Pubsubhubbub.

Home Page:https://docs.laminas.dev/laminas-feed/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Class 'Laminas\Http\Client' not found

benjaminkohl opened this issue · comments

Bug Report

I tried to run Reader::import($url) and there appears to be an issue locating a class from within that class.

Q A
Version(s) 2.12.0

Summary

Here is the stack trace. I swapped out the true paths, class names and the URL to protect our client's privacy.

Exception 'Error' with message 'Class 'Laminas\Http\Client' not found'

in /path/to/site/vendor/laminas/laminas-feed/src/Reader/Reader.php:143

Stack trace:
#0 /path/to/site/vendor/laminas/laminas-feed/src/Reader/Reader.php(200): Laminas\Feed\Reader\Reader::getHttpClient()
#1 /path/to/site/modules/clientname/services/Feed.php(64): Laminas\Feed\Reader\Reader::import('https://example.com...')
#2 /path/to/site/modules/clientname/controllers/console/FeedController.php(33): modules\clientname\services\Feed->importPressReleases()
...

Current behavior

See the stack trace.

How to reproduce

I placed the following at the top of my class:

use Laminas\Feed\Reader\Reader;

In a function, I am calling import like:

$feed = Reader::import($url);

That line with "import" is #1 in the stack trace.

Expected behavior

No exception? Feed is parsed and stored in the $feed variable.

Disregard. I found my answer after the basic usage code block in the docs. So I installed the laminas/laminas-http package and that works.

@benjaminkohl
If you want to import a feed via a URI, you need an HTTP client. Other options for an import are a string and a file therefore the HTTP client is only a soft dependency.
You must install an HTTP client yourself.

Please see also in documentation for this notice:

Importing requires an HTTP client

To import a feed, you will need to have an HTTP client available.

https://docs.laminas.dev/laminas-feed/reader/#importing-feeds

The "suggest" section in the Composer file also contains this note:

"laminas/laminas-http": "Laminas\\Http for PubSubHubbub, and optionally for use with Laminas\\Feed\\Reader",

But thanks anyway, because your request helps us to rethink the error message and provide better help.

Yes, thank you. I probably wouldn't have run into this if that block about the HTTP client appeared above the basic usage code in the documentation.

Good point! 👍

Currently I'm working on a description to include laminas-feed in laminas-mvc application. After this I planned a restructuring of the entire component documentation which included a smaller and clearer quick start.