Make mapper interface independent from Contao models.

This commit is contained in:
David Molineus
2015-01-08 22:56:23 +01:00
parent 46d261a7a1
commit 082ba4f568
4 changed files with 14 additions and 10 deletions

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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);
}

View File

@@ -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);
}
}