Skip to content

Commit

Permalink
[AdminBundle][MultiDomainBundle] deprecated service container usage i…
Browse files Browse the repository at this point in the history
…n domain configuration
  • Loading branch information
Peter Zentjens committed May 29, 2018
1 parent cce25bc commit 10d1b32
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 23 deletions.
6 changes: 6 additions & 0 deletions UPGRADE-5.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ AdminBundle
-----------

* Passing the `logger` service as the second argument in `Kunstmaan\AdminBundle\Toolbar\BundleVersionDataCollector` is deprecated and will be removed in 6.0.
* Injecting the container in the `DomainConfiguration` is deprecated and will be removed in 6.0. Inject the required parameters instead.

AdminListBundle
---------------
Expand Down Expand Up @@ -33,6 +34,11 @@ MediaBundle
* `RenameSoftDeletedCommand::__construct()` now takes an instance of `Doctrine\ORM\EntityManagerInterface` as the first argument. Not passing it is deprecated and will throw a `TypeError` in 6.0.
* `CleanDeletedMediaCommand`, `CreatePdfPreviewCommand`, `RebuildFolderTreeCommand` and `RenameSoftDeletedCommand` have been marked as final.

MultiDomainBundle
-----------------

* Injecting the container in the `DomainConfiguration` is deprecated and will be removed in 6.0. Inject the required parameters instead.

NodeBundle
----------

Expand Down
41 changes: 26 additions & 15 deletions src/Kunstmaan/AdminBundle/Helper/DomainConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,32 @@ class DomainConfiguration implements DomainConfigurationInterface
protected $defaultLocale;

/**
* @param ContainerInterface $container
*/
public function __construct(ContainerInterface $container)
{
$this->container = $container;
$this->multiLanguage = $this->container->getParameter(
'multilanguage'
);
$this->defaultLocale = $this->container->getParameter(
'defaultlocale'
);
$this->requiredLocales = explode(
'|',
$this->container->getParameter('requiredlocales')
);
* @param ContainerInterface|string $multilanguage
*/
public function __construct(/*ContainerInterface|multilanguage string*/ $multilanguage, $defaultLocale = null, $requiredLocales = null)
{
if ($multilanguage instanceof ContainerInterface) {
@trigger_error('Container injection and the usage of the container is deprecated in KunstmaanNodeBundle 5.1 and will be removed in KunstmaanNodeBundle 6.0.', E_USER_DEPRECATED);

$this->container = $multilanguage;
$this->multiLanguage = $this->container->getParameter(
'multilanguage'
);
$this->defaultLocale = $this->container->getParameter(
'defaultlocale'
);
$this->requiredLocales = explode(
'|',
$this->container->getParameter('requiredlocales')
);

return;
}

$this->multiLanguage = $multilanguage;
$this->defaultLocale = $defaultLocale;

$this->requiredLocales = explode('|', $requiredLocales);
}

/**
Expand Down
28 changes: 20 additions & 8 deletions src/Kunstmaan/MultiDomainBundle/Helper/DomainConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Kunstmaan\MultiDomainBundle\Helper;

use Doctrine\ORM\EntityManagerInterface;
use Kunstmaan\AdminBundle\Helper\AdminRouteHelper;
use Kunstmaan\AdminBundle\Helper\DomainConfiguration as BaseDomainConfiguration;
use Kunstmaan\NodeBundle\Entity\Node;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand Down Expand Up @@ -32,22 +34,33 @@ class DomainConfiguration extends BaseDomainConfiguration
protected $adminRouteHelper;

/**
* @param ContainerInterface $container
* @param ContainerInterface|string $multilanguage
*/
public function __construct(ContainerInterface $container)
public function __construct(/*ContainerInterface|multilanguage string*/ $multilanguage, $defaultLocale = null, $requiredLocales = null, AdminRouteHelper $adminRouteHelper = null, EntityManagerInterface $em = null, array $hosts = null)
{
parent::__construct($container);
parent::__construct($multilanguage, $defaultLocale, $requiredLocales);

if ($multilanguage instanceof ContainerInterface) {
@trigger_error('Container injection and the usage of the container is deprecated in KunstmaanNodeBundle 5.1 and will be removed in KunstmaanNodeBundle 6.0.', E_USER_DEPRECATED);

$this->container = $multilanguage;
$this->adminRouteHelper = $this->container->get('kunstmaan_admin.adminroute.helper');
$this->hosts = $this->container->getParameter('kunstmaan_multi_domain.hosts');
$this->em = $this->container->get('doctrine.orm.entity_manager');

} else {
$this->adminRouteHelper = $adminRouteHelper;
$this->hosts = $hosts;
$this->em = $em;
}

$this->hosts = $container->getParameter('kunstmaan_multi_domain.hosts');
foreach ($this->hosts as $host => $hostInfo) {
if (isset($hostInfo['aliases'])) {
foreach ($hostInfo['aliases'] as $alias) {
$this->aliases[$alias] = $host;
}
}
}

$this->adminRouteHelper = $container->get('kunstmaan_admin.adminroute.helper');
}

/**
Expand Down Expand Up @@ -165,8 +178,7 @@ public function getRootNode($host = null)
$host = $this->getRealHost($host);

$internalName = $this->hosts[$host]['root'];
$em = $this->container->get('doctrine.orm.entity_manager');
$nodeRepo = $em->getRepository('KunstmaanNodeBundle:Node');
$nodeRepo = $this->em->getRepository('KunstmaanNodeBundle:Node');
$this->rootNode = $nodeRepo->getNodeByInternalName($internalName);
}

Expand Down

0 comments on commit 10d1b32

Please sign in to comment.