You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.4 KiB
50 lines
1.4 KiB
<?php
|
|
/** @license MIT
|
|
* Copyright 2017 , Dustin Wilson, J. King et al.
|
|
* See LICENSE and AUTHORS files for details */
|
|
|
|
declare(strict_types=1);
|
|
namespace MensBeam\HTML;
|
|
|
|
// This is a write-only map of elements which need to be kept in memory; it
|
|
// exists because values of properties on derived DOM classes are lost unless at
|
|
// least one PHP reference is kept for the element somewhere in userspace. This
|
|
// is that somewhere. It is at present only used for template elements.
|
|
class ElementMap {
|
|
public static $_storage = [];
|
|
|
|
public static function delete(Element $element) {
|
|
foreach (self::$_storage as $k => $v) {
|
|
if ($v->isSameNode($element)) {
|
|
unset(self::$_storage[$k]);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public static function destroy(Document $document) {
|
|
foreach (self::$_storage as $k => $v) {
|
|
if ($v->ownerDocument->isSameNode($document)) {
|
|
unset(self::$_storage[$k]);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static function has(Element $element) {
|
|
foreach (self::$_storage as $v) {
|
|
if ($v->isSameNode($element)) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public static function set(Element $element) {
|
|
if (!self::has($element)) {
|
|
self::$_storage[] = $element;
|
|
}
|
|
}
|
|
}
|
|
|