Skip to content
Snippets Groups Projects
Commit d5844564 authored by Pierre Fleutot's avatar Pierre Fleutot
Browse files

Ajout type DateTimeMicroseconds. DEV : on utilise plus le firewall api pour...

Ajout type DateTimeMicroseconds. DEV : on utilise plus le firewall api pour utilisation plus simple du swagger
parent 1d624ac6
No related branches found
No related tags found
No related merge requests found
doctrine: doctrine:
dbal: dbal:
types:
datetimemicroseconds: App\Doctrine\Types\DateTimeMicrosecondsType
url: '%env(resolve:DATABASE_URL)%' url: '%env(resolve:DATABASE_URL)%'
# IMPORTANT: You MUST configure your server version, # IMPORTANT: You MUST configure your server version,
......
...@@ -18,12 +18,12 @@ security: ...@@ -18,12 +18,12 @@ security:
api_token: api_token:
pattern: ^/api/token$ pattern: ^/api/token$
security: false security: false
api: # api:
pattern: ^/api(?!/doc$) # Accepts routes under /api except /api/doc (pour api/doc, on utilisera donc le firewall "main" ce qui permettra d'accéder au swagger quand on est authentifié via Session PHP avec le role Admin # pattern: ^/api(?!/doc$) # Accepts routes under /api except /api/doc (pour api/doc, on utilisera donc le firewall "main" ce qui permettra d'accéder au swagger quand on est authentifié via Session PHP avec le role Admin
security: true # security: true
stateless: true # Pas d'authentification, pas de session utilisateur (mais le compte user est vérifié via le token) # stateless: true # Pas d'authentification, pas de session utilisateur (mais le compte user est vérifié via le token)
oauth2: true # oauth2: true
user_checker: App\Security\EasyUserChecker # user_checker: App\Security\EasyUserChecker
dev: dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/ pattern: ^/(_(profiler|wdt)|css|images|js)/
...@@ -62,7 +62,7 @@ security: ...@@ -62,7 +62,7 @@ security:
- { path: ^/token, role: PUBLIC_ACCESS } - { path: ^/token, role: PUBLIC_ACCESS }
- { path: ^/.well-known, roles: PUBLIC_ACCESS } - { path: ^/.well-known, roles: PUBLIC_ACCESS }
- { path: ^/api/doc, role: ROLE_ADMIN } # swagger Firewall: main - { path: ^/api/doc, role: ROLE_ADMIN } # swagger Firewall: main
- { path: ^/api, roles: [ROLE_OAUTH2_EMAIL] } # Firewall: Api - { path: ^/api, roles: [ROLE_OAUTH2_EMAIL, ROLE_ADMIN] } # Firewall: Api
- { path: ^/, role: ROLE_USER } - { path: ^/, role: ROLE_USER }
when@test: when@test:
......
<?php
namespace App\Doctrine\Types;
use DateTime;
use DateTimeInterface;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\ConversionException;
/**
* Override datetime datatype to support microseconds
*/
class DateTimeMicrosecondsType extends Type
{
const TYPENAME = 'datetimemicroseconds'; // modify to match your type name
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
if (isset($fieldDeclaration['version']) && $fieldDeclaration['version'] == true) {
return 'TIMESTAMP';
}
return 'DATETIME(6)';
}
public function convertToPHPValue($value, AbstractPlatform $platform)
{
if ($value === null || $value instanceof DateTimeInterface) {
return $value;
}
$val = DateTime::createFromFormat('Y-m-d H:i:s.u', $value);
if ( ! $val) {
$val = date_create($value);
}
if ( ! $val) {
throw ConversionException::conversionFailedFormat(
$value,
$this->getName(),
'Y-m-d H:i:s.u'
);
}
return $val;
}
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
if (null === $value) {
return $value;
}
if ($value instanceof DateTimeInterface) {
return $value->format('Y-m-d H:i:s.u');
}
throw ConversionException::conversionFailedInvalidType(
$value,
$this->getName(),
['null', 'DateTime']
);
}
public function getName()
{
return self::TYPENAME;
}
}
\ No newline at end of file
...@@ -53,7 +53,7 @@ class MetaInfo ...@@ -53,7 +53,7 @@ class MetaInfo
* @ORM\ManyToOne(targetEntity=Graphy::class, inversedBy="metaInfos") * @ORM\ManyToOne(targetEntity=Graphy::class, inversedBy="metaInfos")
* @Groups({"metaInfo:read"}) * @Groups({"metaInfo:read"})
*/ */
private $createdBy; private $graphies;
public function __toString() public function __toString()
{ {
......
...@@ -27,6 +27,12 @@ class Trace ...@@ -27,6 +27,12 @@ class Trace
*/ */
private $createdAt; private $createdAt;
/**
* @Groups({"trace:read"})
* @ORM\Column(type="datetimemicroseconds")
*/
private $timestamp;
/** /**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="traces") * @ORM\ManyToOne(targetEntity=User::class, inversedBy="traces")
* @Groups({"trace:read"}) * @Groups({"trace:read"})
...@@ -126,4 +132,16 @@ class Trace ...@@ -126,4 +132,16 @@ class Trace
return $this; return $this;
} }
public function getTimestamp()
{
return $this->timestamp;
}
public function setTimestamp($timestamp): self
{
$this->timestamp = $timestamp;
return $this;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment