From e8bf4c58a8f50283fd6828559c129593e1f48cd8 Mon Sep 17 00:00:00 2001 From: Aleksandar Date: Sun, 26 May 2024 21:12:17 +0200 Subject: [PATCH] remove orm from this repo --- src/Orm/Attributes/Column.php | 15 --- src/Orm/Attributes/Relation.php | 18 ---- src/Orm/Attributes/Table.php | 15 --- src/Orm/Attributes/ViaToModel.php | 17 ---- src/Orm/ModelCompiler.php | 102 --------------------- src/Orm/RelationalMapper.php | 116 ------------------------ tests/unit/Orm/RelationalMapperTest.php | 45 --------- 7 files changed, 328 deletions(-) delete mode 100644 src/Orm/Attributes/Column.php delete mode 100644 src/Orm/Attributes/Relation.php delete mode 100644 src/Orm/Attributes/Table.php delete mode 100644 src/Orm/Attributes/ViaToModel.php delete mode 100644 src/Orm/ModelCompiler.php delete mode 100644 src/Orm/RelationalMapper.php delete mode 100644 tests/unit/Orm/RelationalMapperTest.php diff --git a/src/Orm/Attributes/Column.php b/src/Orm/Attributes/Column.php deleted file mode 100644 index f0e00b5..0000000 --- a/src/Orm/Attributes/Column.php +++ /dev/null @@ -1,15 +0,0 @@ -compiled[$modelClass])) { - return $this->compiled[$modelClass]; - } - - $resolvedModel = []; - - $reflected = new ReflectionClass($modelClass); - - $resolvedModel['table'] = $reflected->getAttributes(Table::class)[0]->getArguments()[0]; - - $properties = $reflected->getProperties(ReflectionProperty::IS_PUBLIC); - - $resolvedModel['columns'] = $this->resolveColumns($properties); - - $propertyColumnMap = array_flip($resolvedModel['columns']); - - $resolvedModel['relations'] = $this->resolveRelations($properties, $propertyColumnMap); - - $this->compiled[$modelClass] = $resolvedModel; - - foreach ($this->compiled[$modelClass]['relations'] as &$config) { - $config['table'] = $this->resolve($config['model'])['table']; - } - - return $this->compiled[$modelClass]; - } - - protected function resolveColumns(array $properties): array - { - $columns = []; - - foreach ($properties as $property) { - $column = $property->getAttributes(Column::class); - $propertyName = $property->getName(); - - if (!empty($column)) { - $column = $column[0]->getArguments(); - - if (empty($column)) { - $column = $propertyName; - } else { - $column = $column[0]; - } - - $columns[$column] = $propertyName; - } - } - - return $columns; - } - - protected function resolveRelations(array $properties, array $propertyColumnMap): array - { - $relations = []; - - foreach ($properties as $property) { - $relation = $property->getAttributes(Relation::class); - - if (empty($relation)) { - continue; - } - - $propertyName = $property->getName(); - - [ - 'via' => $via, - 'model' => $model, - 'at' => $at, - 'multiple' => $multipleResults - ] = $relation[0]->getArguments(); - - $relations[$propertyName] = [ - 'model' => $model, - 'foreign_key' => $propertyColumnMap[$via], - 'table_key' => $at, - 'multiple_results' => $multipleResults - ]; - - $viaToModel = $property->getAttributes(ViaToModel::class); - } - - return $relations; - } -} \ No newline at end of file diff --git a/src/Orm/RelationalMapper.php b/src/Orm/RelationalMapper.php deleted file mode 100644 index 3a5349f..0000000 --- a/src/Orm/RelationalMapper.php +++ /dev/null @@ -1,116 +0,0 @@ -useDriver($driver); - } - - if ($builder) { - $this->useBuilder($builder); - } - - $this->compiler = new ModelCompiler(); - } - - /** - * Set a driver to be used for queries. - * - * @param Driver $driver Driver to be used. - * @return $this - */ - public function useDriver(Driver $driver): static - { - $this->driver = $driver; - return $this; - } - - /** - * Set query builder to be used. - * - * @param QueryBuilder $builder Builder to be used. - * @return $this - */ - public function useBuilder(QueryBuilder $builder): static - { - $this->builder = $builder; - return $this; - } - - - public function toModelStructure(string $modelClass): array - { - // Relational handler for complex models - // Relational handler should have find, save, delete implemented for the model class - // and the model class should not have any attributes. - // relational handler needs to be registered in this mapper to be used - // models are missing multi primary keys relations - // columns are missing a primary key flag (for insert/update check) - return $this->compiler->resolve($modelClass); - } - - public function find(string $modelClass) - { - - } - - public function save($model) - { - - } - - public function delete($model) - { - - } -} \ No newline at end of file diff --git a/tests/unit/Orm/RelationalMapperTest.php b/tests/unit/Orm/RelationalMapperTest.php deleted file mode 100644 index de1d6ca..0000000 --- a/tests/unit/Orm/RelationalMapperTest.php +++ /dev/null @@ -1,45 +0,0 @@ -toModelStructure(UserTableMock::class); - - $expected = [ - 'table' => 'users', - 'columns' => [ - 'id' => 'id', - 'username' => 'username', - 'password' => 'password', - 'profile_id' => 'profileId' - ], - 'relations' => [ - 'profiles' => [ - 'model' => ProfileTableMock::class, - 'foreign_key' => 'profile_id', - 'table_key' => 'id', - 'multiple_results' => true, - 'table' => 'profiles', - ] - ] - ]; - - expect($structure)->toBe($expected); - } -} \ No newline at end of file