diff --git a/src/Dca/LeafletCallbacks.php b/src/Listener/Dca/LeafletDcaListener.php similarity index 73% rename from src/Dca/LeafletCallbacks.php rename to src/Listener/Dca/LeafletDcaListener.php index 77f0c23..911afdf 100644 --- a/src/Dca/LeafletCallbacks.php +++ b/src/Listener/Dca/LeafletDcaListener.php @@ -10,46 +10,44 @@ * @filesource */ -namespace Netzmacht\Contao\Leaflet\Dca; +namespace Netzmacht\Contao\Leaflet\Listener\Dca; +use Contao\DataContainer; use Netzmacht\Contao\Leaflet\Model\LayerModel; -use Netzmacht\Contao\Toolkit\Dca\Callback\CallbackFactory; use Netzmacht\LeafletPHP\Value\LatLng; +use Symfony\Component\Filesystem\Filesystem; /** * Class Leaflet is the base helper providing different methods. * * @package Netzmacht\Contao\Leaflet\Dca */ -class LeafletCallbacks +class LeafletDcaListener { /** * File system. * - * @var \Files + * @var Filesystem */ private $fileSystem; /** - * LeafletCallbacks constructor. + * Cache dir. * - * @param \Files $fileSystem File system. + * @var string */ - public function __construct(\Files $fileSystem) - { - $this->fileSystem = $fileSystem; - } + private $cacheDir; /** - * Generate the callback definition. + * LeafletCallbacks constructor. * - * @param string $methodName Callback method name. - * - * @return callable + * @param Filesystem $fileSystem File system. + * @param string $cacheDir Cache dir. */ - public static function callback($methodName) + public function __construct(Filesystem $fileSystem, string $cacheDir) { - return CallbackFactory::service('leaflet.dca.common', $methodName); + $this->fileSystem = $fileSystem; + $this->cacheDir = $cacheDir; } /** @@ -65,7 +63,7 @@ class LeafletCallbacks /** * Get the geocoder wizard. * - * @param \DataContainer $dataContainer The dataContainer driver. + * @param DataContainer $dataContainer The dataContainer driver. * * @return string */ @@ -78,10 +76,9 @@ class LeafletCallbacks $latLng = LatLng::fromString($dataContainer->value); $template->marker = json_encode($latLng); } catch (\Exception $e) { - // LatLng throws an exeption of value could not be created. Just let the value empty when. + // LatLng throws an exception of value could not be created. Just let the value empty when. } - return $template->parse(); } @@ -113,7 +110,7 @@ class LeafletCallbacks */ public function clearCache($value = null) { - $this->fileSystem->rrdir('system/cache/leaflet', true); + $this->fileSystem->remove($this->cacheDir); return $value; } diff --git a/src/Resources/config/listeners.yml b/src/Resources/config/listeners.yml index 983ed06..c689984 100644 --- a/src/Resources/config/listeners.yml +++ b/src/Resources/config/listeners.yml @@ -1,4 +1,10 @@ services: + netzmacht.contao_leaflet_maps.listeners.dca.leaflet: + class: Netzmacht\Contao\Leaflet\Listener\Dca\LeafletDcaListener + arguments: + - '@filesystem' + - '%netzmacht.contao_leaflet_maps.cache_dir%' + netzmacht.contao_leaflet_maps.listeners.dca.map: class: Netzmacht\Contao\Leaflet\Listener\Dca\MapDcaListener arguments: diff --git a/src/Resources/contao/dca/tl_leaflet_control.php b/src/Resources/contao/dca/tl_leaflet_control.php index cdf1517..a4aca37 100644 --- a/src/Resources/contao/dca/tl_leaflet_control.php +++ b/src/Resources/contao/dca/tl_leaflet_control.php @@ -27,7 +27,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_control'] = array ) ), 'onsubmit_callback' => [ - \Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('clearCache'), + ['netzmacht.contao_leaflet_maps.listeners.dca.leaflet', 'clearCache'], ], ), @@ -227,7 +227,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_control'] = array 'eval' => array('tl_class' => 'w50'), 'sql' => "char(1) NOT NULL default ''", 'save_callback' => [ - \Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('clearCache'), + ['netzmacht.contao_leaflet_maps.listeners.dca.leaflet', 'clearCache'], ], ), 'zoomInText' => array diff --git a/src/Resources/contao/dca/tl_leaflet_icon.php b/src/Resources/contao/dca/tl_leaflet_icon.php index 4925ed5..6647127 100644 --- a/src/Resources/contao/dca/tl_leaflet_icon.php +++ b/src/Resources/contao/dca/tl_leaflet_icon.php @@ -24,7 +24,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_icon'] = array ) ), 'onsubmit_callback' => [ - \Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('clearCache'), + ['netzmacht.contao_leaflet_maps.listeners.dca.leaflet', 'clearCache'], ], ), @@ -228,7 +228,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_icon'] = array 'eval' => array('tl_class' => 'w50'), 'sql' => "char(1) NOT NULL default ''", 'save_callback' => [ - \Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('clearCache'), + ['netzmacht.contao_leaflet_maps.listeners.dca.leaflet', 'clearCache'], ], ), 'iconImage' => array diff --git a/src/Resources/contao/dca/tl_leaflet_layer.php b/src/Resources/contao/dca/tl_leaflet_layer.php index a92d6a3..822d0d4 100644 --- a/src/Resources/contao/dca/tl_leaflet_layer.php +++ b/src/Resources/contao/dca/tl_leaflet_layer.php @@ -31,7 +31,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = [ }, ], 'onsubmit_callback' => [ - \Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('clearCache'), + ['netzmacht.contao_leaflet_maps.listeners.dca.leaflet', 'clearCache'], ], ], 'list' => [ @@ -294,7 +294,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = [ 'eval' => ['tl_class' => 'w50'], 'sql' => "char(1) NOT NULL default ''", 'save_callback' => [ - \Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('clearCache'), + ['netzmacht.contao_leaflet_maps.listeners.dca.leaflet', 'clearCache'], ], ], 'tile_provider' => [ @@ -452,7 +452,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = [ 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['disableClusteringAtZoom'], 'exclude' => true, 'inputType' => 'select', - 'options_callback' => Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('getZoomLevels'), + 'options_callback' => ['netzmacht.contao_leaflet_maps.listeners.dca.leaflet', 'getZoomLevels'], 'default' => '', 'eval' => [ 'maxlength' => 4, @@ -541,7 +541,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = [ 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['minZoom'], 'exclude' => true, 'inputType' => 'select', - 'options_callback' => Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('getZoomLevels'), + 'options_callback' => ['netzmacht.contao_leaflet_maps.listeners.dca.leaflet', 'getZoomLevels'], 'eval' => [ 'maxlength' => 4, 'rgxp' => 'digit', @@ -555,7 +555,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = [ 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['maxZoom'], 'exclude' => true, 'inputType' => 'select', - 'options_callback' => Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('getZoomLevels'), + 'options_callback' => ['netzmacht.contao_leaflet_maps.listeners.dca.leaflet', 'getZoomLevels'], 'eval' => [ 'maxlength' => 4, 'rgxp' => 'digit', @@ -569,7 +569,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = [ 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['maxNativeZoom'], 'exclude' => true, 'inputType' => 'select', - 'options_callback' => Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('getZoomLevels'), + 'options_callback' => ['netzmacht.contao_leaflet_maps.listeners.dca.leaflet', 'getZoomLevels'], 'eval' => [ 'maxlength' => 4, 'rgxp' => 'digit', diff --git a/src/Resources/contao/dca/tl_leaflet_map.php b/src/Resources/contao/dca/tl_leaflet_map.php index edf1964..00f69d1 100644 --- a/src/Resources/contao/dca/tl_leaflet_map.php +++ b/src/Resources/contao/dca/tl_leaflet_map.php @@ -30,7 +30,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array } ), 'onsubmit_callback' => [ - \Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('clearCache'), + ['netzmacht.contao_leaflet_maps.listeners.dca.leaflet', 'clearCache'], ], ), @@ -194,7 +194,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array \Netzmacht\Contao\Leaflet\Dca\Validator::callback('validateCoordinates'), ), 'wizard' => array( - Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('getGeocoder') + ['netzmacht.contao_leaflet_maps.listeners.dca.leaflet', 'getGeocoder'] ), 'eval' => array( 'maxlength' => 255, @@ -243,7 +243,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_map']['zoom'], 'exclude' => true, 'inputType' => 'select', - 'options_callback' => Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('getZoomLevels'), + 'options_callback' => ['netzmacht.contao_leaflet_maps.listeners.dca.leaflet', 'getZoomLevels'], 'default' => '', 'eval' => array( 'maxlength' => 4, @@ -268,7 +268,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_map']['minZoom'], 'exclude' => true, 'inputType' => 'select', - 'options_callback' => Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('getZoomLevels'), + 'options_callback' => ['netzmacht.contao_leaflet_maps.listeners.dca.leaflet', 'getZoomLevels'], 'eval' => array( 'maxlength' => 4, 'rgxp' => 'digit', @@ -283,7 +283,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_map']['maxZoom'], 'exclude' => true, 'inputType' => 'select', - 'options_callback' => Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('getZoomLevels'), + 'options_callback' => ['netzmacht.contao_leaflet_maps.listeners.dca.leaflet', 'getZoomLevels'], 'eval' => array( 'maxlength' => 4, 'rgxp' => 'digit', @@ -555,7 +555,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_map']['locateMaxZoom'], 'exclude' => true, 'inputType' => 'select', - 'options_callback' => Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('getZoomLevels'), + 'options_callback' => ['netzmacht.contao_leaflet_maps.listeners.dca.leaflet', 'getZoomLevels'], 'eval' => array( 'maxlength' => 4, 'rgxp' => 'digit', diff --git a/src/Resources/contao/dca/tl_leaflet_marker.php b/src/Resources/contao/dca/tl_leaflet_marker.php index cc8c3ba..7993df9 100644 --- a/src/Resources/contao/dca/tl_leaflet_marker.php +++ b/src/Resources/contao/dca/tl_leaflet_marker.php @@ -29,7 +29,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_marker'] = array ['netzmacht.contao_leaflet_maps.listeners.dca.marker', 'initialize'], ), 'onsubmit_callback' => [ - \Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('clearCache'), + ['netzmacht.contao_leaflet_maps.listeners.dca.leaflet', 'clearCache'], ], ), @@ -199,7 +199,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_marker'] = array array('netzmacht.contao_leaflet_maps.listeners.dca.marker', 'loadCoordinates') ), 'wizard' => array( - Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('getGeocoder') + ['netzmacht.contao_leaflet_maps.listeners.dca.leaflet', 'getGeocoder'] ), 'eval' => array( 'maxlength' => 255, @@ -243,7 +243,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_marker'] = array 'eval' => array('tl_class' => 'w50'), 'sql' => "char(1) NOT NULL default ''", 'save_callback' => [ - \Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('clearCache'), + ['netzmacht.contao_leaflet_maps.listeners.dca.leaflet', 'clearCache'], ], ), 'tooltip' => array diff --git a/src/Resources/contao/dca/tl_leaflet_popup.php b/src/Resources/contao/dca/tl_leaflet_popup.php index 36809b8..afee0b4 100644 --- a/src/Resources/contao/dca/tl_leaflet_popup.php +++ b/src/Resources/contao/dca/tl_leaflet_popup.php @@ -24,7 +24,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_popup'] = array ) ), 'onsubmit_callback' => [ - \Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('clearCache'), + ['netzmacht.contao_leaflet_maps.listeners.dca.leaflet', 'clearCache'], ], ), @@ -297,7 +297,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_popup'] = array 'eval' => array('tl_class' => 'w50'), 'sql' => "char(1) NOT NULL default ''", 'save_callback' => [ - \Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('clearCache'), + ['netzmacht.contao_leaflet_maps.listeners.dca.leaflet', 'clearCache'], ], ), ), diff --git a/src/Resources/contao/dca/tl_leaflet_style.php b/src/Resources/contao/dca/tl_leaflet_style.php index 4b2641e..36aa0a0 100644 --- a/src/Resources/contao/dca/tl_leaflet_style.php +++ b/src/Resources/contao/dca/tl_leaflet_style.php @@ -24,7 +24,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_style'] = array ) ), 'onsubmit_callback' => [ - \Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('clearCache'), + ['netzmacht.contao_leaflet_maps.listeners.dca.leaflet', 'clearCache'], ], ), @@ -305,7 +305,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_style'] = array 'eval' => array('tl_class' => 'w50'), 'sql' => "char(1) NOT NULL default ''", 'save_callback' => [ - \Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('clearCache'), + ['netzmacht.contao_leaflet_maps.listeners.dca.leaflet', 'clearCache'], ], ), ), diff --git a/src/Resources/contao/dca/tl_leaflet_vector.php b/src/Resources/contao/dca/tl_leaflet_vector.php index 9429dca..405af7e 100644 --- a/src/Resources/contao/dca/tl_leaflet_vector.php +++ b/src/Resources/contao/dca/tl_leaflet_vector.php @@ -31,7 +31,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_vector'] = array } ), 'onsubmit_callback' => [ - \Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('clearCache'), + ['netzmacht.contao_leaflet_maps.listeners.dca.leaflet', 'clearCache'], ], ), @@ -247,7 +247,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_vector'] = array 'eval' => array('tl_class' => 'w50'), 'sql' => "char(1) NOT NULL default ''", 'save_callback' => [ - \Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('clearCache'), + ['netzmacht.contao_leaflet_maps.listeners.dca.leaflet', 'clearCache'], ], ), 'addPopup' => array @@ -322,7 +322,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_vector'] = array \Netzmacht\Contao\Leaflet\Dca\Validator::callback('validateCoordinates') ), 'wizard' => array( - Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('getGeocoder') + ['netzmacht.contao_leaflet_maps.listeners.dca.leaflet', 'getGeocoder'] ), 'eval' => array( 'maxlength' => 255,