commercetools-sdk-php-v2  master
The platform, import-api and ml-api PHP sdks generated from our api reference.
DateTimeImmutableCollection.php
1 <?php
2 
3 declare(strict_types=1);
10 namespace Commercetools\Base;
11 
13 use DateTimeImmutable;
14 
21 {
28  public function add($value)
29  {
30  if (!$value instanceof DateTimeImmutable) {
31  throw new InvalidArgumentException();
32  }
33  $this->store($value);
34 
35  return $this;
36  }
37 
41  protected function mapper()
42  {
43  return function (int $index): ?DateTimeImmutable {
44  $data = $this->get($index);
45  if (!is_null($data) && !$data instanceof DateTimeImmutable) {
46  $data = new DateTimeImmutable((string)$data);
47  $this->set($data, $index);
48  }
49  return $data;
50  };
51  }
52 }