From 082ba4f5687ac4b745b4f0ca74cd9cc319e0ae2e Mon Sep 17 00:00:00 2001 From: David Molineus Date: Thu, 8 Jan 2015 22:56:23 +0100 Subject: [PATCH] Make mapper interface independent from Contao models. --- src/Netzmacht/Contao/Leaflet/Mapper/AbstractMapper.php | 8 +++++--- .../Contao/Leaflet/Mapper/AbstractTypeMapper.php | 4 +++- src/Netzmacht/Contao/Leaflet/Mapper/Mapper.php | 9 +++++---- .../Leaflet/Mapper/Vector/AbstractVectorMapper.php | 3 +-- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/AbstractMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/AbstractMapper.php index 459908a..12f8e72 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/AbstractMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/AbstractMapper.php @@ -15,7 +15,9 @@ use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds; /** - * Class AbstractMapper. + * Class AbstractMapper is made for mapping Contao models to the definition. + * + * For custom sources besides Contao models use your own implementation of the mapper interface. * * @package Netzmacht\Contao\Leaflet\Mapper */ @@ -149,7 +151,7 @@ abstract class AbstractMapper implements Mapper /** * {@inheritdoc} */ - public function handle(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null) + public function handle($model, DefinitionMapper $mapper, LatLngBounds $bounds = null) { $definition = $this->createInstance($model, $mapper, $bounds); @@ -163,7 +165,7 @@ abstract class AbstractMapper implements Mapper /** * {@inheritdoc} */ - public function match(\Model $model) + public function match($model, LatLngBounds $bounds = null) { $modelClass = static::$modelClass; diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/AbstractTypeMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/AbstractTypeMapper.php index 8a16af6..0405066 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/AbstractTypeMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/AbstractTypeMapper.php @@ -11,12 +11,14 @@ namespace Netzmacht\Contao\Leaflet\Mapper; +use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds; + abstract class AbstractTypeMapper extends AbstractMapper { protected static $type; - public function match(\Model $model) + public function match($model, LatLngBounds $bounds = null) { return parent::match($model) && $model->type === static::$type; } diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/Mapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/Mapper.php index c26ecfd..4637310 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/Mapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/Mapper.php @@ -19,20 +19,21 @@ interface Mapper /** * Map model to the definition. * - * @param \Model $model The model being built. + * @param \Model|mixed $model The model being built. Usually a contao model. but can be anything * @param DefinitionMapper $mapper The definition builder. * @param LatLngBounds $bounds Optional bounds where elements should be in. * * @return Definition */ - public function handle(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null); + public function handle($model, DefinitionMapper $mapper, LatLngBounds $bounds = null); /** * Check if mapper is responsible for the model. * - * @param \Model $model The model being build. + * @param \Model $model The model being build. + * @param LatLngBounds $bounds Optional bounds where elements should be in. * * @return bool */ - public function match(\Model $model); + public function match($model, LatLngBounds $bounds = null); } diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/Vector/AbstractVectorMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/Vector/AbstractVectorMapper.php index d29fefb..052d5e2 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/Vector/AbstractVectorMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/Vector/AbstractVectorMapper.php @@ -16,7 +16,6 @@ use Netzmacht\Contao\Leaflet\Mapper\AbstractTypeMapper; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds; -use Netzmacht\LeafletPHP\Definition\Vector\Path; class AbstractVectorMapper extends AbstractTypeMapper { @@ -49,7 +48,7 @@ class AbstractVectorMapper extends AbstractTypeMapper ) { parent::build($definition, $model, $builder, $bounds); - if ($model->addPopup) { + if ($definition instanceof Definition\HasPopup && $model->addPopup) { $definition->bindPopup($model->popupContent); } }