diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-04-02 11:09:33 +0200 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-04-02 11:09:33 +0200 |
commit | 3350ed7cafa93873a6c0520e2bf0d9c05219adae (patch) | |
tree | b9ae909ad68e6595285159a906eb3102f7c8739b /utility | |
parent | 45d81beb6cc66e720e2983fc29d1a0a82d8bf9c1 (diff) |
added pluggable fetchers
Diffstat (limited to 'utility')
-rw-r--r-- | utility/feedfetcher.php | 10 | ||||
-rw-r--r-- | utility/fetcher.php | 52 | ||||
-rw-r--r-- | utility/ifeedfetcher.php | 31 |
3 files changed, 92 insertions, 1 deletions
diff --git a/utility/feedfetcher.php b/utility/feedfetcher.php index 9bfe1ed31..bf8cbd35b 100644 --- a/utility/feedfetcher.php +++ b/utility/feedfetcher.php @@ -31,7 +31,7 @@ use \OCA\News\Db\Item; use \OCA\News\Db\Feed; -class FeedFetcher { +class FeedFetcher implements IFeedFetcher { private $api; @@ -40,6 +40,14 @@ class FeedFetcher { } + public function canHandle($url){ + + // This fetcher handles all the remaining urls therefore + // return true + return true; + } + + /** * Fetch a feed from remote * @param string url remote url of the feed diff --git a/utility/fetcher.php b/utility/fetcher.php new file mode 100644 index 000000000..c834de5e4 --- /dev/null +++ b/utility/fetcher.php @@ -0,0 +1,52 @@ +<?php + +/** +* ownCloud - News +* +* @author Alessandro Cosentino +* @author Bernhard Posselt +* @copyright 2012 Alessandro Cosentino cosenal@gmail.com +* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +* License as published by the Free Software Foundation; either +* version 3 of the License, or any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU AFFERO GENERAL PUBLIC LICENSE for more details. +* +* You should have received a copy of the GNU Affero General Public +* License along with this library. If not, see <http://www.gnu.org/licenses/>. +* +*/ + +namespace OCA\News\Utility; + + +class Fetcher { + + private $fetchers; + + public function __construct(){ + $this->fetchers = array(); + } + + + public function registerFetcher(IFeedFetcher $fetcher){ + array_push($this->fetchers, $fetcher); + } + + + public function fetch($url){ + foreach($this->fetchers as $fetcher){ + if($fetcher->canHandle($url)){ + return $fetcher->fetch($url); + } + } + } + + +}
\ No newline at end of file diff --git a/utility/ifeedfetcher.php b/utility/ifeedfetcher.php new file mode 100644 index 000000000..0e3ed8732 --- /dev/null +++ b/utility/ifeedfetcher.php @@ -0,0 +1,31 @@ +<?php + +/** +* ownCloud - News +* +* @author Alessandro Cosentino +* @author Bernhard Posselt +* @copyright 2012 Alessandro Cosentino cosenal@gmail.com +* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +* License as published by the Free Software Foundation; either +* version 3 of the License, or any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU AFFERO GENERAL PUBLIC LICENSE for more details. +* +* You should have received a copy of the GNU Affero General Public +* License along with this library. If not, see <http://www.gnu.org/licenses/>. +* +*/ + +namespace OCA\News\Utility; + +interface IFeedFetcher { + function fetch($url); + function canHandle($url); +}
\ No newline at end of file |