Switch to PSR-4.

This commit is contained in:
David Molineus
2017-10-05 14:16:56 +02:00
parent e3344ffd4f
commit 827c746b0d
87 changed files with 4 additions and 6 deletions

View File

@@ -0,0 +1,121 @@
<?php
/**
* @package contao-leaflet-maps
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2014-2016 netzmacht David Molineus
* @license LGPL 3.0
* @filesource
*
*/
namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
use Netzmacht\Contao\Leaflet\Definition\Style;
use Netzmacht\Contao\Leaflet\Filter\Filter;
use Netzmacht\Contao\Leaflet\Frontend\ValueFilter;
use Netzmacht\Contao\Leaflet\Mapper\AbstractTypeMapper;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\Contao\Leaflet\Model\PopupModel;
use Netzmacht\Contao\Leaflet\Model\StyleModel;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\HasPopup;
use Netzmacht\LeafletPHP\Definition\UI\Popup;
use Netzmacht\LeafletPHP\Definition\Vector\Path;
/**
* Class AbstractVectorMapper is the base class for the vector model definition mapping.
*
* @package Netzmacht\Contao\Leaflet\Mapper\Vector
*/
class AbstractVectorMapper extends AbstractTypeMapper
{
/**
* Class of the model being build.
*
* @var string
*/
protected static $modelClass = 'Netzmacht\Contao\Leaflet\Model\VectorModel';
/**
* Frontend filter.
*
* @var ValueFilter
*/
protected $valueFilter;
/**
* Construct.
*
* @param ValueFilter $valueFilter Frontend filter.
*/
public function __construct(ValueFilter $valueFilter)
{
parent::__construct();
$this->valueFilter = $valueFilter;
}
/**
* {@inheritdoc}
*/
protected function build(
Definition $definition,
\Model $model,
DefinitionMapper $mapper,
Filter $filter = null,
Definition $parent = null
) {
parent::build($definition, $model, $mapper, $filter);
if ($definition instanceof Path && $model->style) {
$styleModel = StyleModel::findActiveByPK($model->style);
if ($styleModel) {
$style = $mapper->handle($styleModel);
if ($style instanceof Style) {
$style->apply($definition);
}
}
}
$this->buildPopup($definition, $model, $mapper, $filter);
}
/**
* Build the popup.
*
* @param Definition $definition The definition.
* @param \Model $model The model.
* @param DefinitionMapper $mapper The definition mapper.
* @param Filter $filter The filter.
*
* @return void
*/
protected function buildPopup(
Definition $definition,
\Model $model,
DefinitionMapper $mapper,
Filter $filter = null
) {
if ($definition instanceof HasPopup && $model->addPopup) {
$popup = null;
$content = $this->valueFilter->filter($model->popupContent);
if ($model->popup) {
$popupModel = PopupModel::findActiveByPK($model->popup);
if ($popupModel) {
$popup = $mapper->handle($popupModel, $filter, null, $definition);
}
}
if ($popup instanceof Popup) {
$definition->bindPopup($content, $popup->getOptions());
} else {
$definition->bindPopup($content);
}
}
}
}

View File

@@ -0,0 +1,68 @@
<?php
/**
* @package contao-leaflet-maps
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2014-2016 netzmacht David Molineus
* @license LGPL 3.0
* @filesource
*
*/
namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
use Netzmacht\Contao\Leaflet\Filter\Filter;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Vector\CircleMarker;
use Netzmacht\LeafletPHP\Value\LatLng;
use Netzmacht\LeafletPHP\Definition\Vector\Circle;
/**
* Class CircleMapper maps the database model to the circle definition.
*
* @package Netzmacht\Contao\Leaflet\Mapper\Vector
*/
class CircleMapper extends AbstractVectorMapper
{
/**
* Class of the definition being created.
*
* @var string
*/
protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\Vector\Circle';
/**
* Layer type.
*
* @var string
*/
protected static $type = 'circle';
/**
* {@inheritdoc}
*/
protected function initialize()
{
parent::initialize();
$this->optionsBuilder->addOption('radius');
}
/**
* {@inheritdoc}
*/
protected function build(
Definition $definition,
\Model $model,
DefinitionMapper $mapper,
Filter $filter = null,
Definition $parent = null
) {
parent::build($definition, $model, $mapper, $filter);
if ($definition instanceof CircleMarker) {
$definition->setLatLng(LatLng::fromString($model->coordinates));
}
}
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* @package contao-leaflet-maps
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2014-2016 netzmacht David Molineus
* @license LGPL 3.0
* @filesource
*
*/
namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
/**
* Class CircleMarkerMapper maps the database model to the circle marker definition.
*
* @package Netzmacht\Contao\Leaflet\Mapper\Vector
*/
class CircleMarkerMapper extends CircleMapper
{
/**
* Class of the definition being created.
*
* @var string
*/
protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\Vector\CircleMarker';
/**
* Layer type.
*
* @var string
*/
protected static $type = 'circleMarker';
}

View File

@@ -0,0 +1,56 @@
<?php
/**
* @package contao-leaflet-maps
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2014-2016 netzmacht David Molineus
* @license LGPL 3.0
* @filesource
*
*/
namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
use Netzmacht\Contao\Leaflet\Filter\Filter;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Vector\Polygon;
/**
* Class MultiPolygonMapper maps the multi polygon database model to its definition.
*
* @package Netzmacht\Contao\Leaflet\Mapper\Vector
*/
class MultiPolygonMapper extends MultiPolylineMapper
{
/**
* Class of the definition being created.
*
* @var string
*/
protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\Vector\Polygon';
/**
* Layer type.
*
* @var string
*/
protected static $type = 'multiPolygon';
/**
* {@inheritdoc}
*/
protected function build(
Definition $definition,
\Model $model,
DefinitionMapper $mapper,
Filter $filter = null,
Definition $parent = null
) {
parent::build($definition, $model, $mapper, $filter);
if ($definition instanceof Polygon) {
$this->createLatLngs($definition, $model);
}
}
}

View File

@@ -0,0 +1,79 @@
<?php
/**
* @package contao-leaflet-maps
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2014-2016 netzmacht David Molineus
* @license LGPL 3.0
* @filesource
*
*/
namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
use Netzmacht\Contao\Leaflet\Filter\Filter;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Vector\Polyline;
use Netzmacht\LeafletPHP\Value\LatLng;
/**
* Class MultiPolylineMapper maps the databse model it the multi polyline definition.
*
* @package Netzmacht\Contao\Leaflet\Mapper\Vector
*/
class MultiPolylineMapper extends AbstractVectorMapper
{
/**
* Class of the definition being created.
*
* @var string
*/
protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\Vector\Polyline';
/**
* Layer type.
*
* @var string
*/
protected static $type = 'multiPolyline';
/**
* {@inheritdoc}
*/
protected function build(
Definition $definition,
\Model $model,
DefinitionMapper $mapper,
Filter $filter = null,
Definition $parent = null
) {
parent::build($definition, $model, $mapper, $filter);
if ($definition instanceof Polyline) {
$this->createLatLngs($definition, $model);
}
}
/**
* Create lat lngs for the definition.
*
* @param Polyline $definition The multi polyline.
* @param \Model $model The definition model.
*
* @return void
*/
protected function createLatLngs(Polyline $definition, \Model $model)
{
foreach (deserialize($model->multiData, true) as $ring => $data) {
$latLngs = array_map(
function ($row) {
return LatLng::fromString($row);
},
explode("\n", $data)
);
$definition->addLatLngs($latLngs, $ring);
}
}
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* @package contao-leaflet-maps
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2014-2016 netzmacht David Molineus
* @license LGPL 3.0
* @filesource
*
*/
namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
/**
* Class PolygonMapper maps the database model to the polygon definition.
*
* @package Netzmacht\Contao\Leaflet\Mapper\Vector
*/
class PolygonMapper extends PolylineMapper
{
/**
* Class of the definition being created.
*
* @var string
*/
protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\Vector\Polygon';
/**
* Layer type.
*
* @var string
*/
protected static $type = 'polygon';
}

View File

@@ -0,0 +1,62 @@
<?php
/**
* @package contao-leaflet-maps
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2014-2016 netzmacht David Molineus
* @license LGPL 3.0
* @filesource
*
*/
namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
use Netzmacht\Contao\Leaflet\Filter\Filter;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Value\LatLng;
use Netzmacht\LeafletPHP\Definition\Vector\Polyline;
/**
* Class PolylineMapper maps the database model to the polyline definition.
*
* @package Netzmacht\Contao\Leaflet\Mapper\Vector
*/
class PolylineMapper extends AbstractVectorMapper
{
/**
* Class of the definition being created.
*
* @var string
*/
protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\Vector\Polyline';
/**
* Layer type.
*
* @var string
*/
protected static $type = 'polyline';
/**
* {@inheritdoc}
*/
protected function build(
Definition $definition,
\Model $model,
DefinitionMapper $mapper,
Filter $filter = null,
Definition $parent = null
) {
parent::build($definition, $model, $mapper, $filter);
if ($definition instanceof Polyline) {
array_map(
function ($row) use ($definition) {
$definition->addLatLng(LatLng::fromString($row));
},
explode("\n", $model->data)
);
}
}
}

View File

@@ -0,0 +1,62 @@
<?php
/**
* @package contao-leaflet-maps
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2014-2016 netzmacht David Molineus
* @license LGPL 3.0
* @filesource
*
*/
namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
use Netzmacht\Contao\Leaflet\Filter\Filter;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Value\LatLng;
use Netzmacht\LeafletPHP\Value\LatLngBounds;
/**
* Class RectangleMapper maps a database model to its rectangle vector definition.
*
* @package Netzmacht\Contao\Leaflet\Mapper\Vector
*/
class RectangleMapper extends AbstractVectorMapper
{
/**
* Class of the definition being created.
*
* @var string
*/
protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\Vector\Rectangle';
/**
* Layer type.
*
* @var string
*/
protected static $type = 'rectangle';
/**
* {@inheritdoc}
*/
protected function buildConstructArguments(
\Model $model,
DefinitionMapper $mapper,
Filter $filter = null,
$elementId = null
) {
$latLngs = array_map(
function ($latLng) {
return LatLng::fromString($latLng);
},
deserialize($model->bounds, true)
);
$arguments = parent::buildConstructArguments($model, $mapper, $filter, $elementId);
$arguments[] = new LatLngBounds($latLngs[0], $latLngs[1]);
return $arguments;
}
}