Skip to content

Commit

Permalink
ClassMetadata mapping for timeseries
Browse files Browse the repository at this point in the history
  • Loading branch information
cyildirim committed Jul 3, 2023
1 parent 69e64e7 commit 5e6e40d
Showing 1 changed file with 69 additions and 5 deletions.
74 changes: 69 additions & 5 deletions lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,34 @@
*/
public $collectionMax;

/**
* READ-ONLY: If the collection is fixed size, its size in bytes.
*
* @var int|null
*/
public $collectionSize;

/**
* READ-ONLY: If the collection is fixed size, the maximum number of elements to store in the collection.
*
* @var int|null
*/
public $collectionMax;

/**
* READ-ONLY: If the collection should be a timeseries
*
* @var array{timeField:string,metaField?:string,granularity?:string}|null
*/
public $collectionTimeseries;

/**
* READ-ONLY: If the collection is timeseries, sets automatic removal for the collection.
*
* @var int|null
*/
public $collectionExpireAfterSeconds;

/**
* READ-ONLY Describes how MongoDB clients route read operations to the members of a replica set.
*
Expand Down Expand Up @@ -653,6 +681,13 @@
*/
public $isMappedSuperclass = false;

/**
* READ-ONLY: Whether this class describes the mapping of Timeseries.
*
* @var bool
*/
public $isTimeSeriesDocument = false;

/**
* READ-ONLY: Whether this class describes the mapping of a embedded document.
*
Expand Down Expand Up @@ -1387,7 +1422,7 @@ public function getCollection(): string
* Sets the collection this Document is mapped to.
*
* @param array|string $name
* @psalm-param array{name: string, capped?: bool, size?: int, max?: int}|string $name
* @psalm-param array{name: string, capped?: bool, size?: int, max?: int}|array{name: string, timeseries?: array{timeField:string,metaField?:string,granularity?:string}, expireAfterSeconds?: int}|string $name
*
* @throws InvalidArgumentException
*/
Expand All @@ -1398,10 +1433,19 @@ public function setCollection($name): void
throw new InvalidArgumentException('A name key is required when passing an array to setCollection()');
}

$this->collectionCapped = $name['capped'] ?? false;
$this->collectionSize = $name['size'] ?? 0;
$this->collectionMax = $name['max'] ?? 0;
$this->collection = $name['name'];
if (array_key_exists('timeseries', $name)) {
$this->collectionTimeseries = [
'timeField' => $name['timeseries']['timeField'],
'metaField' => $name['timeseries']['metaField'] ?? null,
'granularity' => $name['timeseries']['granularity'] ?? null
];
$this->collectionExpireAfterSeconds = $name['expireAfterSeconds'] ?? null;
} else {
$this->collectionCapped = $name['capped'] ?? false;
$this->collectionSize = $name['size'] ?? 0;
$this->collectionMax = $name['max'] ?? 0;
$this->collection = $name['name'];
}
} else {
$this->collection = $name;
}
Expand Down Expand Up @@ -1475,7 +1519,23 @@ public function setCollectionMax(int $max): void
{
$this->collectionMax = $max;
}

/**
* @return array|null
*/
public function getCollectionTimeseries(): ?array
{
return $this->collectionTimeseries;
}

/**
* @return int|null
*/
public function getCollectionExpireAfterSeconds(): ?int
{
return $this->collectionExpireAfterSeconds;
}

/**
* Returns TRUE if this Document is mapped to a collection FALSE otherwise.
*/
Expand Down Expand Up @@ -2451,6 +2511,10 @@ public function __sleep()
$serialized[] = 'subClasses';
}

if ($this->isTimeSeriesDocument) {
$serialized[] = 'isTimeSeriesDocument';
}

if ($this->isMappedSuperclass) {
$serialized[] = 'isMappedSuperclass';
}
Expand Down

0 comments on commit 5e6e40d

Please sign in to comment.