public function testAuthenticationSuccessful() { $user = new User('my_username', 'my_password', ['ROLE_USER']); $token = new UsernamePasswordToken($user, 'my_password', 'my_provider'); $response = $this->authenticator->onAuthenticationSuccess(Request::create('/'), $token); $decoded = json_decode($response->getContent(), true); $webToken = $this->coder->decode($decoded['token']); $shouldExpireAt = date_create_immutable('7 days'); $this->assertEquals($shouldExpireAt->format('Y-m-d'), $webToken->getExpireAt()->format('Y-m-d')); }
public function testCoding() { $utc = new \DateTimeZone('UTC'); $issuedAt = date_create_immutable('now'); $expireAt = date_create_immutable('+1 year'); $webToken = $this->coder->decode($this->coder->encode(new WebToken('my_subject', $issuedAt, $expireAt))); $this->assertEquals('my_subject', $webToken->getSubject()); $this->assertEquals($issuedAt->getTimestamp(), $webToken->getIssuedAt()->getTimestamp()); $this->assertEquals($expireAt->getTimestamp(), $webToken->getExpireAt()->getTimestamp()); }
/** * @param \DateTimeImmutable|string|null $value * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform * @return \DateTimeImmutable|null */ public function convertToPHPValue($value, AbstractPlatform $platform) { if ($value === null || $value instanceof DateTimeImmutable) { return $value; } $dateTime = DateTimeImmutable::createFromFormat($platform->getDateTimeFormatString(), $value); if ($dateTime === false) { $dateTime = date_create_immutable($value); } if ($dateTime === false) { throw \Doctrine\DBAL\Types\ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateTimeFormatString()); } return $dateTime; }
public function onAuthenticationSuccess(Request $request, TokenInterface $token) { $claims = []; $user = $token->getUser(); if ($user instanceof ClaimsAwareInterface) { $claims = $user->getClaims(); } $expireAt = date_create_immutable($this->options['time_to_live']); $webToken = new WebToken($token->getUsername(), date_create_immutable(), $expireAt, $claims); return new JsonResponse(['token' => $this->coder->encode($webToken)]); }
<?php $current = "2014-03-02 16:24:08"; $i = DateTimeImmutable::createFromMutable(date_create($current)); var_dump($i); $i = DateTimeImmutable::createFromMutable(date_create_immutable($current)); var_dump($i);
<?php $tz = new DateTimeZone("Asia/Tokyo"); $current = "2012-12-27 16:24:08"; echo "\ngetTimezone():\n"; $v = date_create_immutable($current); $x = $v->getTimezone(); var_dump($x->getName()); echo "\ngetTimestamp():\n"; $v = date_create_immutable($current); $x = $v->getTimestamp(); var_dump($x);
<?php var_dump(date_create('foo')); var_dump(date_create_immutable('foo'));
<?php $date = date_create_immutable(); var_dump(dom_import_simplexml($date)); var_dump(simplexml_import_dom($date));