You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

60 lines
1.5 KiB

  1. <?php
  2. namespace App\Service;
  3. /*
  4. * Copyright (C) 2020 Daniel Siepmann <coding@daniel-siepmann.de>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19. * 02110-1301, USA.
  20. */
  21. use SimplePie;
  22. class FeedParserFactory
  23. {
  24. /**
  25. * @var int
  26. */
  27. private $cacheDuration;
  28. /**
  29. * @var string
  30. */
  31. private $cacheLocation;
  32. public function __construct(
  33. int $cacheDuration,
  34. string $cacheLocation
  35. ) {
  36. $this->cacheDuration = $cacheDuration;
  37. $this->cacheLocation = $cacheLocation;
  38. }
  39. public function getParser(): SimplePie
  40. {
  41. $parser = new SimplePie();
  42. $parser->set_cache_duration($this->cacheDuration);
  43. $parser->set_cache_location($this->cacheLocation);
  44. if (is_dir($this->cacheLocation) === false) {
  45. mkdir($this->cacheLocation);
  46. }
  47. return $parser;
  48. }
  49. }