Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Timestamp.php
Go to the documentation of this file.
1 <?php
7 
10 
22 class Timestamp implements FactoryInterface
23 {
27  const NULL_TIMESTAMP = 'NULL';
28 
32  private $objectManager;
33 
37  private $className;
38 
42  private $booleanUtils;
43 
51  public function __construct(
52  ObjectManagerInterface $objectManager,
53  BooleanUtils $booleanUtils,
54  $className = \Magento\Framework\Setup\Declaration\Schema\Dto\Columns\Timestamp::class
55  ) {
56  $this->objectManager = $objectManager;
57  $this->className = $className;
58  $this->booleanUtils = $booleanUtils;
59  }
60 
64  public function create(array $data)
65  {
66  $data['onUpdate'] = isset($data['on_update']) ? $data['on_update'] : null;
67  //OnUpdate is boolean as there is only one possible value for onUpdate statement.
68  if ($data['onUpdate'] && $data['onUpdate'] !== 'CURRENT_TIMESTAMP') {
69  if ($this->booleanUtils->toBoolean($data['onUpdate'])) {
70  $data['onUpdate'] = 'CURRENT_TIMESTAMP';
71  } else {
72  unset($data['onUpdate']);
73  }
74  }
75  //By default default attribute is not used.
76  if (!isset($data['default'])) {
77  $data['default'] = self::NULL_TIMESTAMP;
78  }
79 
80  return $this->objectManager->create($this->className, $data);
81  }
82 }
$objectManager
Definition: bootstrap.php:17
__construct(ObjectManagerInterface $objectManager, BooleanUtils $booleanUtils, $className=\Magento\Framework\Setup\Declaration\Schema\Dto\Columns\Timestamp::class)
Definition: Timestamp.php:51