123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348 |
- <?php
- namespace andreskrey\Readability;
- use Psr\Log\LoggerAwareTrait;
- use Psr\Log\LoggerInterface;
- use Psr\Log\NullLogger;
- /**
- * Class Configuration.
- */
- class Configuration
- {
- use LoggerAwareTrait;
- /**
- * @var int
- */
- protected $maxTopCandidates = 5;
- /**
- * @var int
- */
- protected $wordThreshold = 500;
- /**
- * @var bool
- */
- protected $articleByLine = false;
- /**
- * @var bool
- */
- protected $stripUnlikelyCandidates = true;
- /**
- * @var bool
- */
- protected $cleanConditionally = true;
- /**
- * @var bool
- */
- protected $weightClasses = true;
- /**
- * @var bool
- */
- protected $fixRelativeURLs = false;
- /**
- * @var bool
- */
- protected $substituteEntities = false;
- /**
- * @var bool
- */
- protected $normalizeEntities = false;
- /**
- * @var bool
- */
- protected $summonCthulhu = false;
- /**
- * @var string
- */
- protected $originalURL = 'http://fakehost';
- /**
- * Configuration constructor.
- *
- * @param array $params
- */
- public function __construct(array $params = [])
- {
- foreach ($params as $key => $value) {
- $setter = sprintf('set%s', $key);
- if (method_exists($this, $setter)) {
- call_user_func([$this, $setter], $value);
- }
- }
- }
- /**
- * Returns an array-representation of configuration.
- *
- * @return array
- */
- public function toArray()
- {
- $out = [];
- foreach ($this as $key => $value) {
- $getter = sprintf('get%s', $key);
- if (!is_object($value) && method_exists($this, $getter)) {
- $out[$key] = call_user_func([$this, $getter]);
- }
- }
- return $out;
- }
- /**
- * @return LoggerInterface
- */
- public function getLogger()
- {
- // If no logger has been set, just return a null logger
- if ($this->logger === null) {
- return new NullLogger();
- } else {
- return $this->logger;
- }
- }
- /**
- * @param LoggerInterface $logger
- *
- * @return Configuration
- */
- public function setLogger(LoggerInterface $logger)
- {
- $this->logger = $logger;
- return $this;
- }
- /**
- * @return int
- */
- public function getMaxTopCandidates()
- {
- return $this->maxTopCandidates;
- }
- /**
- * @param int $maxTopCandidates
- *
- * @return $this
- */
- public function setMaxTopCandidates($maxTopCandidates)
- {
- $this->maxTopCandidates = $maxTopCandidates;
- return $this;
- }
- /**
- * @return int
- */
- public function getWordThreshold()
- {
- return $this->wordThreshold;
- }
- /**
- * @param int $wordThreshold
- *
- * @return $this
- */
- public function setWordThreshold($wordThreshold)
- {
- $this->wordThreshold = $wordThreshold;
- return $this;
- }
- /**
- * @return bool
- */
- public function getArticleByLine()
- {
- return $this->articleByLine;
- }
- /**
- * @param bool $articleByLine
- *
- * @return $this
- */
- public function setArticleByLine($articleByLine)
- {
- $this->articleByLine = $articleByLine;
- return $this;
- }
- /**
- * @return bool
- */
- public function getStripUnlikelyCandidates()
- {
- return $this->stripUnlikelyCandidates;
- }
- /**
- * @param bool $stripUnlikelyCandidates
- *
- * @return $this
- */
- public function setStripUnlikelyCandidates($stripUnlikelyCandidates)
- {
- $this->stripUnlikelyCandidates = $stripUnlikelyCandidates;
- return $this;
- }
- /**
- * @return bool
- */
- public function getCleanConditionally()
- {
- return $this->cleanConditionally;
- }
- /**
- * @param bool $cleanConditionally
- *
- * @return $this
- */
- public function setCleanConditionally($cleanConditionally)
- {
- $this->cleanConditionally = $cleanConditionally;
- return $this;
- }
- /**
- * @return bool
- */
- public function getWeightClasses()
- {
- return $this->weightClasses;
- }
- /**
- * @param bool $weightClasses
- *
- * @return $this
- */
- public function setWeightClasses($weightClasses)
- {
- $this->weightClasses = $weightClasses;
- return $this;
- }
- /**
- * @return bool
- */
- public function getFixRelativeURLs()
- {
- return $this->fixRelativeURLs;
- }
- /**
- * @param bool $fixRelativeURLs
- *
- * @return $this
- */
- public function setFixRelativeURLs($fixRelativeURLs)
- {
- $this->fixRelativeURLs = $fixRelativeURLs;
- return $this;
- }
- /**
- * @return bool
- */
- public function getSubstituteEntities()
- {
- return $this->substituteEntities;
- }
- /**
- * @param bool $substituteEntities
- *
- * @return $this
- */
- public function setSubstituteEntities($substituteEntities)
- {
- $this->substituteEntities = $substituteEntities;
- return $this;
- }
- /**
- * @return bool
- */
- public function getNormalizeEntities()
- {
- return $this->normalizeEntities;
- }
- /**
- * @param bool $normalizeEntities
- *
- * @return $this
- */
- public function setNormalizeEntities($normalizeEntities)
- {
- $this->normalizeEntities = $normalizeEntities;
- return $this;
- }
- /**
- * @return string
- */
- public function getOriginalURL()
- {
- return $this->originalURL;
- }
- /**
- * @param string $originalURL
- *
- * @return $this
- */
- public function setOriginalURL($originalURL)
- {
- $this->originalURL = $originalURL;
- return $this;
- }
- /**
- * @return bool
- */
- public function getSummonCthulhu()
- {
- return $this->summonCthulhu;
- }
- /**
- * @param bool $summonCthulhu
- *
- * @return $this
- */
- public function setSummonCthulhu($summonCthulhu)
- {
- $this->summonCthulhu = $summonCthulhu;
- return $this;
- }
- }
|