Readability return boolean instead html string or Readability instance
Closed this issue · 2 comments
imannms commented
I'm using Laravel 5.7.
This is my code:
use andreskrey\Readability\Readability as PhpReadability;
use andreskrey\Readability\Configuration;
class Readability extends Controller
{
protected $readability;
public function __construct()
{
$this->readability = new PhpReadability(new Configuration());
}
public function parse($html)
{
return $this->readability->parse($html); // return boolean instead of html string or Readability instance;
}
}
imannms commented
Nevermind.
It's just my mistake.
This is my fixed code:
use andreskrey\Readability\Readability as PhpReadability;
use andreskrey\Readability\Configuration;
class Readability extends Controller
{
protected $readability;
public function __construct()
{
$this->readability = new PhpReadability(new Configuration());
}
public function parse($html)
{
$this->readability->parse($html);
return $this->readability;
}
}
andreskrey commented
Glad you figured it out yourself. Just FYI, instead of creating the Readability object in the constructor, you should pass it with dependency injection. This is better practice and it's easier to test: https://laravel.com/docs/5.7/container#introduction