22
33namespace Sprain \NewsParser \Parser \Platforms ;
44
5+ use Sprain \NewsParser \Cache \Cache ;
6+
57abstract class PlatformParser
68{
9+ protected $ cache ;
10+ protected $ rootUrl ;
11+
12+ abstract function doGetMostReadArticles ($ limit = null );
13+
14+ abstract function doGetRecommendedArticles ($ limit = null );
15+
16+ abstract function doGetMostCommentedArticles ($ limit = null );
17+
18+ public function getMostReadArticles ($ limit = null )
19+ {
20+ $ cacheId = get_called_class ().': ' .__METHOD__ ;
21+
22+ if (!$ articles = $ this ->getCache ()->fetch ($ cacheId )) {
23+ $ articles = $ this ->doGetMostReadArticles ($ limit );
24+ $ this ->getCache ()->save ($ cacheId , $ articles );
25+ }
26+
27+ return $ articles ;
28+ }
29+
30+ public function getRecommendedArticles ($ limit = null )
31+ {
32+ $ cacheId = get_called_class ().': ' .__METHOD__ ;
33+
34+ if (!$ articles = $ this ->getCache ()->fetch ($ cacheId )) {
35+ $ articles = $ this ->doGetRecommendedArticles ($ limit );
36+ $ this ->getCache ()->save ($ cacheId , $ articles );
37+ }
38+
39+ return $ articles ;
40+ }
41+
42+ public function getMostCommentedArticles ($ limit = null )
43+ {
44+ $ cacheId = get_called_class ().': ' .__METHOD__ ;
45+
46+ if (!$ articles = $ this ->getCache ()->fetch ($ cacheId )) {
47+ $ articles = $ this ->doGetMostCommentedArticles ($ limit );
48+ $ this ->getCache ()->save ($ cacheId , $ articles );
49+ }
50+
51+ return $ articles ;
52+ }
53+
54+ public function getIconUrl ()
55+ {
56+ return 'http://www.google.com/s2/favicons?domain= ' . $ this ->getRootUrl ();
57+ }
58+
759 public function getRootUrl ()
860 {
961 return $ this ->rootUrl ;
1062 }
63+
64+ public function setCache (Cache $ cache )
65+ {
66+ $ this ->cache = $ cache ;
67+ }
68+
69+ public function getCache ()
70+ {
71+ return $ this ->cache ;
72+ }
1173}
0 commit comments