Rework libraries handling so that libraries don't have to be ported to contao 4.4 only yet.

This commit is contained in:
David Molineus
2017-10-09 15:36:11 +02:00
parent e6ed2c456d
commit edf212b850
8 changed files with 199 additions and 10 deletions

View File

@@ -0,0 +1,95 @@
<?php
/**
* Leaflet maps for Contao CMS.
*
* @package contao-leaflet-maps
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2016-2017 netzmacht David Molineus. All rights reserved.
* @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-maps/blob/master/LICENSE
* @filesource
*/
declare(strict_types=1);
namespace Netzmacht\Contao\Leaflet\Frontend\Assets;
use Contao\CoreBundle\Framework\ContaoFrameworkInterface as ContaoFramework;
use Traversable;
/**
* Class LibrariesConfiguration
*
* @package Netzmacht\Contao\Leaflet\Frontend\Assets
*/
class LibrariesConfiguration implements \IteratorAggregate, \ArrayAccess
{
/**
* @var ContaoFramework
*/
private $framework;
/**
* LibrariesConfiguration constructor.
*
* @param ContaoFramework $framework
*/
public function __construct(ContaoFramework $framework)
{
$this->framework = $framework;
}
/**
* {@inheritdoc}
*
* @SuppressWarnings(PHPMD.Superglobals)
*/
public function getIterator()
{
$this->framework->initialize();
return new \ArrayIterator($GLOBALS['LEAFLET_LIBRARIES']);
}
/**
* {@inheritdoc}
*
* @SuppressWarnings(PHPMD.Superglobals)
*/
public function offsetExists($offset)
{
$this->framework->initialize();
return isset($GLOBALS['LEAFLET_LIBRARIES'][$offset]);
}
/**
* {@inheritdoc}
*
* @SuppressWarnings(PHPMD.Superglobals)
*/
public function offsetGet($offset)
{
return $GLOBALS['LEAFLET_LIBRARIES'][$offset];
}
/**
* {@inheritdoc}
*
* @SuppressWarnings(PHPMD.Superglobals)
*/
public function offsetSet($offset, $value)
{
$GLOBALS['LEAFLET_LIBRARIES'][$offset] = $value;
}
/**
* {@inheritdoc}
*
* @SuppressWarnings(PHPMD.Superglobals)
*/
public function offsetUnset($offset)
{
unset($GLOBALS['LEAFLET_LIBRARIES'][$offset]);
}
}