Skip to content

Commit

Permalink
Dynamically add fluent mapping files on runtime (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickbrouwers committed Jan 29, 2017
1 parent 4c96515 commit 958f91c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Configuration/MetaData/Fluent.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct(Container $container)
*/
public function resolve(array $settings = [])
{
$driver = new FluentDriver(array_get($settings, 'mappings'));
$driver = new FluentDriver(array_get($settings, 'mappings', []));

$namingStrategy = $this->getNamingStrategy($settings);

Expand Down
11 changes: 11 additions & 0 deletions src/DoctrineManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ public function addPaths(array $paths = [], $connection = null)
});
}

/**
* @param array $mappings
* @param string|null $connection
*/
public function addMappings(array $mappings = [], $connection = null)
{
$this->onResolve(function (ManagerRegistry $registry) use ($connection, $mappings) {
$this->getMetaDataDriver($connection, $registry)->addMappings($mappings);
});
}

/**
* @param null $connection
*
Expand Down
15 changes: 13 additions & 2 deletions src/Extensions/MappingDriverChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Doctrine\Common\Persistence\Mapping\Driver\FileDriver;
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain as DoctrineMappingDriverChain;
use Doctrine\Common\Persistence\Mapping\Driver\StaticPHPDriver;
use Doctrine\Common\Persistence\Mapping\Driver\SymfonyFileLocator;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;

Expand Down Expand Up @@ -37,7 +36,7 @@ public function addPaths(array $paths = [])
{
$driver = $this->getDefaultDriver();

if ($driver instanceof AnnotationDriver || $driver instanceof StaticPHPDriver) {
if (method_exists($driver, 'addPaths')) {
$driver->addPaths($paths);
} elseif ($driver instanceof FileDriver) {
if ($driver->getLocator() instanceof DefaultFileLocator) {
Expand All @@ -48,6 +47,18 @@ public function addPaths(array $paths = [])
}
}

/**
* @param array $mappings
*/
public function addMappings(array $mappings = [])
{
$driver = $this->getDefaultDriver();

if (method_exists($driver, 'addMappings')) {
$driver->addMappings($mappings);
}
}

/**
* @return \Doctrine\Common\Annotations\Reader|null
*/
Expand Down
3 changes: 3 additions & 0 deletions tests/Stubs/storage/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!.gitignore
!views/.gitignore
Empty file.

0 comments on commit 958f91c

Please sign in to comment.