Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ class RegisterDriverMappingPass implements CompilerPassInterface
public function process(ContainerBuilder $container)
{
foreach (array_keys($container->findTaggedServiceIds('lug.resource')) as $id) {
$this->getCompilerPass($container->getDefinition($id))->process($container);
if (($compiler = $this->getCompilerPass($container->getDefinition($id))) !== null) {
$compiler->process($container);
}
}
}

/**
* @param Definition $definition
*
* @return CompilerPassInterface
* @return CompilerPassInterface|null
*/
private function getCompilerPass(Definition $definition)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public function __construct(RegistryInterface $resourceRegistry)
public function configure(ResolveTargetSubscriberInterface $resolveTargetObjectSubscriber)
{
foreach ($this->resourceRegistry as $resource) {
if ($resource->getDriver() === null) {
continue;
}

foreach ($resource->getInterfaces() as $interface) {
$resolveTargetObjectSubscriber->addResolveTarget($interface, $resource->getModel());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,15 @@ protected function loadBundle(array $config, ContainerBuilder $container)
*/
private function configureResource(ResourceInterface $resource, array $config)
{
$driverConfig = $config['driver'];
$mappingConfig = $driverConfig['mapping'];

$resource->setModel($config['model']);
$resource->setDriver($config['driver']['name']);
$resource->setDriverManager($config['driver']['manager']);
$resource->setDriverMappingPath($config['driver']['mapping']['path']);
$resource->setDriverMappingFormat($config['driver']['mapping']['format']);
$resource->setRepository($config['repository']);
$resource->setDriver(isset($driverConfig['name']) ? $driverConfig['name'] : null);
$resource->setDriverManager(isset($driverConfig['manager']) ? $driverConfig['manager'] : null);
$resource->setDriverMappingPath(isset($mappingConfig['path']) ? $mappingConfig['path'] : null);
$resource->setDriverMappingFormat(isset($mappingConfig['format']) ? $mappingConfig['format'] : null);
$resource->setRepository(isset($config['repository']) ? $config['repository'] : null);
$resource->setFactory(isset($config['factory']) ? $config['factory'] : null);
$resource->setForm(isset($config['form']) ? $config['form'] : null);
$resource->setChoiceForm(isset($config['choice_form']) ? $config['choice_form'] : null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public function testConfigure()
->method('getIterator')
->will($this->returnValue(new \ArrayIterator([$resource = $this->createResourceMock()])));

$resource
->expects($this->once())
->method('getDriver')
->will($this->returnValue(ResourceInterface::DRIVER_DOCTRINE_ORM));

$resource
->expects($this->once())
->method('getInterfaces')
Expand All @@ -69,6 +74,26 @@ public function testConfigure()
$this->configurator->configure($subscriber);
}

public function testConfigureWithoutDriver()
{
$this->serviceRegistry
->expects($this->once())
->method('getIterator')
->will($this->returnValue(new \ArrayIterator([$resource = $this->createResourceMock()])));

$resource
->expects($this->once())
->method('getDriver')
->will($this->returnValue(null));

$subscriber = $this->createResolveTargetSubscriberMock();
$subscriber
->expects($this->never())
->method('addResolveTarget');

$this->configurator->configure($subscriber);
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject|RegistryInterface
*/
Expand Down