Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ElementInventoryService extends ElementConfigFilter implements HttpHandler
/** @var ElementServiceInterface[] */
protected $serviceElements = array();

public function __construct($disabledClasses)
public function __construct(array $disabledClasses)
{
$this->disabledClassesFromConfig = $disabledClasses ?: array();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class InstanceTunnelService
protected $tokenStorage;
/** @var EntityManagerInterface */
protected $entityManager;
/** @var VendorSpecificHandler */
protected $vendorSpecificHandler;
/** @var Endpoint[] */
protected $bufferedEndPoints = array();
/** @var string */
Expand All @@ -52,18 +54,21 @@ class InstanceTunnelService
* @param TypeDirectoryService $sourceTypeDirectory
* @param TokenStorageInterface $tokenStorage
* @param EntityManagerInterface $entityManager
* @param VendorSpecificHandler $vendorSpecificHandler
*/
public function __construct(HttpTransportInterface $httpTransprot,
RouterInterface $router,
TypeDirectoryService $sourceTypeDirectory,
TokenStorageInterface $tokenStorage,
EntityManagerInterface $entityManager)
EntityManagerInterface $entityManager,
?VendorSpecificHandler $vendorSpecificHandler = null)
{
$this->httpTransport = $httpTransprot;
$this->router = $router;
$this->sourceTypeDirectory = $sourceTypeDirectory;
$this->tokenStorage = $tokenStorage;
$this->entityManager = $entityManager;
$this->vendorSpecificHandler = $vendorSpecificHandler ?? new VendorSpecificHandler();
// @todo: TBD if it's worth making this configurable
$this->tunnelRouteName = 'mapbender_core_instancetunnel_instancetunnel';
$this->legendTunnelRouteName = 'mapbender_core_instancetunnel_instancetunnellegend';
Expand Down Expand Up @@ -103,8 +108,7 @@ public function makeEndpoint(Application $application, SourceInstance $instance)
*/
public function getPublicBaseUrl(Endpoint $endpoint)
{
$vsHandler = new VendorSpecificHandler();
$vsParams = $vsHandler->getPublicParams($endpoint->getSourceInstance(), $this->tokenStorage->getToken());
$vsParams = $this->vendorSpecificHandler->getPublicParams($endpoint->getSourceInstance(), $this->tokenStorage->getToken());
$params = array_replace($vsParams, array(
'slug' => $endpoint->getApplicationEntity()->getSlug(),
'instanceId' => $endpoint->getSourceInstance()->getId(),
Expand Down Expand Up @@ -221,10 +225,9 @@ protected function matchRouteParams(Application $application, array $routerMatch
* @param SourceInstance $instance
* @return string[]
*/
public function getHiddenParams(SourceInstance $instance)
public function getHiddenParams(SourceInstance $instance): array
{
$vsHandler = new VendorSpecificHandler();
return $vsHandler->getHiddenParams($instance, $this->tokenStorage->getToken());
return $this->vendorSpecificHandler->getHiddenParams($instance, $this->tokenStorage->getToken());
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Mapbender/CoreBundle/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@
<argument type="service" id="mapbender.source.typedirectory.service" />
<argument type="service" id="security.token_storage" />
<argument type="service" id="Doctrine\ORM\EntityManagerInterface" />
<argument type="service" id="mapbender.wms.vendor_specific_handler" />
</service>

<service id="mapbender.source.metadata_listener" class="Mapbender\CoreBundle\Component\Source\SourceMetadataListener">
Expand Down
52 changes: 24 additions & 28 deletions src/Mapbender/PrintBundle/Component/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,32 @@ class Template implements \ArrayAccess
const ORIENTATION_PORTRAIT = 'portrait';

/** @var float in mm*/
protected $width;
protected float $width;
/** @var float in mm*/
protected $height;
/** @var string */
protected $orientation;
/** @var RegionCollection */
protected $textFields;
/** @var RegionCollection */
protected $regions;
protected float $height;
protected string $orientation;
protected RegionCollection $textFields;
protected RegionCollection $regions;

/**
* @param float $width in mm
* @param float $height in mm
* @param string $orientation
*/
public function __construct($width, $height, $orientation)
public function __construct(float $width, float $height, string $orientation)
{
if ($width <= 0 || $height <=0) {
throw new \InvalidArgumentException("Invalid width / height "
. print_r($width, true) . ' ' . print_r($height, true));
if ($width <= 0 || $height <= 0) {
throw new \InvalidArgumentException("Invalid width / height " . $width . ' ' . $height);
}
$this->width = floatval($width);
$this->height = floatval($height);
$this->width = $width;
$this->height = $height;
switch ($orientation) {
case self::ORIENTATION_LANDSCAPE:
case self::ORIENTATION_PORTRAIT:
$this->orientation = $orientation;
break;
default:
throw new \InvalidArgumentException("Invalid orientation " . print_r($orientation, true));
throw new \InvalidArgumentException("Invalid orientation " . $orientation);
}

$this->textFields = new RegionCollection();
Expand All @@ -67,74 +63,74 @@ public function __construct($width, $height, $orientation)
/**
* @return string
*/
public function getOrientation()
public function getOrientation(): string
{
return $this->orientation;
}

/**
* @return float
*/
public function getWidth()
public function getWidth(): float
{
return $this->width;
}

/**
* @return float
*/
public function getHeight()
public function getHeight(): float
{
return $this->height;
}

/**
* @return RegionCollection|TemplateRegion[]
*/
public function getRegions()
public function getRegions(): RegionCollection
{
return $this->regions;
}

/**
* @return RegionCollection|TemplateRegion[]
*/
public function getTextFields()
public function getTextFields(): RegionCollection
{
return $this->textFields;
}

/**
* @param string
* @param string $name
* @return TemplateRegion
*/
public function getRegion($name)
public function getRegion($name): TemplateRegion
{
return $this->regions->getMember($name);
}

/**
* @param string
* @param string $name
* @return bool
*/
public function hasRegion($name)
public function hasRegion($name): bool
{
return $this->regions->hasMember($name);
}

/**
* @param string
* @param string $name
* @return bool
*/
public function hasTextField($name)
public function hasTextField($name): bool
{
return $this->textFields->hasMember($name);
}

/**
* @param TemplateRegion $region
*/
public function addRegion($region)
public function addRegion($region): void
{
$region->setParentTemplate($this);
$this->regions->addMember($region->getName(), $region);
Expand All @@ -143,7 +139,7 @@ public function addRegion($region)
/**
* @param TemplateRegion $field
*/
public function addTextField($field)
public function addTextField($field): void
{
$field->setParentTemplate($this);
$this->textFields->addMember($field->getName(), $field);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@
*/
class WmsSourceInstanceConfigGenerator extends SourceInstanceConfigGenerator
{
protected VendorSpecificHandler $vendorSpecificHandler;

public function __construct(
protected UrlProcessor $urlProcessor,
protected TokenStorageInterface $tokenStorage,
protected EntityManagerInterface $em,
protected ?string $defaultLayerOrder)
protected ?string $defaultLayerOrder,
?VendorSpecificHandler $vendorSpecificHandler = null)
{
$this->vendorSpecificHandler = $vendorSpecificHandler ?? new VendorSpecificHandler();
}

/**
Expand Down Expand Up @@ -237,7 +240,7 @@ public function postProcessUrls(Application $application, WmsInstance $sourceIns
* @param WmsInstance $sourceInstance
* @return string
*/
public function getUrlOption(WmsInstance $sourceInstance)
public function getUrlOption(WmsInstance $sourceInstance): string
{
$url = $sourceInstance->getSource()->getGetMap()->getHttpGet();
if (!$this->useTunnel($sourceInstance)) {
Expand All @@ -252,8 +255,7 @@ public function getUrlOption(WmsInstance $sourceInstance)
}
}
$userToken = $this->tokenStorage->getToken();
$vsHandler = new VendorSpecificHandler();
$params = $vsHandler->getPublicParams($sourceInstance, $userToken);
$params = $this->vendorSpecificHandler->getPublicParams($sourceInstance, $userToken);
return UrlUtil::validateUrl($url, $params);
}

Expand All @@ -263,7 +265,7 @@ public function getUrlOption(WmsInstance $sourceInstance)
* @param WmsInstance $sourceInstance
* @return float[][]
*/
public function getBboxConfiguration(WmsInstance $sourceInstance)
public function getBboxConfiguration(WmsInstance $sourceInstance): array
{
$rootLayer = $this->getRootLayerFromCache($sourceInstance);
return $this->getLayerBboxConfiguration($rootLayer);
Expand Down Expand Up @@ -344,7 +346,7 @@ protected function getAvailableStyles(Application $application, WmsInstance $ins
* @param WmsInstance $sourceInstance
* @return array[]
*/
public function getDimensionsConfiguration(WmsInstance $sourceInstance)
public function getDimensionsConfiguration(WmsInstance $sourceInstance): array
{
$dimensionConfigs = array();
$sourceDimensions = array();
Expand Down Expand Up @@ -447,10 +449,9 @@ public function useTunnel(SourceInstance $sourceInstance): bool
}

/** @var WmsInstance $sourceInstance */
$vsHandler = new VendorSpecificHandler();
return
(!!$sourceInstance->getSource()->getUsername()) ||
$vsHandler->hasHiddenParams($sourceInstance) ||
$this->vendorSpecificHandler->hasHiddenParams($sourceInstance) ||
$sourceInstance->getProxy();
}

Expand All @@ -468,7 +469,7 @@ public function useProxy(WmsInstance $sourceInstance): bool
* @return mixed[]
* @todo: this should and can be part of the initial generation
*/
protected function proxifyLayerUrls($layerConfig, ?SourceInstance $sourceInstance = null)
protected function proxifyLayerUrls(array $layerConfig, ?SourceInstance $sourceInstance = null): array
{
/** @var ?WmsInstance $sourceInstance */
if (isset($layerConfig['children'])) {
Expand Down
22 changes: 11 additions & 11 deletions src/Mapbender/WmsBundle/Component/VendorSpecificHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class VendorSpecificHandler
* @param string $input
* @return string|null
*/
public function findDynamicValuePortion($input)
public function findDynamicValuePortion(string $input): ?string
{
$matches = array();
if (\preg_match('#\$[a-z]+\$#i', $input, $matches)) {
Expand All @@ -47,12 +47,12 @@ public function findDynamicValuePortion($input)
* @param string $value
* @return boolean true if a value is dynamic.
*/
public function isValueDynamic($value)
public function isValueDynamic(string $value): bool
{
return !!$this->findDynamicValuePortion($value);
}

public function isValuePublic(VendorSpecific $vendorspec)
public function isValuePublic(VendorSpecific $vendorspec): bool
{
return !$vendorspec->getHidden();
}
Expand All @@ -62,7 +62,7 @@ public function isValuePublic(VendorSpecific $vendorspec)
* @param TokenInterface|null $userToken
* @return string[]
*/
public function getPublicParams(SourceInstance $instance, TokenInterface $userToken=null)
public function getPublicParams(SourceInstance $instance, TokenInterface $userToken=null): array
{
$user = $this->getUserFromToken($userToken);
$params = array();
Expand All @@ -80,7 +80,7 @@ public function getPublicParams(SourceInstance $instance, TokenInterface $userTo
* @param TokenInterface|null $userToken
* @return string[]
*/
public function getHiddenParams(SourceInstance $instance, TokenInterface $userToken=null)
public function getHiddenParams(SourceInstance $instance, TokenInterface $userToken=null): array
{
$user = $this->getUserFromToken($userToken);
$params = array();
Expand All @@ -98,7 +98,7 @@ public function getHiddenParams(SourceInstance $instance, TokenInterface $userTo
* @param TokenInterface|null $userToken
* @return string[]
*/
public function getAllParams(SourceInstance $instance, TokenInterface $userToken=null)
public function getAllParams(SourceInstance $instance, TokenInterface $userToken=null): array
{
$user = $this->getUserFromToken($userToken);
$params = array();
Expand All @@ -116,7 +116,7 @@ public function getAllParams(SourceInstance $instance, TokenInterface $userToken
* @param SourceInstance|WmsInstance $instance; NOTE: lax typing to avoid conflicts with WMTS
* @return bool
*/
public function hasHiddenParams(SourceInstance $instance)
public function hasHiddenParams(SourceInstance $instance): bool
{
foreach ($instance->getVendorspecifics() as $key => $vendorspec) {
if ($this->isVendorSpecificValueValid($vendorspec) && !$this->isValuePublic($vendorspec)) {
Expand All @@ -130,7 +130,7 @@ public function hasHiddenParams(SourceInstance $instance)
* @param TokenInterface $userToken
* @return UserInterface|null
*/
protected function getUserFromToken(TokenInterface $userToken=null)
protected function getUserFromToken(TokenInterface $userToken=null): ?UserInterface
{
if (!$userToken || $userToken instanceof NullToken) {
return null;
Expand All @@ -154,7 +154,7 @@ protected function getUserFromToken(TokenInterface $userToken=null)
* @param UserInterface|null $object
* @return string|null
*/
public function getVendorSpecificValue(VendorSpecific $vs, $object)
public function getVendorSpecificValue(VendorSpecific $vs, $object): ?string
{
$value = $vs->getDefault();
if ($vs->getVstype() !== VendorSpecific::TYPE_VS_SIMPLE) {
Expand All @@ -172,7 +172,7 @@ public function getVendorSpecificValue(VendorSpecific $vs, $object)
* @param string $attributeName
* @return string|null
*/
protected function extractDynamicReference(VendorSpecific $vs, $object, $attributeName)
protected function extractDynamicReference(VendorSpecific $vs, $object, string $attributeName): ?string
{
if (!$object || !is_object($object)) {
return null;
Expand Down Expand Up @@ -205,7 +205,7 @@ protected function extractDynamicReference(VendorSpecific $vs, $object, $attribu
}
}

public function isVendorSpecificValueValid(VendorSpecific $vs)
public function isVendorSpecificValueValid(VendorSpecific $vs): bool
{
if ($vs->getDefault()) {
return true;
Expand Down
Loading