Subscription.php in Zircon Profile 8.0
File
vendor/zendframework/zend-feed/src/PubSubHubbub/Model/Subscription.php
View source
<?php
namespace Zend\Feed\PubSubHubbub\Model;
use DateInterval;
use DateTime;
use Zend\Feed\PubSubHubbub;
class Subscription extends AbstractModel implements SubscriptionPersistenceInterface {
protected $now;
public function setSubscription(array $data) {
if (!isset($data['id'])) {
throw new PubSubHubbub\Exception\InvalidArgumentException('ID must be set before attempting a save');
}
$result = $this->db
->select([
'id' => $data['id'],
]);
if ($result && 0 < count($result)) {
$data['created_time'] = $result
->current()->created_time;
$now = $this
->getNow();
if (array_key_exists('lease_seconds', $data) && $data['lease_seconds']) {
$data['expiration_time'] = $now
->add(new DateInterval('PT' . $data['lease_seconds'] . 'S'))
->format('Y-m-d H:i:s');
}
$this->db
->update($data, [
'id' => $data['id'],
]);
return false;
}
$this->db
->insert($data);
return true;
}
public function getSubscription($key) {
if (empty($key) || !is_string($key)) {
throw new PubSubHubbub\Exception\InvalidArgumentException('Invalid parameter "key"' . ' of "' . $key . '" must be a non-empty string');
}
$result = $this->db
->select([
'id' => $key,
]);
if (count($result)) {
return $result
->current()
->getArrayCopy();
}
return false;
}
public function hasSubscription($key) {
if (empty($key) || !is_string($key)) {
throw new PubSubHubbub\Exception\InvalidArgumentException('Invalid parameter "key"' . ' of "' . $key . '" must be a non-empty string');
}
$result = $this->db
->select([
'id' => $key,
]);
if (count($result)) {
return true;
}
return false;
}
public function deleteSubscription($key) {
$result = $this->db
->select([
'id' => $key,
]);
if (count($result)) {
$this->db
->delete([
'id' => $key,
]);
return true;
}
return false;
}
public function getNow() {
if (null === $this->now) {
return new DateTime();
}
return $this->now;
}
public function setNow(DateTime $now) {
$this->now = $now;
return $this;
}
}