Falseclock /
dbd-php-entity
| 1 | <?php |
||
| 2 | /******************************************************************************** |
||
| 3 | * Apache License, Version 2.0 * |
||
| 4 | * * |
||
| 5 | * Copyright [2020] [Nurlan Mukhanov <[email protected]>] * |
||
| 6 | * * |
||
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); * |
||
| 8 | * you may not use this file except in compliance with the License. * |
||
| 9 | * You may obtain a copy of the License at * |
||
| 10 | * * |
||
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 * |
||
| 12 | * * |
||
| 13 | * Unless required by applicable law or agreed to in writing, software * |
||
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, * |
||
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * |
||
| 16 | * See the License for the specific language governing permissions and * |
||
| 17 | * limitations under the License. * |
||
| 18 | * * |
||
| 19 | ********************************************************************************/ |
||
| 20 | |||
| 21 | declare(strict_types=1); |
||
| 22 | |||
| 23 | namespace DBD\Entity; |
||
| 24 | |||
| 25 | use DBD\Entity\Common\EntityException; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Class Column |
||
| 29 | * |
||
| 30 | * @package DBD\Entity |
||
| 31 | */ |
||
| 32 | class Column |
||
| 33 | { |
||
| 34 | const ANNOTATION = "annotation"; |
||
| 35 | const DEFAULT = "defaultValue"; |
||
| 36 | const IS_AUTO = "isAuto"; |
||
| 37 | const KEY = "key"; |
||
| 38 | const MAXLENGTH = "maxLength"; |
||
| 39 | const NAME = "name"; |
||
| 40 | const NULLABLE = "nullable"; |
||
| 41 | const ORIGIN_TYPE = "originType"; |
||
| 42 | const PRECISION = "precision"; |
||
| 43 | /** |
||
| 44 | * @see Primitive |
||
| 45 | * @var string Primitive Type |
||
| 46 | */ |
||
| 47 | const PRIMITIVE_TYPE = "type"; |
||
| 48 | const SCALE = "scale"; |
||
| 49 | /** @var string $annotation */ |
||
| 50 | public $annotation; |
||
| 51 | /** @var mixed $defaultValue */ |
||
| 52 | public $defaultValue; |
||
| 53 | /** @var boolean $isAuto does column have auto increment or auto generated value? */ |
||
| 54 | public $isAuto = false; |
||
| 55 | /** @var boolean $key Flag of Primary key */ |
||
| 56 | public $key; |
||
| 57 | /** @var int $maxLength */ |
||
| 58 | public $maxLength; |
||
| 59 | /** @var string $name name of column in database */ |
||
| 60 | public $name; |
||
| 61 | /** @var bool $nullable */ |
||
| 62 | public $nullable; |
||
| 63 | /** @var string $type type of column as written in database */ |
||
| 64 | public $originType; |
||
| 65 | /** @var int $precision */ |
||
| 66 | public $precision; |
||
| 67 | /** @var mixed $scale */ |
||
| 68 | public $scale; |
||
| 69 | /** @var Primitive $type */ |
||
| 70 | public $type; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Column constructor. |
||
| 74 | * |
||
| 75 | * @param string|array $columnNameOrArray |
||
| 76 | * @throws EntityException |
||
| 77 | */ |
||
| 78 | public function __construct($columnNameOrArray) |
||
| 79 | { |
||
| 80 | if (isset($columnNameOrArray)) { |
||
| 81 | if (is_string($columnNameOrArray)) { |
||
| 82 | $this->name = $columnNameOrArray; |
||
| 83 | } else if (is_array($columnNameOrArray)) { |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 84 | foreach ($columnNameOrArray as $key => $value) { |
||
| 85 | if ($key == self::PRIMITIVE_TYPE) { |
||
| 86 | $this->type = new Primitive($value); |
||
| 87 | } else { |
||
| 88 | $this->$key = $value; |
||
| 89 | } |
||
| 90 | } |
||
| 91 | } else { |
||
| 92 | throw new EntityException("column constructor accepts only string or array"); |
||
| 93 | } |
||
| 94 | } |
||
| 95 | |||
| 96 | if (!isset($this->name)) { |
||
| 97 | throw new EntityException(sprintf("columns not set: %s. Check that Embedded and Complex fields are protected type.", json_encode($columnNameOrArray))); |
||
| 98 | } |
||
| 99 | } |
||
| 100 | } |
||
| 101 |