TimestampColumn.php 994 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace Michel\PaperORM\Mapping\Column;
  3. use Attribute;
  4. use Michel\PaperORM\Types\DateTimeType;
  5. #[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::IS_REPEATABLE)]
  6. final class TimestampColumn extends Column
  7. {
  8. private bool $onCreated;
  9. private bool $onUpdated;
  10. public function __construct(
  11. string $name = null,
  12. bool $onCreated = false,
  13. bool $onUpdated = false,
  14. bool $nullable = true
  15. )
  16. {
  17. if (!$onCreated && !$onUpdated) {
  18. throw new \InvalidArgumentException(
  19. 'A TimestampColumn must be either onCreated or onUpdated (at least one true).'
  20. );
  21. }
  22. parent::__construct('', $name, DateTimeType::class, $nullable);
  23. $this->onCreated = $onCreated;
  24. $this->onUpdated = $onUpdated;
  25. }
  26. public function isOnCreated(): bool
  27. {
  28. return $this->onCreated;
  29. }
  30. public function isOnUpdated(): bool
  31. {
  32. return $this->onUpdated;
  33. }
  34. }