mrjosh / laravel-phantomjs

🏏 Use phantom-js in laravel

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Type error: Return value of Josh\Component\PhantomJs\PhantomJs::getClient() must be an instance of JonnyW\PhantomJs\Client, null returned

SnakeME opened this issue · comments

After a fresh installation with Laravel 5.7 i got the following problem:

Type error: Return value of Josh\Component\PhantomJs\PhantomJs::getClient() must be an instance of JonnyW\PhantomJs\Client, null returned

Hey there thanks for the issue.

Did you use facade or just used the Josh\Component\PhantomJs\PhantomJs object ?

let me know how did you used your code. Thanks

commented

I have the same isssue.

this is my code

$request = \PhantomJs::get('http://phantomjs.org/'); $response = \PhantomJs::send($request); if($response->getStatus() === 200) { echo $response->getContent(); }

commented

Exception trace:

1 Josh\Component\PhantomJs\PhantomJs::getClient()
/site/vendor/josh/laravel-phantomjs/src/PhantomJs.php:302

2 Josh\Component\PhantomJs\PhantomJs::send(Object(JonnyW\PhantomJs\Http\Request))
/site/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:223

3 Illuminate\Support\Facades\Facade::__callStatic("send")
/site/app/Console/Commands/HouseStartCommand.php:23

commented

I try to run setClient myself, it works.

\PhantomJs::setClient(); $request = \PhantomJs::get('http://m.ctrip.com/webapp/Hotel/HotelDetail/473770.html?oversea=&hotelid=473770'); $response = \PhantomJs::send($request); if($response->getStatus() === 200) { echo $response->getContent(); }

Yeah i got the issue.
the setClient method must called in constructor.
i'll fix it asap or you can just send me pull request for this if you want.

Hey! Hope this small fix will help closing this issue. Also, I noticed you have an outdated phpdoc in src/Facade/PhantomJs.php. Even though it doesn't affect the runtime, it would be really nice to have a valid code snippets for those folks who use IDEs.

As my pull request has been accepted, I think this issue can be closed for now.