本文整理汇总了PHP中Timestamp::makeNow方法的典型用法代码示例。如果您正苦于以下问题:PHP Timestamp::makeNow方法的具体用法?PHP Timestamp::makeNow怎么用?PHP Timestamp::makeNow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Timestamp
的用法示例。
在下文中一共展示了Timestamp::makeNow方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: associate
/**
* "associate" mode request
*
* @param $server to make association with (usually obtained from OpenIdCredentials)
* @param $manager - dao-like association manager
* @return OpenIdConsumerAssociation
**/
public function associate(HttpUrl $server, OpenIdConsumerAssociationManager $manager)
{
Assert::isTrue($server->isValid());
if ($association = $manager->findByServer($server)) {
return $association;
}
$dhParameters = new DiffieHellmanParameters($this->numberFactory->makeNumber(self::DIFFIE_HELLMAN_G), $this->numberFactory->makeNumber(self::DIFFIE_HELLMAN_P));
$keyPair = DiffieHellmanKeyPair::generate($dhParameters, $this->randomSource);
$request = HttpRequest::create()->setMethod(HttpMethod::post())->setUrl($server)->setPostVar('openid.ns', self::NAMESPACE_2_0)->setPostVar('openid.mode', 'associate')->setPostVar('openid.assoc_type', self::ASSOCIATION_TYPE)->setPostVar('openid.session_type', 'DH-SHA1')->setPostVar('openid.dh_modulus', base64_encode($dhParameters->getModulus()->toBinary()))->setPostVar('openid.dh_gen', base64_encode($dhParameters->getGen()->toBinary()))->setPostVar('openid.dh_consumer_public', base64_encode($keyPair->getPublic()->toBinary()));
$response = $this->httpClient->setFollowLocation(true)->send($request);
if ($response->getStatus()->getId() != HttpStatus::CODE_200) {
throw new OpenIdException('bad response code from server');
}
$result = $this->parseKeyValueFormat($response->getBody());
if (empty($result['assoc_handle'])) {
throw new OpenIdException('can\\t live without handle');
}
if (!isset($result['assoc_type']) || $result['assoc_type'] !== self::ASSOCIATION_TYPE) {
throw new OpenIdException('bad association type');
}
if (!isset($result['expires_in']) || !is_numeric($result['expires_in'])) {
throw new OpenIdException('bad expires');
}
if (isset($result['session_type']) && $result['session_type'] == 'DH-SHA1' && isset($result['dh_server_public'])) {
$secret = sha1($keyPair->makeSharedKey($this->numberFactory->makeFromBinary(base64_decode($result['dh_server_public'])))->toBinary(), true) ^ base64_decode($result['enc_mac_key']);
} elseif (empty($result['session_type']) && isset($result['mac_key'])) {
$secret = base64_decode($result['mac_key']);
} else {
throw new OpenIdException('no secret in answer');
}
return $manager->makeAndSave($result['assoc_handle'], $result['assoc_type'], $secret, Timestamp::makeNow()->modify('+ ' . $result['expires_in'] . ' seconds'), $server);
}
示例2: testDayDifference
public function testDayDifference()
{
$today = Date::makeToday();
$this->dayDifferenceTest($today, $today, 0);
$timestamp = Timestamp::makeNow();
$this->dayDifferenceTest($timestamp, $timestamp, 0);
$left = Date::create('2008-01-12');
$right = Date::create('2008-01-13');
$this->dayDifferenceTest($left, $right, 1);
$left = Date::create('2008-01-12');
$right = Date::create('2009-01-13');
$this->dayDifferenceTest($left, $right, 367);
$left = Date::create('2008-01-12');
$right = Date::create('2008-01-11');
$this->dayDifferenceTest($left, $right, -1);
$left = Timestamp::create('2008-01-12 01:23:00');
$right = Timestamp::create('2008-01-13 13:01:17');
$this->dayDifferenceTest($left, $right, 1);
// change time from winter to summer
$left = Timestamp::create('2008-03-29 02:00:00');
$right = Timestamp::create('2008-03-30 02:00:00');
$this->dayDifferenceTest($left, $right, 1);
$left = Timestamp::create('2008-03-29 03:00:00');
$right = Timestamp::create('2008-03-30 03:00:00');
$this->dayDifferenceTest($left, $right, 1);
// unsolved giv's case
// $left = Timestamp::create('2008-10-25 03:00:00');
// $right = Timestamp::create('2008-10-26 02:59:00');
// $this->dayDifferenceTest($left, $right, 0);
return $this;
}
示例3: testSleeping
public function testSleeping()
{
$stamp = Timestamp::makeNow();
$serializedStamp = serialize($stamp);
$unserializedStamp = unserialize($serializedStamp);
$this->assertEquals($stamp->getDay(), $unserializedStamp->getDay());
$this->assertEquals($stamp->getMonth(), $unserializedStamp->getMonth());
$this->assertEquals($stamp->getYear(), $unserializedStamp->getYear());
$this->assertEquals($stamp->getMinute(), $unserializedStamp->getMinute());
$this->assertEquals($stamp->getSecond(), $unserializedStamp->getSecond());
}
示例4: testIpAddressProperty
public function testIpAddressProperty()
{
foreach (DBTestPool::me()->getPool() as $db) {
DBPool::me()->setDefault($db);
$city = TestCity::create()->setName('Khimki');
TestCity::dao()->add($city);
$userWithIp = TestUser::create()->setCredentials(Credentials::create()->setNickName('postgreser')->setPassword(sha1('postgreser')))->setLastLogin(Timestamp::makeNow())->setRegistered(Timestamp::makeNow())->setCity($city)->setIp(IpAddress::create('127.0.0.1'));
TestUser::dao()->add($userWithIp);
$this->assertTrue($userWithIp->getId() >= 1);
$this->assertTrue($userWithIp->getIp() instanceof IpAddress);
$plainIp = DBPool::me()->getByDao(TestUser::dao())->queryColumn(OSQL::select()->get('ip')->from(TestUser::dao()->getTable())->where(Expression::eq('id', $userWithIp->getId())));
$this->assertEquals($plainIp[0], $userWithIp->getIp()->toString());
$count = Criteria::create(TestUser::dao())->add(Expression::eq('ip', IpAddress::create('127.0.0.1')))->addProjection(Projection::count('*', 'count'))->getCustom('count');
$this->assertEquals($count, 1);
}
}
示例5: testQueueConsumer
public function testQueueConsumer()
{
$c = new AMQPPecl(AMQPCredentials::createDefault());
$channel = $c->createChannel(1);
$channel->exchangeDeclare(self::EXCHANGE_NAME, AMQPExchangeConfig::create()->setType(new AMQPExchangeType(AMQPExchangeType::DIRECT))->setDurable(true));
$inQueueCount = $channel->queueDeclare(self::QUEUE_NAME, AMQPQueueConfig::create()->setDurable(true));
$this->assertSame(0, $inQueueCount);
$channel->queueBind(self::QUEUE_NAME, self::EXCHANGE_NAME, self::ROUTING_KEY);
//cleanup
$channel->queuePurge(self::QUEUE_NAME);
for ($i = 1; $i <= self::COUNT_OF_PUBLISH; $i++) {
$channel->basicPublish(self::EXCHANGE_NAME, self::ROUTING_KEY, AMQPOutgoingMessage::create()->setBody("message {$i}")->setTimestamp(Timestamp::makeNow())->setAppId(__CLASS__)->setMessageId($i)->setContentEncoding('utf-8'));
}
$consumer = new AMQPTestCaseQueueConsumer($channel);
$channel->basicConsume(self::QUEUE_NAME, false, $consumer);
$i = 0;
while (true) {
$message = $consumer->getNextDelivery();
//send acknowledge to RabbitMQ
$channel->basicAck($message->getDeliveryTag(), false);
$i++;
$this->assertSame($consumer->getConsumerTag(), $message->getConsumerTag());
$this->assertEquals($i, $message->getMessageId());
$this->assertEquals(__CLASS__, $message->getAppId());
$this->assertEquals("message {$i}", $message->getBody());
if ($i == self::COUNT_OF_PUBLISH) {
break;
}
}
$channel->basicCancel($consumer->getConsumerTag());
//observer logic test
$this->assertSame('ABBBBBC', $consumer->getCheckString());
//drop channels and close connection
$c->disconnect();
$c = new AMQPPecl(AMQPCredentials::createDefault());
$channel = $c->createChannel(1);
$channel->exchangeDeclare(self::EXCHANGE_NAME, AMQPExchangeConfig::create()->setType(new AMQPExchangeType(AMQPExchangeType::DIRECT))->setDurable(true));
//queue must be empty, because we sent acknowledge
$inQueueCount = $channel->queueDeclare(self::QUEUE_NAME, AMQPQueueConfig::create()->setDurable(true));
$this->assertSame(0, $inQueueCount);
//cleanup
$channel->queuePurge(self::QUEUE_NAME);
}
示例6: publishMessages
/**
* @param AMQPChannelInterface $channel
* @param bool $check
* @param string $key
* @param string $queueName
*/
protected function publishMessages(AMQPChannelInterface $channel, $check = true, $label = 'basic')
{
for ($i = 1; $i <= self::COUNT_OF_PUBLISH; $i++) {
$channelInterface = $channel->basicPublish(self::$queueList[$label]['exchange'], self::$queueList[$label]['key'], AMQPOutgoingMessage::create()->setBody("message {$i}")->setTimestamp(Timestamp::makeNow())->setAppId(__CLASS__)->setMessageId($i)->setContentEncoding('utf-8'));
if ($check) {
$this->assertInstanceOf('AMQPChannelInterface', $channelInterface);
}
}
if ($check) {
$this->checkMessageCount($channel, $label);
}
}
示例7: __construct
public function __construct()
{
$this->date = Timestamp::makeNow();
}
示例8: testSleeping
public function testSleeping()
{
$stamp = Timestamp::makeNow();
$serializedStamp = serialize($stamp);
$unserializedStamp = unserialize($serializedStamp);
$this->assertEquals($stamp->getDay(), $unserializedStamp->getDay());
$this->assertEquals($stamp->getMonth(), $unserializedStamp->getMonth());
$this->assertEquals($stamp->getYear(), $unserializedStamp->getYear());
$this->assertEquals($stamp->getMinute(), $unserializedStamp->getMinute());
$this->assertEquals($stamp->getSecond(), $unserializedStamp->getSecond());
$stamp = Timestamp::create('2039-01-05 12:14:05 Europe/Moscow');
$serializedStamp = serialize($stamp);
$unserializedStamp = unserialize($serializedStamp);
$this->assertEquals($stamp->getDay(), $unserializedStamp->getDay());
$this->assertEquals($stamp->getMonth(), $unserializedStamp->getMonth());
$this->assertEquals($stamp->getYear(), $unserializedStamp->getYear());
$this->assertEquals($stamp->getMinute(), $unserializedStamp->getMinute());
$this->assertEquals($stamp->getSecond(), $unserializedStamp->getSecond());
$stamp = Timestamp::create('1899-12-31 16:07:45 Europe/London');
$serializedStamp = serialize($stamp);
$unserializedStamp = unserialize($serializedStamp);
$this->assertEquals($stamp->getDay(), $unserializedStamp->getDay());
$this->assertEquals($stamp->getMonth(), $unserializedStamp->getMonth());
$this->assertEquals($stamp->getYear(), $unserializedStamp->getYear());
$this->assertEquals($stamp->getMinute(), $unserializedStamp->getMinute());
$this->assertEquals($stamp->getSecond(), $unserializedStamp->getSecond());
}
示例9: __construct
public function __construct(Timestamp $timestamp = null)
{
$this->timestamp = $timestamp ?: Timestamp::makeNow();
}