Skip to content

Commit

Permalink
Extension: config key 'entities' renamed to 'mapping'
Browse files Browse the repository at this point in the history
  • Loading branch information
janpecha committed Feb 15, 2021
1 parent 063091f commit 06bca0b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ leanmapper:
``` neon
leanmapper:
entityFactory: LeanMapper\DefaultEntityFactory
entities:
mapping:
table: EntityClass
table:
Expand Down
16 changes: 8 additions & 8 deletions src/LeanMapperExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class LeanMapperExtension extends \Nette\DI\CompilerExtension
'charset' => NULL,

// entities
'entities' => NULL,
'mapping' => NULL,
];


Expand Down Expand Up @@ -112,26 +112,26 @@ protected function configMapper(ContainerBuilder $builder, array $config)
->setClass($config['mapper'], [$config['defaultEntityNamespace']]);

$this->processEntityProviders($mapper, $config);
$this->processUserEntities($mapper, $config);
$this->processUserMapping($mapper, $config);

return $mapper;
}


/**
* Processes user entities definitions + registers repositories in container
* Processes user entities mapping + registers repositories in container
* @return void
*/
protected function processUserEntities(ServiceDefinition $mapper, array $config)
protected function processUserMapping(ServiceDefinition $mapper, array $config)
{
$builder = $this->getContainerBuilder();

if (isset($config['entities'])) {
if (!is_array($config['entities'])) {
throw new \RuntimeException('List of entities must be array, ' . gettype($config['entities']) . ' given');
if (isset($config['mapping'])) {
if (!is_array($config['mapping'])) {
throw new \RuntimeException('Mapping must be array, ' . gettype($config['mapping']) . ' given');
}

foreach ($config['entities'] as $tableName => $mapping) {
foreach ($config['mapping'] as $tableName => $mapping) {
if (isset($mapping['repository']) && !is_string($mapping['repository'])) {
throw new \RuntimeException('Repository class must be string or NULL, ' . gettype($mapping['primaryKey']) . ' given');
}
Expand Down
2 changes: 1 addition & 1 deletion tests/LeanMapperExtension/config/readme.entities.neon
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

leanmapper:
driver: fakeMysql
entities:
mapping:
user: UserEntity

newslist:
Expand Down

0 comments on commit 06bca0b

Please sign in to comment.