annotate vendor/zendframework/zend-feed/src/PubSubHubbub/PubSubHubbub.php @ 19:fa3358dc1485 tip

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