Config.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace PicoFeed\Config;
  3. /**
  4. * Config class.
  5. *
  6. * @author Frederic Guillot
  7. *
  8. * @method \PicoFeed\Config\Config setAdditionalCurlOptions(array $options)
  9. * @method \PicoFeed\Config\Config setClientTimeout(integer $value)
  10. * @method \PicoFeed\Config\Config setClientUserAgent(string $value)
  11. * @method \PicoFeed\Config\Config setMaxRedirections(integer $value)
  12. * @method \PicoFeed\Config\Config setMaxRecursions(integer $value)
  13. * @method \PicoFeed\Config\Config setMaxBodySize(integer $value)
  14. * @method \PicoFeed\Config\Config setProxyHostname(string $value)
  15. * @method \PicoFeed\Config\Config setProxyPort(integer $value)
  16. * @method \PicoFeed\Config\Config setProxyUsername(string $value)
  17. * @method \PicoFeed\Config\Config setProxyPassword(string $value)
  18. * @method \PicoFeed\Config\Config setGrabberRulesFolder(string $value)
  19. * @method \PicoFeed\Config\Config setGrabberTimeout(integer $value)
  20. * @method \PicoFeed\Config\Config setGrabberUserAgent(string $value)
  21. * @method \PicoFeed\Config\Config setParserHashAlgo(string $value)
  22. * @method \PicoFeed\Config\Config setContentFiltering(boolean $value)
  23. * @method \PicoFeed\Config\Config setTimezone(string $value)
  24. * @method \PicoFeed\Config\Config setFilterIframeWhitelist(array $value)
  25. * @method \PicoFeed\Config\Config setFilterIntegerAttributes(array $value)
  26. * @method \PicoFeed\Config\Config setFilterAttributeOverrides(array $value)
  27. * @method \PicoFeed\Config\Config setFilterRequiredAttributes(array $value)
  28. * @method \PicoFeed\Config\Config setFilterMediaBlacklist(array $value)
  29. * @method \PicoFeed\Config\Config setFilterMediaAttributes(array $value)
  30. * @method \PicoFeed\Config\Config setFilterSchemeWhitelist(array $value)
  31. * @method \PicoFeed\Config\Config setFilterWhitelistedTags(array $value)
  32. * @method \PicoFeed\Config\Config setFilterBlacklistedTags(array $value)
  33. * @method \PicoFeed\Config\Config setFilterImageProxyUrl($value)
  34. * @method \PicoFeed\Config\Config setFilterImageProxyCallback($closure)
  35. * @method \PicoFeed\Config\Config setFilterImageProxyProtocol($value)
  36. * @method integer getClientTimeout()
  37. * @method string getClientUserAgent()
  38. * @method integer getMaxRedirections()
  39. * @method integer getMaxRecursions()
  40. * @method integer getMaxBodySize()
  41. * @method string getProxyHostname()
  42. * @method integer getProxyPort()
  43. * @method string getProxyUsername()
  44. * @method string getProxyPassword()
  45. * @method string getGrabberRulesFolder()
  46. * @method integer getGrabberTimeout()
  47. * @method string getGrabberUserAgent()
  48. * @method string getParserHashAlgo()
  49. * @method boolean getContentFiltering(bool $default_value)
  50. * @method string getTimezone()
  51. * @method array getFilterIframeWhitelist(array $default_value)
  52. * @method array getFilterIntegerAttributes(array $default_value)
  53. * @method array getFilterAttributeOverrides(array $default_value)
  54. * @method array getFilterRequiredAttributes(array $default_value)
  55. * @method array getFilterMediaBlacklist(array $default_value)
  56. * @method array getFilterMediaAttributes(array $default_value)
  57. * @method array getFilterSchemeWhitelist(array $default_value)
  58. * @method array getFilterWhitelistedTags(array $default_value)
  59. * @method array getFilterBlacklistedTags(array $default_value)
  60. * @method string getFilterImageProxyUrl()
  61. * @method \Closure getFilterImageProxyCallback()
  62. * @method string getFilterImageProxyProtocol()
  63. * @method array getAdditionalCurlOptions()
  64. */
  65. class Config
  66. {
  67. /**
  68. * Contains all parameters.
  69. *
  70. * @var array
  71. */
  72. private $container = array();
  73. /**
  74. * Magic method to have any kind of setters or getters.
  75. *
  76. * @param string $name Getter/Setter name
  77. * @param array $arguments Method arguments
  78. *
  79. * @return mixed
  80. */
  81. public function __call($name, array $arguments)
  82. {
  83. $name = strtolower($name);
  84. $prefix = substr($name, 0, 3);
  85. $parameter = substr($name, 3);
  86. if ($prefix === 'set' && isset($arguments[0])) {
  87. $this->container[$parameter] = $arguments[0];
  88. return $this;
  89. } elseif ($prefix === 'get') {
  90. $default_value = isset($arguments[0]) ? $arguments[0] : null;
  91. return isset($this->container[$parameter]) ? $this->container[$parameter] : $default_value;
  92. }
  93. return null;
  94. }
  95. }