本文整理汇总了PHP中Zend\Date\Date::add方法的典型用法代码示例。如果您正苦于以下问题:PHP Date::add方法的具体用法?PHP Date::add怎么用?PHP Date::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Date\Date
的用法示例。
在下文中一共展示了Date::add方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setSubscription
/**
* 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: setSubscription
/**
* 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: testFractionalPrecision
/**
* @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: testRespondsToValidConfirmationWithBodyContainingHubChallenge
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: _getRequestParameters
/**
* 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));
}