summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndres Rey <[email protected]>2018-03-12 11:13:40 +0000
committerGitHub <[email protected]>2018-03-12 11:13:40 +0000
commit081f66134e464082de0299494e0adb4160cb536a (patch)
tree92342ccd38880c1e77f0290d36a0c0c321fbc9f7 /src
parenta2db9880e856bcc6c2f49438c55d62749ed68a3b (diff)
parent3a4988ed07047fd6bce4db077ed4152b6faf58b8 (diff)
Merge pull request #48 from topotru/configuration-constructor
Added: Configuration parameters array constructor injection
Diffstat (limited to 'src')
-rw-r--r--src/Configuration.php52
1 files changed, 47 insertions, 5 deletions
diff --git a/src/Configuration.php b/src/Configuration.php
index de3d16a..a0f363f 100644
--- a/src/Configuration.php
+++ b/src/Configuration.php
@@ -17,44 +17,91 @@ class Configuration
* @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()
@@ -286,9 +333,4 @@ class Configuration
return $this;
}
-
- /**
- * @var bool
- */
- protected $summonCthulhu = false;
}