comparison vendor/zendframework/zend-feed/src/PubSubHubbub/PubSubHubbub.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 7a779792577d
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
4 *
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
9
10 namespace Zend\Feed\PubSubHubbub;
11
12 use Zend\Escaper\Escaper;
13 use Zend\Feed\Reader;
14 use Zend\Http;
15
16 class PubSubHubbub
17 {
18 /**
19 * Verification Modes
20 */
21 const VERIFICATION_MODE_SYNC = 'sync';
22 const VERIFICATION_MODE_ASYNC = 'async';
23
24 /**
25 * Subscription States
26 */
27 const SUBSCRIPTION_VERIFIED = 'verified';
28 const SUBSCRIPTION_NOTVERIFIED = 'not_verified';
29 const SUBSCRIPTION_TODELETE = 'to_delete';
30
31 /**
32 * @var Escaper
33 */
34 protected static $escaper;
35
36 /**
37 * Singleton instance if required of the HTTP client
38 *
39 * @var Http\Client
40 */
41 protected static $httpClient = null;
42
43 /**
44 * Simple utility function which imports any feed URL and
45 * determines the existence of Hub Server endpoints. This works
46 * best if directly given an instance of Zend\Feed\Reader\Atom|Rss
47 * to leverage off.
48 *
49 * @param \Zend\Feed\Reader\Feed\AbstractFeed|string $source
50 * @return array
51 * @throws Exception\InvalidArgumentException
52 */
53 public static function detectHubs($source)
54 {
55 if (is_string($source)) {
56 $feed = Reader\Reader::import($source);
57 } elseif ($source instanceof Reader\Feed\AbstractFeed) {
58 $feed = $source;
59 } else {
60 throw new Exception\InvalidArgumentException('The source parameter was'
61 . ' invalid, i.e. not a URL string or an instance of type'
62 . ' Zend\Feed\Reader\Feed\AbstractFeed');
63 }
64 return $feed->getHubs();
65 }
66
67 /**
68 * Allows the external environment to make ZendOAuth use a specific
69 * Client instance.
70 *
71 * @param Http\Client $httpClient
72 * @return void
73 */
74 public static function setHttpClient(Http\Client $httpClient)
75 {
76 static::$httpClient = $httpClient;
77 }
78
79 /**
80 * Return the singleton instance of the HTTP Client. Note that
81 * the instance is reset and cleared of previous parameters GET/POST.
82 * Headers are NOT reset but handled by this component if applicable.
83 *
84 * @return Http\Client
85 */
86 public static function getHttpClient()
87 {
88 if (!isset(static::$httpClient)) {
89 static::$httpClient = new Http\Client;
90 } else {
91 static::$httpClient->resetParameters();
92 }
93 return static::$httpClient;
94 }
95
96 /**
97 * Simple mechanism to delete the entire singleton HTTP Client instance
98 * which forces a new instantiation for subsequent requests.
99 *
100 * @return void
101 */
102 public static function clearHttpClient()
103 {
104 static::$httpClient = null;
105 }
106
107 /**
108 * Set the Escaper instance
109 *
110 * If null, resets the instance
111 *
112 * @param null|Escaper $escaper
113 */
114 public static function setEscaper(Escaper $escaper = null)
115 {
116 static::$escaper = $escaper;
117 }
118
119 /**
120 * Get the Escaper instance
121 *
122 * If none registered, lazy-loads an instance.
123 *
124 * @return Escaper
125 */
126 public static function getEscaper()
127 {
128 if (null === static::$escaper) {
129 static::setEscaper(new Escaper());
130 }
131 return static::$escaper;
132 }
133
134 /**
135 * RFC 3986 safe url encoding method
136 *
137 * @param string $string
138 * @return string
139 */
140 public static function urlencode($string)
141 {
142 $escaper = static::getEscaper();
143 $rawencoded = $escaper->escapeUrl($string);
144 $rfcencoded = str_replace('%7E', '~', $rawencoded);
145 return $rfcencoded;
146 }
147 }