Skip to content

Commit 93306ed

Browse files
committed
Merge pull request #18 from marcojanssen/master
Added alias mapping option for entity namespaces
2 parents d0a6dd4 + 86485ef commit 93306ed

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ Configuration
212212
* **resources_namespace**: A namespaceish path to where the mapping
213213
files are located. Example: `Path\To\Foo\Resources\mappings`
214214

215+
Each mapping definition can have the following optional options:
216+
* **alias** (Default: null): Set the alias for the entity namespace.
217+
215218
Each **annotation** mapping may also specify the following options:
216219
* **use_simple_annotation_reader** (Default: true):
217220
If `true`, only simple notations like `@Entity` will work.

src/Dflydev/Pimple/Provider/DoctrineOrm/DoctrineOrmServiceProvider.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ public function register(\Pimple $app)
129129
$entity['path'] = $app['psr0_resource_locator']->findFirstDirectory($entity['resources_namespace']);
130130
}
131131

132+
if (isset($entity['alias'])) {
133+
$config->addEntityNamespace($entity['alias'], $entity['namespace']);
134+
}
135+
132136
switch ($entity['type']) {
133137
case 'annotation':
134138
$useSimpleAnnotationReader =

tests/Dflydev/Pimple/Provider/DoctrineOrm/DoctrineOrmServiceProviderTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,4 +282,31 @@ public function testInvalidMappingAsOption()
282282

283283
$app['orm.ems.config'];
284284
}
285+
286+
/**
287+
* Test if namespace alias can be set through the mapping options
288+
*/
289+
public function testMappingAlias()
290+
{
291+
$app = $this->createMockDefaultApp();
292+
293+
$doctrineOrmServiceProvider = new DoctrineOrmServiceProvider;
294+
$doctrineOrmServiceProvider->register($app);
295+
296+
$alias = 'Foo';
297+
$namespace = 'Foo\Entities';
298+
299+
$app['orm.em.options'] = array(
300+
'mappings' => array(
301+
array(
302+
'type' => 'annotation',
303+
'namespace' => $namespace,
304+
'path' => __DIR__.'/src/Foo/Entities',
305+
'alias' => $alias
306+
)
307+
),
308+
);
309+
310+
$this->assertEquals($namespace, $app['orm.em.config']->getEntityNameSpace($alias));
311+
}
285312
}

0 commit comments

Comments
 (0)