forked from Snck3rs/contao-leaflet-maps
Update for PHP 8.1 and MetaModels 2.3
This commit is contained in:
@@ -29,12 +29,14 @@ services:
|
|||||||
- '%netzmacht.contao_leaflet.filters%'
|
- '%netzmacht.contao_leaflet.filters%'
|
||||||
|
|
||||||
netzmacht.contao_leaflet.cache.default:
|
netzmacht.contao_leaflet.cache.default:
|
||||||
class: Doctrine\Common\Cache\FilesystemCache
|
class: Symfony\Component\Cache\Adapter\FilesystemAdapter
|
||||||
arguments:
|
arguments:
|
||||||
|
- 'netzmacht.contao_leaflet'
|
||||||
|
- 0
|
||||||
- '%netzmacht.contao_leaflet.cache_dir%'
|
- '%netzmacht.contao_leaflet.cache_dir%'
|
||||||
|
|
||||||
netzmacht.contao_leaflet.cache.debug:
|
netzmacht.contao_leaflet.cache.debug:
|
||||||
class: Doctrine\Common\Cache\ArrayCache
|
class: Symfony\Component\Cache\Adapter\ArrayAdapter
|
||||||
|
|
||||||
netzmacht.contao_leaflet.frontend.value_filter:
|
netzmacht.contao_leaflet.frontend.value_filter:
|
||||||
class: Netzmacht\Contao\Leaflet\Frontend\ValueFilter
|
class: Netzmacht\Contao\Leaflet\Frontend\ValueFilter
|
||||||
|
|||||||
@@ -13,7 +13,6 @@
|
|||||||
namespace Netzmacht\Contao\Leaflet;
|
namespace Netzmacht\Contao\Leaflet;
|
||||||
|
|
||||||
use Contao\Input;
|
use Contao\Input;
|
||||||
use Doctrine\Common\Cache\Cache;
|
|
||||||
use Netzmacht\Contao\Leaflet\Encoder\ContaoAssets;
|
use Netzmacht\Contao\Leaflet\Encoder\ContaoAssets;
|
||||||
use Netzmacht\Contao\Leaflet\Event\GetJavascriptEvent;
|
use Netzmacht\Contao\Leaflet\Event\GetJavascriptEvent;
|
||||||
use Netzmacht\Contao\Leaflet\Filter\Filter;
|
use Netzmacht\Contao\Leaflet\Filter\Filter;
|
||||||
@@ -28,7 +27,9 @@ use Netzmacht\Contao\Toolkit\View\Template\TemplateRenderer;
|
|||||||
use Netzmacht\LeafletPHP\Definition\Map;
|
use Netzmacht\LeafletPHP\Definition\Map;
|
||||||
use Netzmacht\LeafletPHP\Leaflet;
|
use Netzmacht\LeafletPHP\Leaflet;
|
||||||
use Netzmacht\LeafletPHP\Value\GeoJson\FeatureCollection;
|
use Netzmacht\LeafletPHP\Value\GeoJson\FeatureCollection;
|
||||||
|
use Symfony\Component\Cache\CacheItem;
|
||||||
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface as EventDispatcher;
|
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface as EventDispatcher;
|
||||||
|
use Symfony\Contracts\Cache\CacheInterface as Cache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class MapProvider.
|
* Class MapProvider.
|
||||||
@@ -212,25 +213,29 @@ class MapProvider
|
|||||||
if ($doCache) {
|
if ($doCache) {
|
||||||
$cacheKey = $this->getCacheKey($mapId, $filter, $elementId, $template, $style);
|
$cacheKey = $this->getCacheKey($mapId, $filter, $elementId, $template, $style);
|
||||||
|
|
||||||
if ($this->cache->contains($cacheKey)) {
|
if ($this->cache->hasItem($cacheKey)) {
|
||||||
$cached = $this->cache->fetch($cacheKey);
|
$cached = $this->cache->getItem($cacheKey);
|
||||||
$this->assets->fromArray($cached['assets']);
|
$achedData = $cached->get();
|
||||||
|
$this->assets->fromArray($achedData['assets']);
|
||||||
|
|
||||||
return $cached['javascript'];
|
return $achedData['javascript'];
|
||||||
|
} else {
|
||||||
|
$cached = $this->cache->getItem($cacheKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$buffer = $this->doGenerate($model, $filter, $elementId, $template, $style);
|
$buffer = $this->doGenerate($model, $filter, $elementId, $template, $style);
|
||||||
|
|
||||||
if ($doCache) {
|
if ($doCache) {
|
||||||
$this->cache->save(
|
$cached
|
||||||
$cacheKey,
|
->expiresAfter((int)$model->cacheLifeTime)
|
||||||
[
|
->set(
|
||||||
'assets' => $this->assets->toArray(),
|
[
|
||||||
'javascript' => $buffer,
|
'assets' => $this->assets->toArray(),
|
||||||
],
|
'javascript' => $buffer,
|
||||||
(int) $model->cacheLifeTime
|
]
|
||||||
);
|
);
|
||||||
|
$this->cache->save($cached);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $buffer;
|
return $buffer;
|
||||||
@@ -270,12 +275,19 @@ class MapProvider
|
|||||||
$cacheKey .= '.filter_' . md5($filter->toRequest());
|
$cacheKey .= '.filter_' . md5($filter->toRequest());
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->cache->contains($cacheKey)) {
|
if ($this->cache->hasItem($cacheKey)) {
|
||||||
return $this->cache->fetch($cacheKey);
|
$cachedItem = $this->cache->getItem($cacheKey);
|
||||||
|
|
||||||
|
return $cachedItem->get();
|
||||||
|
} else {
|
||||||
|
$cachedItem = $this->cache->getItem($cacheKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
$collection = $this->mapper->handleGeoJson($model, $request);
|
$collection = $this->mapper->handleGeoJson($model, $request);
|
||||||
$this->cache->save($cacheKey, $collection, $model->cacheLifeTime);
|
$cachedItem
|
||||||
|
->expiresAfter($model->cacheLifeTime)
|
||||||
|
->set($collection);
|
||||||
|
$this->cache->save($cachedItem);
|
||||||
|
|
||||||
return $collection;
|
return $collection;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user