Skip to content

Commit b47d17d

Browse files
committed
Merge pull request #3 from texdc/namespace
Add Namespace and PSR-4 autoloading
2 parents 31188fc + 89d1910 commit b47d17d

File tree

3 files changed

+80
-24
lines changed

3 files changed

+80
-24
lines changed

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
This PHP library implements a subscriber for PubSubHubbub.
22

3-
It was written by Josh Fraser (joshfraser.com) and is released under the Apache 2.0 License
3+
It was written by [Josh Fraser](http://joshfraser.com) and is released under the Apache 2.0 License
44

5-
# Usage
5+
# Install
6+
Update your `composer` require block:
7+
```json
8+
"require": { "pubsubhubub/subscriber": "*" }
9+
```
610

11+
# Usage
712
```php
8-
include("subscriber.php");
13+
use pubsubhubbub\subscriber\Subscriber;
914

10-
$hub_url = "http://pubsubhubbub.appspot.com";
15+
$hub_url = "http://pubsubhubbub.appspot.com";
1116
$callback_url = "put your own endpoint here";
1217

13-
$feed = "http://feeds.feedburner.com/onlineaspect";
14-
1518
// create a new subscriber
1619
$s = new Subscriber($hub_url, $callback_url);
1720

21+
$feed = "http://feeds.feedburner.com/onlineaspect";
22+
1823
// subscribe to a feed
1924
$s->subscribe($feed);
2025

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
}
1313
],
1414
"require": {
15-
"php": ">=5.0.0"
15+
"php": "~5.4 || ~7.0"
1616
},
17-
"autoload": {
18-
"classmap": ["subscriber.php"]
17+
"autoload": {
18+
"psr-4": { "pubsubhubbub\\subscriber\\": "src/" }
1919
}
2020
}

subscriber.php renamed to src/subscriber.php

Lines changed: 66 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,50 @@
11
<?php
2+
/**
3+
* A PHP client library for pubsubhubbub
4+
*
5+
* @link http://code.google.com/p/pubsubhubbub/
6+
* @author Josh Fraser | joshfraser.com | josh@eventvue.com
7+
* @license Apache License 2.0
8+
*/
29

3-
// a PHP client library for pubsubhubbub
4-
// as defined at http://code.google.com/p/pubsubhubbub/
5-
// written by Josh Fraser | joshfraser.com | josh@eventvue.com
6-
// Released under Apache License 2.0
10+
namespace pubsubhubbub/subscriber;
711

812
class Subscriber {
9-
10-
// put your google key here
11-
// required if you want to use the google feed API to lookup RSS feeds
13+
/**
14+
* put your google key here
15+
* required if you want to use the google feed API to lookup RSS feeds
16+
*
17+
* @var string
18+
*/
1219
protected $google_key = "";
1320

21+
/** @var string */
1422
protected $hub_url;
23+
24+
/** @var string */
1525
protected $callback_url;
26+
27+
/** @var string */
1628
protected $credentials;
17-
// accepted values are "async" and "sync"
29+
30+
/**
31+
* @var string accepted values are "async" and "sync"
32+
*/
1833
protected $verify = "async";
34+
35+
/** @var string */
1936
protected $verify_token;
37+
38+
/** @var int */
2039
protected $lease_seconds;
2140

22-
// create a new Subscriber (credentials added for SuperFeedr support)
41+
/**
42+
* create a new Subscriber (credentials added for SuperFeedr support)
43+
*
44+
* @param string $hub_url
45+
* @param string $callback_url
46+
* @param string $credentials
47+
*/
2348
public function __construct($hub_url, $callback_url, $credentials = false) {
2449

2550
if (!isset($hub_url))
@@ -36,7 +61,13 @@ public function __construct($hub_url, $callback_url, $credentials = false) {
3661
$this->credentials = $credentials;
3762
}
3863

39-
// $use_regexp lets you choose whether to use google AJAX feed api (faster, but cached) or a regexp to read from site
64+
/**
65+
* $use_regexp lets you choose whether to use google AJAX feed api (faster, but cached) or a regexp to read from site
66+
*
67+
* @param string $url
68+
* @param callable $http_function
69+
* @return string
70+
*/
4071
public function find_feed($url, $http_function = false) {
4172
// using google feed API
4273
$url = "http://ajax.googleapis.com/ajax/services/feed/lookup?key={$this->google_key}&v=1.0&q=".urlencode($url);
@@ -51,15 +82,32 @@ public function find_feed($url, $http_function = false) {
5182
return $rss_url;
5283
}
5384

85+
/**
86+
* @param string $topic_url
87+
* @param callable $http_function
88+
* @return mixed
89+
*/
5490
public function subscribe($topic_url, $http_function = false) {
5591
return $this->change_subscription("subscribe", $topic_url, $http_function = false);
5692
}
5793

94+
/**
95+
* @param string $topic_url
96+
* @param callable $http_function
97+
* @return mixed
98+
*/
5899
public function unsubscribe($topic_url, $http_function = false) {
59100
return $this->change_subscription("unsubscribe", $topic_url, $http_function = false);
60101
}
61102

62-
// helper function since sub/unsub are handled the same way
103+
/**
104+
* helper function since sub/unsub are handled the same way
105+
*
106+
* @param string $mode
107+
* @param string $topic_url
108+
* @param callable $http_function
109+
* @return mixed
110+
*/
63111
private function change_subscription($mode, $topic_url, $http_function = false) {
64112
if (!isset($topic_url))
65113
throw new Exception('Please specify a topic url');
@@ -86,7 +134,13 @@ private function change_subscription($mode, $topic_url, $http_function = false)
86134
return $this->http($this->hub_url,$post_string);
87135
}
88136

89-
// default http function that uses curl to post to the hub endpoint
137+
/**
138+
* default http function that uses curl to post to the hub endpoint
139+
*
140+
* @param string $url
141+
* @param string $post_string
142+
* @return mixed
143+
*/
90144
private function http($url, $post_string) {
91145

92146
// add any additional curl options here
@@ -115,6 +169,3 @@ private function http($url, $post_string) {
115169
return false;
116170
}
117171
}
118-
119-
120-
?>

0 commit comments

Comments
 (0)