예제 #1
0
 /**
  * Save subscription to RDMBS
  *
  * @param array $data
  * @return bool
  */
 public function setSubscription(array $data)
 {
     if (!isset($data['id'])) {
         throw new PubSubHubbub\Exception('ID must be set before attempting a save');
     }
     $result = $this->_db->select(array('id' => $data['id']));
     if ($result && 0 < count($result)) {
         $data['created_time'] = $result->current()->created_time;
         $now = new Date\Date();
         if (array_key_exists('lease_seconds', $data) && $data['lease_seconds']) {
             $data['expiration_time'] = $now->add($data['lease_seconds'], Date\Date::SECOND)->get('yyyy-MM-dd HH:mm:ss');
         }
         $this->_db->update($data, array('id' => $data['id']));
         return false;
     }
     $this->_db->insert($data);
     return true;
 }
예제 #2
0
 /**
  * Save subscription to RDMBS
  *
  * @param array $data
  * @return bool
  */
 public function setSubscription(array $data)
 {
     if (!isset($data['id'])) {
         throw new PubSubHubbub\Exception('ID must be set before attempting a save');
     }
     $result = $this->_db->find($data['id']);
     if ($result) {
         $data['created_time'] = $result->current()->created_time;
         $now = new Date\Date();
         if ($data['lease_seconds']) {
             $data['expiration_time'] = $now->add($data['lease_seconds'], Date\Date::SECOND)->get('yyyy-MM-dd HH:mm:ss');
         }
         $this->_db->update($data, $this->_db->getAdapter()->quoteInto('id = ?', $data['id']));
         return false;
     }
     $this->_db->insert($data);
     return true;
 }
예제 #3
0
파일: DateTest.php 프로젝트: rikaix/zf2
 /**
  * @ZF-8650
  */
 public function testFractionalPrecision()
 {
     $date = new Date();
     $date->set('012345', Date::MILLISECOND);
     $this->assertEquals(3, $date->getFractionalPrecision());
     $this->assertEquals('345', $date->toString('S'));
     $date->setFractionalPrecision(6);
     $this->assertEquals(6, $date->getFractionalPrecision());
     $this->assertEquals('345000', $date->toString('S'));
     $date->add(200, Date::MILLISECOND);
     $this->assertEquals(6, $date->getFractionalPrecision());
     $this->assertEquals('345200', $date->toString('S'));
 }
예제 #4
0
 public function testRespondsToValidConfirmationWithBodyContainingHubChallenge()
 {
     $this->_tableGateway->expects($this->any())->method('find')->with($this->equalTo('verifytokenkey'))->will($this->returnValue($this->_rowset));
     $t = new Date\Date();
     $rowdata = array('id' => 'verifytokenkey', 'verify_token' => hash('sha256', 'cba'), 'created_time' => $t->get(Date\Date::TIMESTAMP), 'lease_seconds' => 10000);
     $row = new \Zend\Db\Table\Row(array('data' => $rowdata));
     $this->_rowset->expects($this->any())->method('current')->will($this->returnValue($row));
     // require for the count call on the rowset in Model/Subscription
     $this->_rowset->expects($this->any())->method('count')->will($this->returnValue(1));
     $this->_tableGateway->expects($this->once())->method('update')->with($this->equalTo(array('id' => 'verifytokenkey', 'verify_token' => hash('sha256', 'cba'), 'created_time' => $t->get(Date\Date::TIMESTAMP), 'lease_seconds' => 1234567, 'subscription_state' => 'verified', 'expiration_time' => $t->add(1234567, Date\Date::SECOND)->get('yyyy-MM-dd HH:mm:ss'))), $this->equalTo('id = \'verifytokenkey\''));
     $this->_adapter->expects($this->once())->method('quoteInto')->with($this->equalTo('id = ?'), $this->equalTo('verifytokenkey'))->will($this->returnValue('id = \'verifytokenkey\''));
     $this->_callback->handle($this->_get);
     $this->assertTrue($this->_callback->getHttpResponse()->getBody() == 'abc');
 }
예제 #5
0
 /**
  * Return a list of standard protocol/optional parameters for addition to
  * client's POST body that are specific to the current Hub Server URL
  *
  * @param  string $hubUrl
  * @param  mode $hubUrl
  * @return string
  */
 protected function _getRequestParameters($hubUrl, $mode)
 {
     if (!in_array($mode, array('subscribe', 'unsubscribe'))) {
         throw new Exception('Invalid mode specified: "' . $mode . '" which should have been "subscribe" or "unsubscribe"');
     }
     $params = array('hub.mode' => $mode, 'hub.topic' => $this->getTopicUrl());
     if ($this->getPreferredVerificationMode() == PubSubHubbub::VERIFICATION_MODE_SYNC) {
         $vmodes = array(PubSubHubbub::VERIFICATION_MODE_SYNC, PubSubHubbub::VERIFICATION_MODE_ASYNC);
     } else {
         $vmodes = array(PubSubHubbub::VERIFICATION_MODE_ASYNC, PubSubHubbub::VERIFICATION_MODE_SYNC);
     }
     $params['hub.verify'] = array();
     foreach ($vmodes as $vmode) {
         $params['hub.verify'][] = $vmode;
     }
     /**
      * Establish a persistent verify_token and attach key to callback
      * URL's path/querystring
      */
     $key = $this->_generateSubscriptionKey($params, $hubUrl);
     $token = $this->_generateVerifyToken();
     $params['hub.verify_token'] = $token;
     // Note: query string only usable with PuSH 0.2 Hubs
     if (!$this->_usePathParameter) {
         $params['hub.callback'] = $this->getCallbackUrl() . '?xhub.subscription=' . PubSubHubbub::urlencode($key);
     } else {
         $params['hub.callback'] = rtrim($this->getCallbackUrl(), '/') . '/' . PubSubHubbub::urlencode($key);
     }
     if ($mode == 'subscribe' && !is_null($this->getLeaseSeconds())) {
         $params['hub.lease_seconds'] = $this->getLeaseSeconds();
     }
     // hub.secret not currently supported
     $optParams = $this->getParameters();
     foreach ($optParams as $name => $value) {
         $params[$name] = $value;
     }
     // store subscription to storage
     $now = new Date\Date();
     $expires = null;
     if (isset($params['hub.lease_seconds'])) {
         $expires = $now->add($params['hub.lease_seconds'], Date\Date::SECOND)->get('yyyy-MM-dd HH:mm:ss');
     }
     $data = array('id' => $key, 'topic_url' => $params['hub.topic'], 'hub_url' => $hubUrl, 'created_time' => $now->get('yyyy-MM-dd HH:mm:ss'), 'lease_seconds' => $expires, 'verify_token' => hash('sha256', $params['hub.verify_token']), 'secret' => null, 'expiration_time' => $expires, 'subscription_state' => PubSubHubbub::SUBSCRIPTION_NOTVERIFIED);
     $this->getStorage()->setSubscription($data);
     return $this->_toByteValueOrderedString($this->_urlEncode($params));
 }