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.cache.default:
|
||||
class: Doctrine\Common\Cache\FilesystemCache
|
||||
class: Symfony\Component\Cache\Adapter\FilesystemAdapter
|
||||
arguments:
|
||||
- 'netzmacht.contao_leaflet'
|
||||
- 0
|
||||
- '%netzmacht.contao_leaflet.cache_dir%'
|
||||
|
||||
netzmacht.contao_leaflet.cache.debug:
|
||||
class: Doctrine\Common\Cache\ArrayCache
|
||||
class: Symfony\Component\Cache\Adapter\ArrayAdapter
|
||||
|
||||
netzmacht.contao_leaflet.frontend.value_filter:
|
||||
class: Netzmacht\Contao\Leaflet\Frontend\ValueFilter
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
namespace Netzmacht\Contao\Leaflet;
|
||||
|
||||
use Contao\Input;
|
||||
use Doctrine\Common\Cache\Cache;
|
||||
use Netzmacht\Contao\Leaflet\Encoder\ContaoAssets;
|
||||
use Netzmacht\Contao\Leaflet\Event\GetJavascriptEvent;
|
||||
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\Leaflet;
|
||||
use Netzmacht\LeafletPHP\Value\GeoJson\FeatureCollection;
|
||||
use Symfony\Component\Cache\CacheItem;
|
||||
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface as EventDispatcher;
|
||||
use Symfony\Contracts\Cache\CacheInterface as Cache;
|
||||
|
||||
/**
|
||||
* Class MapProvider.
|
||||
@@ -212,25 +213,29 @@ class MapProvider
|
||||
if ($doCache) {
|
||||
$cacheKey = $this->getCacheKey($mapId, $filter, $elementId, $template, $style);
|
||||
|
||||
if ($this->cache->contains($cacheKey)) {
|
||||
$cached = $this->cache->fetch($cacheKey);
|
||||
$this->assets->fromArray($cached['assets']);
|
||||
if ($this->cache->hasItem($cacheKey)) {
|
||||
$cached = $this->cache->getItem($cacheKey);
|
||||
$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);
|
||||
|
||||
if ($doCache) {
|
||||
$this->cache->save(
|
||||
$cacheKey,
|
||||
[
|
||||
'assets' => $this->assets->toArray(),
|
||||
'javascript' => $buffer,
|
||||
],
|
||||
(int) $model->cacheLifeTime
|
||||
);
|
||||
$cached
|
||||
->expiresAfter((int)$model->cacheLifeTime)
|
||||
->set(
|
||||
[
|
||||
'assets' => $this->assets->toArray(),
|
||||
'javascript' => $buffer,
|
||||
]
|
||||
);
|
||||
$this->cache->save($cached);
|
||||
}
|
||||
|
||||
return $buffer;
|
||||
@@ -270,12 +275,19 @@ class MapProvider
|
||||
$cacheKey .= '.filter_' . md5($filter->toRequest());
|
||||
}
|
||||
|
||||
if ($this->cache->contains($cacheKey)) {
|
||||
return $this->cache->fetch($cacheKey);
|
||||
if ($this->cache->hasItem($cacheKey)) {
|
||||
$cachedItem = $this->cache->getItem($cacheKey);
|
||||
|
||||
return $cachedItem->get();
|
||||
} else {
|
||||
$cachedItem = $this->cache->getItem($cacheKey);
|
||||
}
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user