Skip to content

Commit

Permalink
Fix incompatibility with Nette 2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
enumag authored and fprochazka committed Apr 19, 2016
1 parent bb5bf7b commit cb548e0
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/Kdyby/Doctrine/DI/OrmExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -607,17 +607,18 @@ protected function processMetadataDriver(Nette\DI\ServiceDefinition $metadataDri
$driver = new Statement(self::ANNOTATION_DRIVER, is_array($paths) ? $paths : [$paths]);
}

$impl = $driver instanceof \stdClass ? $driver->value : ($driver instanceof Statement ? $driver->entity : (string) $driver);
$impl = $driver instanceof \stdClass ? $driver->value : ($driver instanceof Statement ? $driver->getEntity() : (string) $driver);
list($driver) = CacheHelpers::filterArgs($driver);
/** @var Statement $driver */

/** @var string $impl */
if (isset($this->metadataDriverClasses[$impl])) {
$driver->entity = $this->metadataDriverClasses[$impl];
$driver->setEntity($this->metadataDriverClasses[$impl]);
}

if (is_string($driver->entity) && substr($driver->entity, 0, 1) === '@') {
$metadataDriver->addSetup('addDriver', [$driver->entity, $namespace]);
return $driver->entity;
if (is_string($driver->getEntity()) && substr($driver->getEntity(), 0, 1) === '@') {
$metadataDriver->addSetup('addDriver', [$driver->getEntity(), $namespace]);
return $driver->getEntity();
}

if ($impl === self::ANNOTATION_DRIVER) {
Expand All @@ -631,7 +632,7 @@ protected function processMetadataDriver(Nette\DI\ServiceDefinition $metadataDri

$this->getContainerBuilder()->addDefinition($serviceName)
->setClass('Doctrine\Common\Persistence\Mapping\Driver\MappingDriver')
->setFactory($driver->entity, $driver->arguments)
->setFactory($driver->getEntity(), $driver->arguments)
->setAutowired(FALSE)
->setInject(FALSE);

Expand Down Expand Up @@ -678,7 +679,7 @@ protected function processRepositories()

$disabled = TRUE;
foreach ($this->configuredManagers as $managerName => $_) {
$factoryClassName = $builder->getDefinition($this->prefix($managerName . '.repositoryFactory'))->class;
$factoryClassName = $builder->getDefinition($this->prefix($managerName . '.repositoryFactory'))->getClass();
if ($factoryClassName === 'Kdyby\Doctrine\RepositoryFactory' || in_array('Kdyby\Doctrine\RepositoryFactory', class_parents($factoryClassName), TRUE)) {
$disabled = FALSE;
}
Expand Down Expand Up @@ -728,21 +729,21 @@ protected function processRepositories()

if ($boundEntity = $originalDef->getTag(self::TAG_REPOSITORY_ENTITY)) {
if (!is_string($boundEntity) || !class_exists($boundEntity)) {
throw new Nette\Utils\AssertionException(sprintf('The entity "%s" for repository "%s" cannot be autoloaded.', $boundEntity, $originalDef->class));
throw new Nette\Utils\AssertionException(sprintf('The entity "%s" for repository "%s" cannot be autoloaded.', $boundEntity, $originalDef->getClass()));
}
$entityArgument = $boundEntity;

} else {
$entityArgument = new Code\PhpLiteral('"%entityName%"');
$this->postCompileRepositoriesQueue[$boundManagers[0]][] = [ltrim($originalDef->class, '\\'), $originalServiceName];
$this->postCompileRepositoriesQueue[$boundManagers[0]][] = [ltrim($originalDef->getClass(), '\\'), $originalServiceName];
}

$builder->removeDefinition($originalServiceName);
$builder->addDefinition($originalServiceName)
->setClass($originalDef->class)
->setClass($originalDef->getClass())
->setFactory(sprintf('@%s::getRepository', $this->configuredManagers[$boundManagers[0]]), [$entityArgument]);

$serviceMap[$boundManagers[0]][$originalDef->class] = $factoryServiceName;
$serviceMap[$boundManagers[0]][$originalDef->getClass()] = $factoryServiceName;
}

foreach ($this->configuredManagers as $managerName => $_) {
Expand Down Expand Up @@ -772,7 +773,7 @@ protected function getServiceBoundManagers(Nette\DI\ServiceDefinition $def)

public function afterCompile(Code\ClassType $class)
{
$init = $class->methods['initialize'];
$init = $class->getMethod('initialize');

if ($this->isTracyPresent()) {
$init->addBody('Kdyby\Doctrine\Diagnostics\Panel::registerBluescreen($this);');
Expand Down

0 comments on commit cb548e0

Please sign in to comment.