Skip to content

Commit

Permalink
Merge pull request #108 from Jean-Beru/fix-addClassesToCompile-deprec…
Browse files Browse the repository at this point in the history
…ation

Fix addClassesToCompile deprecation
  • Loading branch information
francisbesset authored Feb 6, 2018
2 parents dbca4a9 + cc82062 commit 83d2cf7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
30 changes: 17 additions & 13 deletions src/DependencyInjection/BeSimpleI18nRoutingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ public function load(array $configs, ContainerBuilder $container)
$this->configureRouteNameInflector($config, $container);
$this->configureAnnotations($config, $container, $loader);

$this->addClassesToCompile(array(
'BeSimple\\I18nRoutingBundle\\Routing\\Router',
'BeSimple\\I18nRoutingBundle\\Routing\\RouteGenerator\\NameInflector\\RouteNameInflectorInterface'
));
if (PHP_VERSION_ID < 70000) {
$this->addClassesToCompile(array(
'BeSimple\\I18nRoutingBundle\\Routing\\Router',
'BeSimple\\I18nRoutingBundle\\Routing\\RouteGenerator\\NameInflector\\RouteNameInflectorInterface'
));
}
}

/**
Expand Down Expand Up @@ -175,16 +177,18 @@ private function configureRouteNameInflector(array $config, ContainerBuilder $co
$container->setAlias('be_simple_i18n_routing.route_name_inflector', $config['route_name_inflector']);
}

// Try and register the route name inflector to compilation/caching
try {
$def = $container->findDefinition('be_simple_i18n_routing.route_name_inflector');
if ($def->getClass() !== null) {
$this->addClassesToCompile(array($def->getClass()));
if (PHP_VERSION_ID < 70000) {
// Try and register the route name inflector to compilation/caching
try {
$def = $container->findDefinition('be_simple_i18n_routing.route_name_inflector');
if ($def->getClass() !== null) {
$this->addClassesToCompile(array($def->getClass()));
}
} catch (ServiceNotFoundException $e) {
// This happens when the alias is set to a external service
} catch (InvalidArgumentException $e) {
// This happens when the alias is set to a external service in Symfony 2.3
}
} catch (ServiceNotFoundException $e) {
// This happens when the alias is set to a external service
} catch (InvalidArgumentException $e) {
// This happens when the alias is set to a external service in Symfony 2.3
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function loading_with_default_values()
$classesToCompile = $this->container->getExtension('be_simple_i18n_routing')->getClassesToCompile();
$this->assertEquals(
$classesToCompile,
array(
PHP_VERSION_ID >= 70000 ? array() : array(
'BeSimple\\I18nRoutingBundle\\Routing\\RouteGenerator\\NameInflector\\PostfixInflector',
'BeSimple\\I18nRoutingBundle\\Routing\\Router',
'BeSimple\\I18nRoutingBundle\\Routing\\RouteGenerator\\NameInflector\\RouteNameInflectorInterface',
Expand Down Expand Up @@ -80,7 +80,7 @@ public function loading_with_route_name_inflector()

$this->assertEquals(
$this->container->getExtension('be_simple_i18n_routing')->getClassesToCompile(),
array(
PHP_VERSION_ID >= 70000 ? array() : array(
'BeSimple\\I18nRoutingBundle\\Routing\\Router',
'BeSimple\\I18nRoutingBundle\\Routing\\RouteGenerator\\NameInflector\\RouteNameInflectorInterface'
)
Expand Down

0 comments on commit 83d2cf7

Please sign in to comment.