3 * Zend Framework (http://framework.zend.com/)
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
10 namespace Zend\Feed\PubSubHubbub;
12 use Zend\Escaper\Escaper;
21 const VERIFICATION_MODE_SYNC = 'sync';
22 const VERIFICATION_MODE_ASYNC = 'async';
27 const SUBSCRIPTION_VERIFIED = 'verified';
28 const SUBSCRIPTION_NOTVERIFIED = 'not_verified';
29 const SUBSCRIPTION_TODELETE = 'to_delete';
34 protected static $escaper;
37 * Singleton instance if required of the HTTP client
41 protected static $httpClient = null;
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
49 * @param \Zend\Feed\Reader\Feed\AbstractFeed|string $source
51 * @throws Exception\InvalidArgumentException
53 public static function detectHubs($source)
55 if (is_string($source)) {
56 $feed = Reader\Reader::import($source);
57 } elseif ($source instanceof Reader\Feed\AbstractFeed) {
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');
64 return $feed->getHubs();
68 * Allows the external environment to make ZendOAuth use a specific
71 * @param Http\Client $httpClient
74 public static function setHttpClient(Http\Client $httpClient)
76 static::$httpClient = $httpClient;
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.
86 public static function getHttpClient()
88 if (! isset(static::$httpClient)) {
89 static::$httpClient = new Http\Client;
91 static::$httpClient->resetParameters();
93 return static::$httpClient;
97 * Simple mechanism to delete the entire singleton HTTP Client instance
98 * which forces a new instantiation for subsequent requests.
102 public static function clearHttpClient()
104 static::$httpClient = null;
108 * Set the Escaper instance
110 * If null, resets the instance
112 * @param null|Escaper $escaper
114 public static function setEscaper(Escaper $escaper = null)
116 static::$escaper = $escaper;
120 * Get the Escaper instance
122 * If none registered, lazy-loads an instance.
126 public static function getEscaper()
128 if (null === static::$escaper) {
129 static::setEscaper(new Escaper());
131 return static::$escaper;
135 * RFC 3986 safe url encoding method
137 * @param string $string
140 public static function urlencode($string)
142 $escaper = static::getEscaper();
143 $rawencoded = $escaper->escapeUrl($string);
144 $rfcencoded = str_replace('%7E', '~', $rawencoded);