Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 23 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| ColumnAttributeHandler | |
0.00% |
0 / 23 |
|
0.00% |
0 / 4 |
182 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| attributeClass | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| targets | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| handle | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
110 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Dynart\Micro\Entities\AttributeHandler; |
| 4 | |
| 5 | use Dynart\Micro\AttributeHandlerInterface; |
| 6 | use Dynart\Micro\Entities\Attribute\Column; |
| 7 | use Dynart\Micro\Entities\EntityManager; |
| 8 | |
| 9 | class ColumnAttributeHandler implements AttributeHandlerInterface { |
| 10 | |
| 11 | private EntityManager $entityManager; |
| 12 | |
| 13 | public function __construct(EntityManager $entityManager) { |
| 14 | $this->entityManager = $entityManager; |
| 15 | } |
| 16 | |
| 17 | public function attributeClass(): string { |
| 18 | return Column::class; |
| 19 | } |
| 20 | |
| 21 | public function targets(): array { |
| 22 | return [AttributeHandlerInterface::TARGET_PROPERTY]; |
| 23 | } |
| 24 | |
| 25 | public function handle(string $className, mixed $subject, object $attribute): void { |
| 26 | /** @var Column $attribute */ |
| 27 | $columnData = [EntityManager::COLUMN_TYPE => $attribute->type]; |
| 28 | |
| 29 | if ($attribute->size !== 0) { |
| 30 | $columnData[EntityManager::COLUMN_SIZE] = $attribute->size; |
| 31 | } |
| 32 | if ($attribute->fixSize) { |
| 33 | $columnData[EntityManager::COLUMN_FIX_SIZE] = true; |
| 34 | } |
| 35 | if ($attribute->notNull) { |
| 36 | $columnData[EntityManager::COLUMN_NOT_NULL] = true; |
| 37 | } |
| 38 | if ($attribute->autoIncrement) { |
| 39 | $columnData[EntityManager::COLUMN_AUTO_INCREMENT] = true; |
| 40 | } |
| 41 | if ($attribute->primaryKey) { |
| 42 | $columnData[EntityManager::COLUMN_PRIMARY_KEY] = true; |
| 43 | } |
| 44 | if ($attribute->default !== null) { |
| 45 | $columnData[EntityManager::COLUMN_DEFAULT] = $attribute->default; |
| 46 | } |
| 47 | if ($attribute->foreignKey !== null) { |
| 48 | $columnData[EntityManager::COLUMN_FOREIGN_KEY] = $attribute->foreignKey; |
| 49 | } |
| 50 | if ($attribute->onDelete !== null) { |
| 51 | $columnData[EntityManager::COLUMN_ON_DELETE] = $attribute->onDelete; |
| 52 | } |
| 53 | if ($attribute->onUpdate !== null) { |
| 54 | $columnData[EntityManager::COLUMN_ON_UPDATE] = $attribute->onUpdate; |
| 55 | } |
| 56 | |
| 57 | $this->entityManager->addColumn($className, $subject->getName(), $columnData); |
| 58 | } |
| 59 | } |