Closed AliHassan13 closed 4 years ago
duplicate #342
Use $ composer require laminas/laminas-diactoros
and works.
Also, I found slim/http
and guzzle/psr7
that doesn't work, I'll check it later.
I think I figure out what happened to this problem, you need to implement factories by yourself.
For example, you wanna use guzlehttp/psr7
, for you, entry code likes:
// Implementing by yourself.
$client = new CurlClient(new ResponseFactory());
$request = new RequestFactory();
$uri = new UriFactory();
$crawler = new Crawler($client, $request, $uri);
$embed = new Embed($crawler);
$info = $embed->get('https://google.com');
Next, you need to step by step to implement what you need Factories.
use GuzzleHttp\Psr7\Request;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\RequestInterface;
class RequestFactory implements RequestFactoryInterface
{
public function createRequest(string $method, $uri): RequestInterface
{
return new Request($method, $uri);
}
}
use GuzzleHttp\Psr7\Response;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
class ResponseFactory implements ResponseFactoryInterface
{
public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface
{
return (new Response())
->withStatus($code, $reasonPhrase);
}
}
use GuzzleHttp\Psr7\Uri;
use Psr\Http\Message\UriFactoryInterface;
use Psr\Http\Message\UriInterface;
class UriFactory implements UriFactoryInterface
{
public function createUri(string $uri = ''): UriInterface
{
return new Uri($uri);
}
}
And then it should work, I suggest the documentation changing description:
Embed comes with a CURL client compatible with PSR-18 but you need to install a PSR-7 / PSR-17 library. Here you can see a list of popular libraries and the library can detect automatically 'laminas\diactoros', 'guzzleHttp\psr7', 'slim\psr7', 'nyholm\psr7' and 'sunrise\http' (in this order). If you want to use a different PSR implementation, you can do it in this way:
Embed\Http\FactoryDiscovery.php
detect automatically should be changing, Excepting Laminas\Diactoros
have implemented these factories, others no.
Thanks a lot.. i just install $ composer require laminas/laminas-diactoros
and its work.
@Mombuyish guzzle/psr7
works with the version 2.x (not stable yet). Version 1.x does not include factories.
A workaround is using one of the http-factories provided here: https://github.com/http-interop
i'm just install this with
composer require embed/embed
use it in my controlleruse Embed\Embed
this is my test function just for demoi got this error and i don't know how i fix it.