Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Refactored PubSubHubbub to use Escaper
Browse files Browse the repository at this point in the history
- instead of rawurlencode()
- added static accessors for Escaper instance
- added zend-escaper to composer.json for Zend\Feed
  • Loading branch information
weierophinney committed Sep 20, 2012
1 parent 7f48d9e commit 07d847b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
48 changes: 41 additions & 7 deletions library/Zend/Feed/PubSubHubbub/PubSubHubbub.php
Expand Up @@ -10,6 +10,7 @@

namespace Zend\Feed\PubSubHubbub;

use Zend\Escaper\Escaper;
use Zend\Feed\Reader;
use Zend\Http;

Expand All @@ -32,10 +33,15 @@ class PubSubHubbub
const SUBSCRIPTION_NOTVERIFIED = 'not_verified';
const SUBSCRIPTION_TODELETE = 'to_delete';

/**
* @var Escaper
*/
protected static $escaper;

/**
* Singleton instance if required of the HTTP client
*
* @var \Zend\Http\Client
* @var Http\Client
*/
protected static $httpClient = null;

Expand Down Expand Up @@ -67,7 +73,7 @@ public static function detectHubs($source)
* Allows the external environment to make Zend_Oauth use a specific
* Client instance.
*
* @param \Zend\Http\Client $httpClient
* @param Http\Client $httpClient
* @return void
*/
public static function setHttpClient(Http\Client $httpClient)
Expand All @@ -80,15 +86,15 @@ public static function setHttpClient(Http\Client $httpClient)
* the instance is reset and cleared of previous parameters GET/POST.
* Headers are NOT reset but handled by this component if applicable.
*
* @return \Zend\Http\Client
* @return Http\Client
*/
public static function getHttpClient()
{
if (!isset(self::$httpClient)):
if (!isset(self::$httpClient)) {
self::$httpClient = new Http\Client;
else:
} else {
self::$httpClient->resetParameters();
endif;
}
return self::$httpClient;
}

Expand All @@ -103,6 +109,33 @@ public static function clearHttpClient()
self::$httpClient = null;
}

/**
* Set the Escaper instance
*
* If null, resets the instance
*
* @param null|Escaper $escaper
*/
public static function setEscaper(Escaper $escaper = null)
{
static::$escaper = $escaper;
}

/**
* Get the Escaper instance
*
* If none registered, lazy-loads an instance.
*
* @return Escaper
*/
public static function getEscaper()
{
if (null === static::$escaper) {
static::setEscaper(new Escaper());
}
return static::$escaper;
}

/**
* RFC 3986 safe url encoding method
*
Expand All @@ -111,7 +144,8 @@ public static function clearHttpClient()
*/
public static function urlencode($string)
{
$rawencoded = rawurlencode($string);
$escaper = static::getEscaper();
$rawencoded = $escaper->escapeUrl($string);
$rfcencoded = str_replace('%7E', '~', $rawencoded);
return $rfcencoded;
}
Expand Down
1 change: 1 addition & 0 deletions library/Zend/Feed/composer.json
Expand Up @@ -14,6 +14,7 @@
"target-dir": "Zend/Feed",
"require": {
"php": ">=5.3.3",
"zendframework/zend-escaper": "self.version",
"zendframework/zend-stdlib": "self.version"
},
"suggest": {
Expand Down

0 comments on commit 07d847b

Please sign in to comment.