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

Commit

Permalink
Merge branch 'master' of git://github.com/zendframework/zf2 into cach…
Browse files Browse the repository at this point in the history
…e_internals

Conflicts:
	library/Zend/Cache/Storage/Adapter/Filesystem.php
  • Loading branch information
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 75 deletions.
6 changes: 4 additions & 2 deletions src/PubSubHubbub/Model/AbstractModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*/
namespace Zend\Feed\PubSubHubbub\Model;

use \Zend\Db\TableGateway;

/**
* @uses \Zend\Db\Table\Table
* @uses \Zend\Registry
Expand All @@ -47,12 +49,12 @@ class AbstractModel
* @param \Zend\Db\Table\AbstractTable $tableGateway
* @return void
*/
public function __construct(\Zend\Db\Table\AbstractTable $tableGateway = null)
public function __construct(TableGateway\TableGatewayInterface $tableGateway = null)
{
if ($tableGateway === null) {
$parts = explode('\\', get_class($this));
$table = strtolower(array_pop($parts));
$this->_db = new \Zend\Db\Table\Table($table);
$this->_db = new TableGateway\TableGateway($table);
} else {
$this->_db = $tableGateway;
}
Expand Down
14 changes: 7 additions & 7 deletions src/PubSubHubbub/Model/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function setSubscription(array $data)
'ID must be set before attempting a save'
);
}
$result = $this->_db->find($data['id']);
$result = $this->_db->select(array('id' => $data['id']));
if ($result && (0 < count($result))) {
$data['created_time'] = $result->current()->created_time;
$now = new Date\Date;
Expand All @@ -65,7 +65,7 @@ public function setSubscription(array $data)
}
$this->_db->update(
$data,
$this->_db->getAdapter()->quoteInto('id = ?', $data['id'])
array('id' => $data['id'])
);
return false;
}
Expand All @@ -86,9 +86,9 @@ public function getSubscription($key)
throw new PubSubHubbub\Exception('Invalid parameter "key"'
.' of "' . $key . '" must be a non-empty string');
}
$result = $this->_db->find($key);
$result = $this->_db->select(array('id' => $key));
if (count($result)) {
return $result->current()->toArray();
return $result->current()->getArrayCopy();
}
return false;
}
Expand All @@ -105,7 +105,7 @@ public function hasSubscription($key)
throw new PubSubHubbub\Exception('Invalid parameter "key"'
.' of "' . $key . '" must be a non-empty string');
}
$result = $this->_db->find($key);
$result = $this->_db->select(array('id' => $key));
if (count($result)) {
return true;
}
Expand All @@ -120,10 +120,10 @@ public function hasSubscription($key)
*/
public function deleteSubscription($key)
{
$result = $this->_db->find($key);
$result = $this->_db->select(array('id' => $key));
if (count($result)) {
$this->_db->delete(
$this->_db->getAdapter()->quoteInto('id = ?', $key)
array('id' => $key)
);
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/PubSubHubbub/Publisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ public function getErrors()
protected function _getHttpClient()
{
$client = PubSubHubbub::getHttpClient();
$client->setMethod(\Zend\Http\Client::POST);
$client->setMethod(\Zend\Http\Request::METHOD_POST);
$client->setConfig(array(
'useragent' => 'Zend_Feed_Pubsubhubbub_Publisher/' . \Zend\Version::VERSION,
));
Expand All @@ -403,7 +403,7 @@ protected function _getHttpClient()
$params[] = urlencode($name) . '=' . urlencode($value);
}
$paramString = implode('&', $params);
$client->setRawData($paramString);
$client->setRawBody($paramString);
return $client;
}
}
17 changes: 9 additions & 8 deletions src/Reader/FeedSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,34 +65,35 @@ public function addLinks(\DOMNodeList $links, $uri)
continue;
}
if (!isset($this->rss) && $link->getAttribute('type') == 'application/rss+xml') {
$this->rss = $this->_absolutiseUri(trim($link->getAttribute('href')), $uri);
$this->rss = $this->absolutiseUri(trim($link->getAttribute('href')), $uri);
} elseif(!isset($this->atom) && $link->getAttribute('type') == 'application/atom+xml') {
$this->atom = $this->_absolutiseUri(trim($link->getAttribute('href')), $uri);
$this->atom = $this->absolutiseUri(trim($link->getAttribute('href')), $uri);
} elseif(!isset($this->rdf) && $link->getAttribute('type') == 'application/rdf+xml') {
$this->rdf = $this->_absolutiseUri(trim($link->getAttribute('href')), $uri);
$this->rdf = $this->absolutiseUri(trim($link->getAttribute('href')), $uri);
}
$this[] = new self(array(
'rel' => 'alternate',
'type' => $link->getAttribute('type'),
'href' => $this->_absolutiseUri(trim($link->getAttribute('href')), $uri),
'href' => $this->absolutiseUri(trim($link->getAttribute('href')), $uri),
));
}
}

/**
* Attempt to turn a relative URI into an absolute URI
*/
protected function _absolutiseUri($link, $uri = null)
protected function absolutiseUri($link, $uri = null)
{
if (!Uri\UriFactory::factory($link)->isValid()) {
$linkUri = Uri\UriFactory::factory($link);
if (!$linkUri->isAbsolute() or !$linkUri->isValid()) {
if ($uri !== null) {
$uri = Uri\UriFactory::factory($uri);

if ($link[0] !== '/') {
$link = $uri->getPath() . '/' . $link;
}

$link = $uri->getScheme() . '://' . $uri->getHost() . '/' . $this->_canonicalizePath($link);
$link = $uri->getScheme() . '://' . $uri->getHost() . '/' . $this->canonicalizePath($link);
if (!Uri\UriFactory::factory($link)->isValid()) {
$link = null;
}
Expand All @@ -104,7 +105,7 @@ protected function _absolutiseUri($link, $uri = null)
/**
* Canonicalize relative path
*/
protected function _canonicalizePath($path)
protected function canonicalizePath($path)
{
$parts = array_filter(explode('/', $path));
$absolutes = array();
Expand Down
8 changes: 4 additions & 4 deletions src/Reader/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,11 @@ public static function import($uri, $etag = null, $lastModified = null)
} else {
$responseXml = $response->getBody();
$cache->setItem($cacheId, $responseXml);
if ($response->getHeader('ETag')) {
$cache->setItem($cacheId . '_etag', $response->getHeader('ETag'));
if ($response->headers()->get('ETag')) {
$cache->setItem($cacheId . '_etag', $response->headers()->get('ETag')->getFieldValue());
}
if ($response->getHeader('Last-Modified')) {
$cache->setItem($cacheId . '_lastmodified', $response->getHeader('Last-Modified'));
if ($response->headers()->get('Last-Modified')) {
$cache->setItem($cacheId . '_lastmodified', $response->headers()->get('Last-Modified')->getFieldValue());
}
}
return self::importString($responseXml);
Expand Down
24 changes: 16 additions & 8 deletions test/PubSubHubbub/Model/SubscriptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
namespace ZendTest\Feed\PubSubHubbub\Model;

use Zend\Feed\PubSubHubbub\Model\Subscription;
use \Zend\Db\Adapter\Adapter as DbAdapter;
use \Zend\Db\TableGateway\TableGateway;

/**
* @category Zend
Expand All @@ -38,8 +40,13 @@ class SubscriptionTest extends \PHPUnit_Framework_TestCase
*/
public function testAllOperations()
{
$this->_initDb();
$subscription = new Subscription();
$this->markTestIncomplete('PDO_Sqlite does not return row count, and no solution in Zend\Db yet for this');

$adapter = $this->initDb();
$table = new TableGateway('subscription', $adapter);

$subscription = new Subscription($table);

$id = uniqid();
$this->assertFalse($subscription->hasSubscription($id));
$this->assertFalse($subscription->getSubscription($id));
Expand All @@ -66,19 +73,20 @@ public function testImpemetsSubscriptionInterface()
unset($reflection);
}

protected function _initDb()
protected function initDb()
{
if (!extension_loaded('pdo')
|| !in_array('sqlite', \PDO::getAvailableDrivers())
) {
$this->markTestSkipped('Test only with pdo_sqlite');
}
$db = \Zend\Db\Db::factory('Pdo\Sqlite', array('dbname' => ':memory:'));
\Zend\Db\Table\AbstractTable::setDefaultAdapter($db);
$this->_createTable();
$db = new DbAdapter(array('driver' => 'pdo_sqlite', 'dsn' => 'sqlite::memory:'));
$this->createTable($db);

return $db;
}

protected function _createTable()
protected function createTable($db)
{
$sql = "CREATE TABLE subscription ("
. "id varchar(32) PRIMARY KEY NOT NULL DEFAULT '', "
Expand All @@ -92,6 +100,6 @@ protected function _createTable()
. "subscription_state varchar(12) DEFAULT NULL"
. ");";

\Zend\Db\Table\AbstractTable::getDefaultAdapter()->getConnection()->query($sql);
$db->query($sql)->execute();
}
}
4 changes: 2 additions & 2 deletions test/PubSubHubbub/PublisherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,15 +309,15 @@ public function request($method = null) {
$response = new ResponseSuccess;
return $response;
}
public function getBody(){return $this->_prepareBody();}
public function getBody(){return $this->prepareBody();}
}
class ClientFail extends Http\Client
{
public function request($method = null) {
$response = new ResponseFail;
return $response;
}
public function getBody(){return $this->_prepareBody();}
public function getBody(){return $this->prepareBody();}
}
class ResponseSuccess
{
Expand Down
Loading

0 comments on commit 765b017

Please sign in to comment.