forked from Snck3rs/contao-leaflet-maps
Work on service definitions.
This commit is contained in:
66
src/Alias/DefaultAliasGeneratorFactory.php
Normal file
66
src/Alias/DefaultAliasGeneratorFactory.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Leaflet maps for Contao CMS.
|
||||
*
|
||||
* @package contao-leaflet-maps
|
||||
* @author David Molineus <david.molineus@netzmacht.de>
|
||||
* @copyright 2016-2017 netzmacht David Molineus. All rights reserved.
|
||||
* @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-maps/blob/master/LICENSE
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Alias;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Netzmacht\Contao\Toolkit\Data\Alias\AliasGenerator;
|
||||
use Netzmacht\Contao\Toolkit\Data\Alias\Factory\AliasGeneratorFactory;
|
||||
use Netzmacht\Contao\Toolkit\Data\Alias\Filter\ExistingAliasFilter;
|
||||
use Netzmacht\Contao\Toolkit\Data\Alias\Filter\SlugifyFilter;
|
||||
use Netzmacht\Contao\Toolkit\Data\Alias\Filter\SuffixFilter;
|
||||
use Netzmacht\Contao\Toolkit\Data\Alias\FilterBasedAliasGenerator;
|
||||
use Netzmacht\Contao\Toolkit\Data\Alias\Validator\UniqueDatabaseValueValidator;
|
||||
|
||||
/**
|
||||
* Class DefaultAliasGeneratorFactory.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Alias
|
||||
*/
|
||||
class DefaultAliasGeneratorFactory implements AliasGeneratorFactory
|
||||
{
|
||||
/**
|
||||
* Database connection.
|
||||
*
|
||||
* @var Connection
|
||||
*/
|
||||
private $connection;
|
||||
|
||||
/**
|
||||
* DefaultAliasGeneratorFactory constructor.
|
||||
*
|
||||
* @param Connection $connection Database connection.
|
||||
*/
|
||||
public function __construct(Connection $connection)
|
||||
{
|
||||
$this->connection = $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function create(string $dataContainerName, string $aliasField, array $fields): AliasGenerator
|
||||
{
|
||||
$filters = [
|
||||
new ExistingAliasFilter(),
|
||||
new SlugifyFilter($fields),
|
||||
new DefaultAliasFilter($dataContainerName),
|
||||
new SuffixFilter(),
|
||||
];
|
||||
|
||||
$validator = new UniqueDatabaseValueValidator($this->connection, $dataContainerName, $aliasField);
|
||||
|
||||
return new FilterBasedAliasGenerator($filters, $validator, $dataContainerName, $aliasField, '_');
|
||||
}
|
||||
}
|
||||
66
src/Alias/ParentAliasGeneratorFactory.php
Normal file
66
src/Alias/ParentAliasGeneratorFactory.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Leaflet maps for Contao CMS.
|
||||
*
|
||||
* @package contao-leaflet-maps
|
||||
* @author David Molineus <david.molineus@netzmacht.de>
|
||||
* @copyright 2016-2017 netzmacht David Molineus. All rights reserved.
|
||||
* @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-maps/blob/master/LICENSE
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Alias;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Netzmacht\Contao\Toolkit\Data\Alias\AliasGenerator;
|
||||
use Netzmacht\Contao\Toolkit\Data\Alias\Factory\AliasGeneratorFactory;
|
||||
use Netzmacht\Contao\Toolkit\Data\Alias\Filter\ExistingAliasFilter;
|
||||
use Netzmacht\Contao\Toolkit\Data\Alias\Filter\SlugifyFilter;
|
||||
use Netzmacht\Contao\Toolkit\Data\Alias\Filter\SuffixFilter;
|
||||
use Netzmacht\Contao\Toolkit\Data\Alias\FilterBasedAliasGenerator;
|
||||
use Netzmacht\Contao\Toolkit\Data\Alias\Validator\UniqueDatabaseValueValidator;
|
||||
|
||||
/**
|
||||
* Alias generator validating against the parent id (pid).
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Alias
|
||||
*/
|
||||
class ParentAliasGeneratorFactory implements AliasGeneratorFactory
|
||||
{
|
||||
/**
|
||||
* Database connection.
|
||||
*
|
||||
* @var Connection
|
||||
*/
|
||||
private $connection;
|
||||
|
||||
/**
|
||||
* DefaultAliasGeneratorFactory constructor.
|
||||
*
|
||||
* @param Connection $connection Database connection.
|
||||
*/
|
||||
public function __construct(Connection $connection)
|
||||
{
|
||||
$this->connection = $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function create(string $dataContainerName, string $aliasField, array $fields): AliasGenerator
|
||||
{
|
||||
$filters = [
|
||||
new ExistingAliasFilter(),
|
||||
new SlugifyFilter($fields),
|
||||
new DefaultAliasFilter($dataContainerName),
|
||||
new SuffixFilter(),
|
||||
];
|
||||
|
||||
$validator = new UniqueDatabaseValueValidator($this->connection, $dataContainerName, $aliasField, ['pid']);
|
||||
|
||||
return new FilterBasedAliasGenerator($filters, $validator, $dataContainerName, $aliasField, '_');
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,9 @@
|
||||
# The encoders transforms the definitions into javascript. The encoders has to be an implementation of the
|
||||
# EventSubscriberInterface of the event dispatcher.
|
||||
services:
|
||||
_defaults:
|
||||
public: false
|
||||
|
||||
netzmacht.contao_leaflet_maps.encoder.map:
|
||||
class: Netzmacht\LeafletPHP\Encoder\MapEncoder
|
||||
tags:
|
||||
|
||||
@@ -1,6 +1,75 @@
|
||||
parameters:
|
||||
netzmacht.contao_leaflet_maps.cache_dir: '%kernel.cache_dir%/leaflet'
|
||||
|
||||
# JSON_UNESCAPED_SLASHES ^ Netzmacht\JavascriptBuilder\Flags::BUILD_STACK
|
||||
netzmacht.contao_leaflet_maps.encoding_flags: 16448
|
||||
|
||||
services:
|
||||
netzmacht.contao_leaflet_maps.map.provider:
|
||||
class: Netzmacht\Contao\Leaflet\MapProvider
|
||||
arguments:
|
||||
- '@netzmacht.contao_leaflet_maps.definition.mapper'
|
||||
- '@netzmacht.contao_leaflet_maps.definition.builder'
|
||||
- '@event_dispatcher'
|
||||
- '@netzmacht.contao_toolkit.contao.input'
|
||||
- '@netzmacht.contao_leaflet_maps.map.assets'
|
||||
- '@netzmacht.contao_leaflet_maps.cache'
|
||||
- '' # TODO: Rework filter handling.
|
||||
- '%kernel.debug%'
|
||||
|
||||
netzmacht.contao_leaflet_maps.cache:
|
||||
alias: 'netzmacht.contao_leaflet_maps.cache.default'
|
||||
|
||||
netzmacht.contao_leaflet_maps.cache.default:
|
||||
class: Doctrine\Common\Cache\FilesystemCache
|
||||
arguments:
|
||||
- '%netzmacht.contao_leaflet_maps.cache_dir%'
|
||||
|
||||
netzmacht.contao_leaflet_maps.cache.debug:
|
||||
class: Doctrine\Common\Cache\ArrayCache
|
||||
|
||||
netzmacht.contao_leaflet_maps.frontend.value_filter:
|
||||
class:
|
||||
class: Netzmacht\Contao\Leaflet\Frontend\ValueFilter
|
||||
arguments:
|
||||
- '@netzmacht.contao_toolkit.insert_tag.replacer'
|
||||
|
||||
netzmacht.contao_leaflet_maps.map.assets:
|
||||
class:
|
||||
class: Netzmacht\Contao\Leaflet\ContaoAssets
|
||||
arguments:
|
||||
- '@netzmacht.contao_toolkit.assets_manager'
|
||||
|
||||
netzmacht.contao_leaflet_maps.definition.builder:
|
||||
class: Netzmacht\LeafletPHP\Leaflet
|
||||
arguments:
|
||||
- '@netzmacht.contao_leaflet_maps.definition.builder.javascript_builder'
|
||||
- '@netzmacht.contao_leaflet_maps.definition.builder.event_dispatcher'
|
||||
- []
|
||||
- '%netzmacht.contao_leaflet_maps.encoding_flags%'
|
||||
|
||||
netzmacht.contao_leaflet_maps.definition.builder.javascript_builder:
|
||||
class: Netzmacht\JavascriptBuilder\Builder
|
||||
arguments:
|
||||
- '@netzmacht.contao_leaflet_maps.definition.encoder_factory'
|
||||
|
||||
netzmacht.contao_leaflet_maps.definition.builder.event_dispatcher:
|
||||
class: Symfony\Component\EventDispatcher\EventDispatcher
|
||||
|
||||
netzmacht.contao_leaflet_maps.definition.mapper:
|
||||
class: Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper
|
||||
arguments:
|
||||
- '@event_dispatcher'
|
||||
|
||||
netzmacht.contao_leaflet_maps.definition.encoder_factory:
|
||||
class: Netzmacht\Contao\Leaflet\Encoder\EncoderFactory
|
||||
arguments:
|
||||
- '@netzmacht.contao_leaflet_maps.definition.builder.event_dispatcher'
|
||||
|
||||
netzmacht.contao_leaflet_maps.definition.alias_generator.factory_default:
|
||||
class: Netzmacht\Contao\Leaflet\Alias\DefaultAliasGeneratorFactory
|
||||
arguments:
|
||||
- '@database_connection'
|
||||
|
||||
netzmacht.contao_leaflet_maps.definition.alias_generator.factory_parent:
|
||||
class: Netzmacht\Contao\Leaflet\Alias\ParentAliasGeneratorFactory
|
||||
arguments:
|
||||
- '@database_connection'
|
||||
|
||||
Reference in New Issue
Block a user