Rename doBuild to build and introduce getClassName method.

This commit is contained in:
David Molineus
2015-01-08 09:51:43 +01:00
parent b3c0bd72df
commit 5cd680562d
14 changed files with 42 additions and 29 deletions

View File

@@ -15,9 +15,9 @@ use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds; use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
/** /**
* Class AbstractBuilder. * Class AbstractMapper.
* *
* @package Netzmacht\Contao\Leaflet\Builder * @package Netzmacht\Contao\Leaflet\Mapper
*/ */
abstract class AbstractMapper implements Mapper abstract class AbstractMapper implements Mapper
{ {
@@ -149,13 +149,13 @@ abstract class AbstractMapper implements Mapper
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function handle(\Model $model, DefinitionMapper $builder, LatLngBounds $bounds = null) public function handle(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
{ {
$definition = $this->createInstance($model, $builder, $bounds); $definition = $this->createInstance($model, $mapper, $bounds);
$this->buildOptions($definition, $model); $this->buildOptions($definition, $model);
$this->buildConditionals($definition, $model); $this->buildConditionals($definition, $model);
$this->doBuild($definition, $model, $builder, $bounds); $this->build($definition, $model, $mapper, $bounds);
return $definition; return $definition;
} }
@@ -171,13 +171,12 @@ abstract class AbstractMapper implements Mapper
} }
/** /**
* Initialize the builder. * Initialize the mapper.
* *
* @return void * @return void
*/ */
protected function initialize() protected function initialize()
{ {
} }
/** /**
@@ -185,15 +184,15 @@ abstract class AbstractMapper implements Mapper
* *
* @param Definition $definition The definition being built. * @param Definition $definition The definition being built.
* @param \Model $model The model. * @param \Model $model The model.
* @param DefinitionMapper $builder The definition builder. * @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.
* *
* @return void * @return void
*/ */
protected function doBuild( protected function build(
Definition $definition, Definition $definition,
\Model $model, \Model $model,
DefinitionMapper $builder, DefinitionMapper $mapper,
LatLngBounds $bounds = null LatLngBounds $bounds = null
) { ) {
} }
@@ -209,7 +208,7 @@ abstract class AbstractMapper implements Mapper
*/ */
protected function createInstance(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null) protected function createInstance(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
{ {
$reflector = new \ReflectionClass(static::$definitionClass); $reflector = new \ReflectionClass($this->getClassName($model, $mapper, $bounds));
$instance = $reflector->newInstanceArgs($this->buildConstructArguments($model, $mapper, $bounds)); $instance = $reflector->newInstanceArgs($this->buildConstructArguments($model, $mapper, $bounds));
return $instance; return $instance;
@@ -331,4 +330,18 @@ abstract class AbstractMapper implements Mapper
return null; return null;
} }
/**
* Get definition class name.
*
* @param \Model $model The model.
* @param DefinitionMapper $mapper The definition mapper.
* @param LatLngBounds $bounds Optional bounds where elements should be in.
*
* @return string
*/
protected function getClassName(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
{
return static::$definitionClass;
}
} }

View File

@@ -50,7 +50,7 @@ class AttributionControlMapper extends AbstractControlMapper
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function doBuild(Definition $definition, \Model $model, DefinitionMapper $builder, LatLngBounds $bounds = null) protected function build(Definition $definition, \Model $model, DefinitionMapper $builder, LatLngBounds $bounds = null)
{ {
if (!$definition instanceof Attribution) { if (!$definition instanceof Attribution) {
return; return;

View File

@@ -53,7 +53,7 @@ class GroupLayerMapper extends AbstractLayerMapper
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function doBuild( protected function build(
Definition $definition, Definition $definition,
\Model $model, \Model $model,
DefinitionMapper $mapper, DefinitionMapper $mapper,

View File

@@ -57,7 +57,7 @@ class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function doBuild( protected function build(
Definition $definition, Definition $definition,
\Model $model, \Model $model,
DefinitionMapper $mapper, DefinitionMapper $mapper,

View File

@@ -70,7 +70,7 @@ class ProviderLayerMapper extends AbstractLayerMapper
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function doBuild(Definition $definition, \Model $model, DefinitionMapper $builder, LatLngBounds $bounds = null) protected function build(Definition $definition, \Model $model, DefinitionMapper $builder, LatLngBounds $bounds = null)
{ {
if (!empty($this->providers[$model->tile_provider]['options'])) { if (!empty($this->providers[$model->tile_provider]['options'])) {
$this->applyOptions( $this->applyOptions(

View File

@@ -58,7 +58,7 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function doBuild( protected function build(
Definition $definition, Definition $definition,
\Model $model, \Model $model,
DefinitionMapper $mapper, DefinitionMapper $mapper,

View File

@@ -51,7 +51,7 @@ class MapMapper extends AbstractMapper
/** /**
* @inheritdoc * @inheritdoc
*/ */
protected function doBuild(Definition $map, \Model $model, DefinitionMapper $builder, LatLngBounds $bounds = null) protected function build(Definition $map, \Model $model, DefinitionMapper $builder, LatLngBounds $bounds = null)
{ {
if ($map instanceof Map && $model instanceof MapModel) { if ($map instanceof Map && $model instanceof MapModel) {
$this->buildCustomOptions($map, $model); $this->buildCustomOptions($map, $model);

View File

@@ -63,7 +63,7 @@ class ImageIconMapper extends AbstractIconMapper
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function doBuild( protected function build(
Definition $definition, Definition $definition,
\Model $model, \Model $model,
DefinitionMapper $mapper, DefinitionMapper $mapper,

View File

@@ -61,7 +61,7 @@ class MarkerMapper extends AbstractMapper
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function doBuild( protected function build(
Definition $definition, Definition $definition,
\Model $model, \Model $model,
DefinitionMapper $builder, DefinitionMapper $builder,

View File

@@ -41,13 +41,13 @@ class AbstractVectorMapper extends AbstractTypeMapper
; ;
} }
protected function doBuild( protected function build(
Definition $definition, Definition $definition,
\Model $model, \Model $model,
DefinitionMapper $builder, DefinitionMapper $builder,
LatLngBounds $bounds = null LatLngBounds $bounds = null
) { ) {
parent::doBuild($definition, $model, $builder, $bounds); parent::build($definition, $model, $builder, $bounds);
if ($definition instanceof Path) { if ($definition instanceof Path) {
if ($model->addPopup) { if ($model->addPopup) {

View File

@@ -41,13 +41,13 @@ class CircleMapper extends AbstractVectorMapper
$this->addOption('radius'); $this->addOption('radius');
} }
protected function doBuild( protected function build(
Definition $definition, Definition $definition,
\Model $model, \Model $model,
DefinitionMapper $builder, DefinitionMapper $builder,
LatLngBounds $bounds = null LatLngBounds $bounds = null
) { ) {
parent::doBuild($definition, $model, $builder, $bounds); parent::build($definition, $model, $builder, $bounds);
if ($definition instanceof Circle) { if ($definition instanceof Circle) {
$definition->setLatLng(LatLng::fromString($model->coordinates)); $definition->setLatLng(LatLng::fromString($model->coordinates));

View File

@@ -34,13 +34,13 @@ class MultiPolygonMapper extends MultiPolylineMapper
*/ */
protected static $type = 'multiPolygon'; protected static $type = 'multiPolygon';
protected function doBuild( protected function build(
Definition $definition, Definition $definition,
\Model $model, \Model $model,
DefinitionMapper $builder, DefinitionMapper $builder,
LatLngBounds $bounds = null LatLngBounds $bounds = null
) { ) {
parent::doBuild($definition, $model, $builder, $bounds); parent::build($definition, $model, $builder, $bounds);
if ($definition instanceof MultiPolygon) { if ($definition instanceof MultiPolygon) {
$latLngs = array(); $latLngs = array();

View File

@@ -36,13 +36,13 @@ class MultiPolylineMapper extends AbstractVectorMapper
protected static $type = 'multiPolyline'; protected static $type = 'multiPolyline';
protected function doBuild( protected function build(
Definition $definition, Definition $definition,
\Model $model, \Model $model,
DefinitionMapper $builder, DefinitionMapper $builder,
LatLngBounds $bounds = null LatLngBounds $bounds = null
) { ) {
parent::doBuild($definition, $model, $builder, $bounds); parent::build($definition, $model, $builder, $bounds);
if ($definition instanceof MultiPolyline) { if ($definition instanceof MultiPolyline) {
$latLngs = array(); $latLngs = array();

View File

@@ -35,13 +35,13 @@ class PolylineMapper extends AbstractVectorMapper
protected static $type = 'polyline'; protected static $type = 'polyline';
protected function doBuild( protected function build(
Definition $definition, Definition $definition,
\Model $model, \Model $model,
DefinitionMapper $builder, DefinitionMapper $builder,
LatLngBounds $bounds = null LatLngBounds $bounds = null
) { ) {
parent::doBuild($definition, $model, $builder, $bounds); parent::build($definition, $model, $builder, $bounds);
if ($definition instanceof Polyline) { if ($definition instanceof Polyline) {
array_map( array_map(