Skip to content

Commit

Permalink
Merge pull request #18 from marcojanssen/master
Browse files Browse the repository at this point in the history
Added alias mapping option for entity namespaces
  • Loading branch information
simensen committed Sep 18, 2013
2 parents d0a6dd4 + 86485ef commit 93306ed
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ Configuration
* **resources_namespace**: A namespaceish path to where the mapping
files are located. Example: `Path\To\Foo\Resources\mappings`

Each mapping definition can have the following optional options:
* **alias** (Default: null): Set the alias for the entity namespace.

Each **annotation** mapping may also specify the following options:
* **use_simple_annotation_reader** (Default: true):
If `true`, only simple notations like `@Entity` will work.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ public function register(\Pimple $app)
$entity['path'] = $app['psr0_resource_locator']->findFirstDirectory($entity['resources_namespace']);
}

if (isset($entity['alias'])) {
$config->addEntityNamespace($entity['alias'], $entity['namespace']);
}

switch ($entity['type']) {
case 'annotation':
$useSimpleAnnotationReader =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,31 @@ public function testInvalidMappingAsOption()

$app['orm.ems.config'];
}

/**
* Test if namespace alias can be set through the mapping options
*/
public function testMappingAlias()
{
$app = $this->createMockDefaultApp();

$doctrineOrmServiceProvider = new DoctrineOrmServiceProvider;
$doctrineOrmServiceProvider->register($app);

$alias = 'Foo';
$namespace = 'Foo\Entities';

$app['orm.em.options'] = array(
'mappings' => array(
array(
'type' => 'annotation',
'namespace' => $namespace,
'path' => __DIR__.'/src/Foo/Entities',
'alias' => $alias
)
),
);

$this->assertEquals($namespace, $app['orm.em.config']->getEntityNameSpace($alias));
}
}

0 comments on commit 93306ed

Please sign in to comment.