Add parent to mapper handle method.

This commit is contained in:
David Molineus
2015-01-20 16:38:23 +01:00
parent 2496994759
commit 762e6b5dbc
19 changed files with 77 additions and 42 deletions

View File

@@ -151,13 +151,18 @@ abstract class AbstractMapper implements Mapper
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function handle($model, DefinitionMapper $mapper, LatLngBounds $bounds = null, $elementId = null) public function handle(
{ $model,
DefinitionMapper $mapper,
LatLngBounds $bounds = null,
$elementId = null,
Definition $parent = null
) {
$definition = $this->createInstance($model, $mapper, $bounds, $elementId); $definition = $this->createInstance($model, $mapper, $bounds, $elementId);
$this->buildOptions($definition, $model); $this->buildOptions($definition, $model);
$this->buildConditionals($definition, $model); $this->buildConditionals($definition, $model);
$this->build($definition, $model, $mapper, $bounds); $this->build($definition, $model, $mapper, $bounds, $parent);
return $definition; return $definition;
} }
@@ -188,6 +193,7 @@ abstract class AbstractMapper implements Mapper
* @param \Model $model The model. * @param \Model $model The model.
* @param DefinitionMapper $mapper The definition mapper. * @param DefinitionMapper $mapper The definition mapper.
* @param LatLngBounds $bounds Optional bounds where elements should be in. * @param LatLngBounds $bounds Optional bounds where elements should be in.
* @param Definition|null $parent The parent object.
* *
* @return void * @return void
* *
@@ -197,7 +203,8 @@ abstract class AbstractMapper implements Mapper
Definition $definition, Definition $definition,
\Model $model, \Model $model,
DefinitionMapper $mapper, DefinitionMapper $mapper,
LatLngBounds $bounds = null LatLngBounds $bounds = null,
Definition $parent = null
) { ) {
} }

View File

@@ -53,8 +53,9 @@ class AttributionControlMapper extends AbstractControlMapper
protected function build( protected function build(
Definition $definition, Definition $definition,
\Model $model, \Model $model,
DefinitionMapper $builder, DefinitionMapper $mapper,
LatLngBounds $bounds = null LatLngBounds $bounds = null,
Definition $parent = null
) { ) {
if (!$definition instanceof Attribution) { if (!$definition instanceof Attribution) {
return; return;

View File

@@ -69,7 +69,8 @@ class LoadingControlMapper extends AbstractControlMapper
Definition $definition, Definition $definition,
\Model $model, \Model $model,
DefinitionMapper $mapper, DefinitionMapper $mapper,
LatLngBounds $bounds = null LatLngBounds $bounds = null,
Definition $parent = null
) { ) {
parent::build($definition, $model, $mapper, $bounds); parent::build($definition, $model, $mapper, $bounds);

View File

@@ -80,12 +80,13 @@ class DefinitionMapper
* @param mixed $model The definition model. * @param mixed $model The definition model.
* @param LatLngBounds $bounds Optional bounds where elements should be in. * @param LatLngBounds $bounds Optional bounds where elements should be in.
* @param string $elementId Optional element id. If none given the mapId or alias is used. * @param string $elementId Optional element id. If none given the mapId or alias is used.
* @param Definition|null $parent Optional pass the parent object.
* *
* @return Definition|null * @return Definition|null
* *
* @throws \RuntimeException If model could not be mapped to a definition. * @throws \RuntimeException If model could not be mapped to a definition.
*/ */
public function handle($model, LatLngBounds $bounds = null, $elementId = null) public function handle($model, LatLngBounds $bounds = null, $elementId = null, $parent = null)
{ {
$hash = $this->getHash($model, $elementId); $hash = $this->getHash($model, $elementId);
@@ -96,7 +97,7 @@ class DefinitionMapper
foreach ($this->builders as $builders) { foreach ($this->builders as $builders) {
foreach ($builders as $builder) { foreach ($builders as $builder) {
if ($builder->match($model)) { if ($builder->match($model)) {
$definition = $builder->handle($model, $this, $bounds, $elementId); $definition = $builder->handle($model, $this, $bounds, $elementId, $parent);
if ($definition) { if ($definition) {
$event = new BuildDefinitionEvent($definition, $model, $bounds); $event = new BuildDefinitionEvent($definition, $model, $bounds);

View File

@@ -58,7 +58,8 @@ class GroupLayerMapper extends AbstractLayerMapper
Definition $definition, Definition $definition,
\Model $model, \Model $model,
DefinitionMapper $mapper, DefinitionMapper $mapper,
LatLngBounds $bounds = null LatLngBounds $bounds = null,
Definition $parent = null
) { ) {
if (!$definition instanceof LayerGroup) { if (!$definition instanceof LayerGroup) {
return; return;

View File

@@ -86,7 +86,8 @@ class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
Definition $definition, Definition $definition,
\Model $model, \Model $model,
DefinitionMapper $mapper, DefinitionMapper $mapper,
LatLngBounds $bounds = null LatLngBounds $bounds = null,
Definition $parent = null
) { ) {
if ($definition instanceof GeoJson) { if ($definition instanceof GeoJson) {
$collection = $this->loadMarkerModels($model); $collection = $this->loadMarkerModels($model);

View File

@@ -73,8 +73,9 @@ class ProviderLayerMapper extends AbstractLayerMapper
protected function build( protected function build(
Definition $definition, Definition $definition,
\Model $model, \Model $model,
DefinitionMapper $builder, DefinitionMapper $mapper,
LatLngBounds $bounds = null LatLngBounds $bounds = null,
Definition $parent = null
) { ) {
if (!empty($this->providers[$model->tile_provider]['options'])) { if (!empty($this->providers[$model->tile_provider]['options'])) {
$this->applyOptions( $this->applyOptions(

View File

@@ -13,6 +13,7 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Layer;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\Contao\Leaflet\Model\LayerModel; use Netzmacht\Contao\Leaflet\Model\LayerModel;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds; use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
/** /**
@@ -32,7 +33,7 @@ class ReferenceLayerMapper extends AbstractLayerMapper
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function handle($model, DefinitionMapper $mapper, LatLngBounds $bounds = null, $elementId = null) public function handle($model, DefinitionMapper $mapper, LatLngBounds $bounds = null, $elementId = null, Definition $parent = null)
{ {
$reference = LayerModel::findByPk($model->reference); $reference = LayerModel::findByPk($model->reference);

View File

@@ -100,7 +100,8 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
Definition $definition, Definition $definition,
\Model $model, \Model $model,
DefinitionMapper $mapper, DefinitionMapper $mapper,
LatLngBounds $bounds = null LatLngBounds $bounds = null,
Definition $parent = null
) { ) {
if ($definition instanceof GeoJson) { if ($definition instanceof GeoJson) {
$collection = $this->loadVectorModels($model); $collection = $this->loadVectorModels($model);

View File

@@ -57,12 +57,17 @@ class MapMapper extends AbstractMapper
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function build(Definition $map, \Model $model, DefinitionMapper $builder, LatLngBounds $bounds = null) protected function build(
{ Definition $map,
\Model $model,
DefinitionMapper $mapper,
LatLngBounds $bounds = null,
Definition $parent = null
) {
if ($map instanceof Map && $model instanceof MapModel) { if ($map instanceof Map && $model instanceof MapModel) {
$this->buildCustomOptions($map, $model); $this->buildCustomOptions($map, $model);
$this->buildControls($map, $model, $builder, $bounds); $this->buildControls($map, $model, $mapper, $bounds);
$this->buildLayers($map, $model, $builder, $bounds); $this->buildLayers($map, $model, $mapper, $bounds);
$this->buildBoundsCalculation($map, $model); $this->buildBoundsCalculation($map, $model);
} }
} }

View File

@@ -27,11 +27,18 @@ interface Mapper
* @param \Model|mixed $model The model being built. Usually a contao model, but can be anything. * @param \Model|mixed $model The model being built. Usually a contao model, but can be anything.
* @param DefinitionMapper $mapper The definition builder. * @param DefinitionMapper $mapper The definition builder.
* @param LatLngBounds $bounds Optional bounds where elements should be in. * @param LatLngBounds $bounds Optional bounds where elements should be in.
* @param string $elementId Optional element id. * @param string $elementId Optional element.
* @param Definition|null $parent Optional passed parent.
* *
* @return Definition * @return Definition
*/ */
public function handle($model, DefinitionMapper $mapper, LatLngBounds $bounds = null, $elementId = null); public function handle(
$model,
DefinitionMapper $mapper,
LatLngBounds $bounds = null,
$elementId = null,
Definition $parent = null
);
/** /**
* Check if mapper is responsible for the model. * Check if mapper is responsible for the model.

View File

@@ -54,7 +54,8 @@ class DivIconMapper extends AbstractIconMapper
Definition $definition, Definition $definition,
\Model $model, \Model $model,
DefinitionMapper $mapper, DefinitionMapper $mapper,
LatLngBounds $bounds = null LatLngBounds $bounds = null,
Definition $parent = null
) { ) {
parent::build($definition, $model, $mapper, $bounds); parent::build($definition, $model, $mapper, $bounds);

View File

@@ -67,7 +67,8 @@ class ImageIconMapper extends AbstractIconMapper
Definition $definition, Definition $definition,
\Model $model, \Model $model,
DefinitionMapper $mapper, DefinitionMapper $mapper,
LatLngBounds $bounds = null LatLngBounds $bounds = null,
Definition $parent = null
) { ) {
if ($definition instanceof ImageIcon) { if ($definition instanceof ImageIcon) {
$this->addIcon($definition, $model); $this->addIcon($definition, $model);

View File

@@ -73,8 +73,9 @@ class MarkerMapper extends AbstractMapper
protected function build( protected function build(
Definition $definition, Definition $definition,
\Model $model, \Model $model,
DefinitionMapper $builder, DefinitionMapper $mapper,
LatLngBounds $bounds = null LatLngBounds $bounds = null,
Definition $parent = null
) { ) {
if ($definition instanceof Marker) { if ($definition instanceof Marker) {
if ($model->addPopup) { if ($model->addPopup) {
@@ -90,7 +91,7 @@ class MarkerMapper extends AbstractMapper
if ($iconModel) { if ($iconModel) {
/** @var ImageIcon $icon */ /** @var ImageIcon $icon */
$icon = $builder->handle($iconModel); $icon = $mapper->handle($iconModel);
$definition->setIcon($icon); $definition->setIcon($icon);
} }
} }

View File

@@ -41,7 +41,8 @@ class AbstractVectorMapper extends AbstractTypeMapper
Definition $definition, Definition $definition,
\Model $model, \Model $model,
DefinitionMapper $mapper, DefinitionMapper $mapper,
LatLngBounds $bounds = null LatLngBounds $bounds = null,
Definition $parent = null
) { ) {
parent::build($definition, $model, $mapper, $bounds); parent::build($definition, $model, $mapper, $bounds);

View File

@@ -54,10 +54,11 @@ class CircleMapper extends AbstractVectorMapper
protected function build( protected function build(
Definition $definition, Definition $definition,
\Model $model, \Model $model,
DefinitionMapper $builder, DefinitionMapper $mapper,
LatLngBounds $bounds = null LatLngBounds $bounds = null,
Definition $parent = null
) { ) {
parent::build($definition, $model, $builder, $bounds); parent::build($definition, $model, $mapper, $bounds);
if ($definition instanceof Circle) { if ($definition instanceof Circle) {
$definition->setLatLng(LatLng::fromString($model->coordinates)); $definition->setLatLng(LatLng::fromString($model->coordinates));

View File

@@ -44,10 +44,11 @@ class MultiPolygonMapper extends MultiPolylineMapper
protected function build( protected function build(
Definition $definition, Definition $definition,
\Model $model, \Model $model,
DefinitionMapper $builder, DefinitionMapper $mapper,
LatLngBounds $bounds = null LatLngBounds $bounds = null,
Definition $parent = null
) { ) {
parent::build($definition, $model, $builder, $bounds); parent::build($definition, $model, $mapper, $bounds);
if ($definition instanceof MultiPolygon) { if ($definition instanceof MultiPolygon) {
$this->createLatLngs($definition, $model); $this->createLatLngs($definition, $model);

View File

@@ -45,10 +45,11 @@ class MultiPolylineMapper extends AbstractVectorMapper
protected function build( protected function build(
Definition $definition, Definition $definition,
\Model $model, \Model $model,
DefinitionMapper $builder, DefinitionMapper $mapper,
LatLngBounds $bounds = null LatLngBounds $bounds = null,
Definition $parent = null
) { ) {
parent::build($definition, $model, $builder, $bounds); parent::build($definition, $model, $mapper, $bounds);
if ($definition instanceof MultiPolyline) { if ($definition instanceof MultiPolyline) {
$this->createLatLngs($definition, $model); $this->createLatLngs($definition, $model);

View File

@@ -44,10 +44,11 @@ class PolylineMapper extends AbstractVectorMapper
protected function build( protected function build(
Definition $definition, Definition $definition,
\Model $model, \Model $model,
DefinitionMapper $builder, DefinitionMapper $mapper,
LatLngBounds $bounds = null LatLngBounds $bounds = null,
Definition $parent = null
) { ) {
parent::build($definition, $model, $builder, $bounds); parent::build($definition, $model, $mapper, $bounds);
if ($definition instanceof Polyline) { if ($definition instanceof Polyline) {
array_map( array_map(