Refactor the factories so that they don't use the container.

This commit is contained in:
David Molineus
2017-10-18 08:27:49 +02:00
parent 60306459d2
commit 5501887231
3 changed files with 129 additions and 29 deletions

View File

@@ -83,7 +83,11 @@ services:
netzmacht.contao_leaflet.frontend.element_factory: netzmacht.contao_leaflet.frontend.element_factory:
class: Netzmacht\Contao\Leaflet\Frontend\ContentElement\MapElementFactory class: Netzmacht\Contao\Leaflet\Frontend\ContentElement\MapElementFactory
arguments: arguments:
- '@service_container' - '@templating'
- '@translator'
- '@netzmacht.contao_leaflet.map.provider'
- '@netzmacht.contao_toolkit.contao.input_adapter'
- '@netzmacht.contao_toolkit.contao.config_adapter'
tags: tags:
- { name: 'netzmacht.contao_toolkit.component.content_element_factory' } - { name: 'netzmacht.contao_toolkit.component.content_element_factory' }
- { name: 'netzmacht.contao_toolkit.component.content_element', alias: 'leaflet', category: 'includes' } - { name: 'netzmacht.contao_toolkit.component.content_element', alias: 'leaflet', category: 'includes' }
@@ -91,7 +95,11 @@ services:
netzmacht.contao_leaflet.frontend.module_factory: netzmacht.contao_leaflet.frontend.module_factory:
class: Netzmacht\Contao\Leaflet\Frontend\Module\MapModuleFactory class: Netzmacht\Contao\Leaflet\Frontend\Module\MapModuleFactory
arguments: arguments:
- '@service_container' - '@templating'
- '@translator'
- '@netzmacht.contao_leaflet.map.provider'
- '@netzmacht.contao_toolkit.contao.input_adapter'
- '@netzmacht.contao_toolkit.contao.config_adapter'
tags: tags:
- { name: 'netzmacht.contao_toolkit.component.frontend_module_factory' } - { name: 'netzmacht.contao_toolkit.component.frontend_module_factory' }
- { name: 'netzmacht.contao_toolkit.component.frontend_module', alias: 'leaflet', category: 'includes' } - { name: 'netzmacht.contao_toolkit.component.frontend_module', alias: 'leaflet', category: 'includes' }

View File

@@ -14,9 +14,14 @@ declare(strict_types=1);
namespace Netzmacht\Contao\Leaflet\Frontend\ContentElement; namespace Netzmacht\Contao\Leaflet\Frontend\ContentElement;
use Contao\Config;
use Contao\CoreBundle\Framework\Adapter;
use Contao\Input;
use Netzmacht\Contao\Leaflet\MapProvider;
use Netzmacht\Contao\Toolkit\Component\Component; use Netzmacht\Contao\Toolkit\Component\Component;
use Netzmacht\Contao\Toolkit\Component\ComponentFactory; use Netzmacht\Contao\Toolkit\Component\ComponentFactory;
use Psr\Container\ContainerInterface as Container; use Symfony\Component\Templating\EngineInterface as TemplateEngine;
use Symfony\Component\Translation\TranslatorInterface as Translator;
/** /**
* Class MapElementFactory * Class MapElementFactory
@@ -26,20 +31,61 @@ use Psr\Container\ContainerInterface as Container;
class MapElementFactory implements ComponentFactory class MapElementFactory implements ComponentFactory
{ {
/** /**
* Dependency container. * Template engine.
* *
* @var Container * @var TemplateEngine
*/ */
private $container; private $templating;
/**
* Translator.
*
* @var Translator
*/
private $translator;
/**
* Map provider.
*
* @var MapProvider
*/
private $mapProvider;
/**
* Input adapter.
*
* @var Input|Adapter
*/
private $input;
/**
* Config adapter.
*
* @var Config|Adapter
*/
private $config;
/** /**
* MapElementFactory constructor. * MapElementFactory constructor.
* *
* @param Container $container Dependency container. * @param TemplateEngine $engine Template engine.
* @param Translator $translator Translator.
* @param MapProvider $mapProvider Map provider.
* @param Input|Adapter $input Input adapter.
* @param Config|Adapter $config Config adapter.
*/ */
public function __construct(Container $container) public function __construct(
{ TemplateEngine $engine,
$this->container = $container; Translator $translator,
MapProvider $mapProvider,
$input,
$config
) {
$this->templating = $engine;
$this->translator = $translator;
$this->mapProvider = $mapProvider;
$this->input = $input;
$this->config = $config;
} }
/** /**
@@ -57,11 +103,11 @@ class MapElementFactory implements ComponentFactory
{ {
return new MapElement( return new MapElement(
$model, $model,
$this->container->get('templating'), $this->templating,
$this->container->get('translator'), $this->translator,
$this->container->get('netzmacht.contao_leaflet.map.provider'), $this->mapProvider,
$this->container->get('netzmacht.contao_toolkit.contao.input_adapter'), $this->input,
$this->container->get('netzmacht.contao_toolkit.contao.config_adapter'), $this->config,
$column $column
); );
} }

View File

@@ -14,9 +14,14 @@ declare(strict_types=1);
namespace Netzmacht\Contao\Leaflet\Frontend\Module; namespace Netzmacht\Contao\Leaflet\Frontend\Module;
use Contao\Config;
use Contao\CoreBundle\Framework\Adapter;
use Contao\Input;
use Netzmacht\Contao\Leaflet\MapProvider;
use Netzmacht\Contao\Toolkit\Component\Component; use Netzmacht\Contao\Toolkit\Component\Component;
use Netzmacht\Contao\Toolkit\Component\ComponentFactory; use Netzmacht\Contao\Toolkit\Component\ComponentFactory;
use Psr\Container\ContainerInterface as Container; use Symfony\Component\Templating\EngineInterface as TemplateEngine;
use Symfony\Component\Translation\TranslatorInterface as Translator;
/** /**
* Class MapElementFactory * Class MapElementFactory
@@ -26,20 +31,61 @@ use Psr\Container\ContainerInterface as Container;
class MapModuleFactory implements ComponentFactory class MapModuleFactory implements ComponentFactory
{ {
/** /**
* Dependency container. * Template engine.
* *
* @var Container * @var TemplateEngine
*/ */
private $container; private $templating;
/** /**
* MapModuleFactory constructor. * Translator.
* *
* @param Container $container Dependency container. * @var Translator
*/ */
public function __construct(Container $container) private $translator;
{
$this->container = $container; /**
* Map provider.
*
* @var MapProvider
*/
private $mapProvider;
/**
* Input adapter.
*
* @var Input|Adapter
*/
private $input;
/**
* Config adapter.
*
* @var Config|Adapter
*/
private $config;
/**
* MapElementFactory constructor.
*
* @param TemplateEngine $engine Template engine.
* @param Translator $translator Translator.
* @param MapProvider $mapProvider Map provider.
* @param Input|Adapter $input Input adapter.
* @param Config|Adapter $config Config adapter.
*/
public function __construct(
TemplateEngine $engine,
Translator $translator,
MapProvider $mapProvider,
$input,
$config
) {
$this->templating = $engine;
$this->translator = $translator;
$this->mapProvider = $mapProvider;
$this->input = $input;
$this->config = $config;
} }
/** /**
@@ -57,11 +103,11 @@ class MapModuleFactory implements ComponentFactory
{ {
return new MapModule( return new MapModule(
$model, $model,
$this->container->get('templating'), $this->templating,
$this->container->get('translator'), $this->translator,
$this->container->get('netzmacht.contao_leaflet.map.provider'), $this->mapProvider,
$this->container->get('netzmacht.contao_toolkit.contao.input_adapter'), $this->input,
$this->container->get('netzmacht.contao_toolkit.contao.config_adapter'), $this->config,
$column $column
); );
} }