From 05e92d4fd92b8d3ab20bd786da4b3510b80bef5e Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 15 Jul 2021 23:37:19 -0700 Subject: [PATCH] Schema - Add PhpDataTypeSpecTrait --- Civi/Schema/Traits/PhpDataTypeSpecTrait.php | 88 +++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 Civi/Schema/Traits/PhpDataTypeSpecTrait.php diff --git a/Civi/Schema/Traits/PhpDataTypeSpecTrait.php b/Civi/Schema/Traits/PhpDataTypeSpecTrait.php new file mode 100644 index 0000000000..3c3e7dd52c --- /dev/null +++ b/Civi/Schema/Traits/PhpDataTypeSpecTrait.php @@ -0,0 +1,88 @@ +required = FALSE; + } + $type = preg_grep('/null/i', $type, PREG_GREP_INVERT); + // If there is one `@var` type, then attempt to infer the `dataType` and `serialize` type. + if (count($type) === 1) { + switch ($type[0]) { + case 'string[]': + case 'int[]': + case 'bool[]': + case 'array': + $autoDataType = 'Blob'; + $autoSerialize = \CRM_Core_DAO::SERIALIZE_JSON; + break; + + case 'string': + case 'int': + $autoDataType = ucfirst($type[0]); + $autoSerialize = NULL; + break; + + case 'bool': + $autoDataType = 'Boolean'; + $autoSerialize = NULL; + break; + } + + if ($this->dataType === NULL) { + $this->setDataType($autoDataType); + } + if ($this->serialize === NULL) { + $this->setSerialize($autoSerialize); + } + } + $this->type = $type; + return $this; + } + + /** + * @return string[] + */ + public function getType(): array { + return $this->type; + } + +} -- 2.25.1