andreskrey/readability.php

Readability return boolean instead html string or Readability instance

Closed this issue · 2 comments

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;
      }
}

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;
      }
}

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