# class: Mapa # define un mapa de obketos class Mapa extends ArrayObject{ public function __construct(){ parent::__construct(); } # agrega un elemento al mapa en el indice especificado # si no viene definido ix, lo agrega en la 1er pos. public function add($ix,$elem){ if(empty($ix)){ parent::append($elem); }else{ parent::offsetSet($ix,$elem); } } # retorna bool, si existe el indice del mapa public function indexExists($ix){ return parent::offsetExists($ix); } #retorna un iterador public function getIterator(): Iterator { return parent::getIterator(); } #retorna el elemento actual del iterador public function getCurrent(){ //return parent::getIterator()->getCurrent(); return parent::getIterator()->current(); } #retorna bool si el iterador es valido public function valid(){ return parent::getIterator()->valid(); } #retorna proximo iterador public function next(){ return parent::getIterator()->next(); } #rewind pone el iterator al comienzo public function rewind(){ parent::getIterator()->rewind(); return parent::getIterator(); } # retorna un array donde los ids son obtneidos por $metodGetId y el valor por $metodGetValor public function getAsArray($metodGetId,$metodGetValor){ $return = false; $iterator = $this->getIterator(); $iterator->rewind(); while($iterator->valid()) { $id = $iterator->current()->$metodGetId(); $valor = $iterator->current()->$metodGetValor(); $return[$id]=$valor; $iterator->next(); } return $return; } public function toArray() { return $this->getArrayCopy(); } # retorna el número de elementos en el mapa public function getCount(){ return parent::count(); } # método para obtener y eliminar el primer elemento public function first() { if ($this->count() == 0) { return null; // o lanzar una excepción, según lo que prefieras } // Obtener el primer elemento $iterator = $this->getIterator(); $iterator->rewind(); $firstElement = $iterator->current(); // Eliminar el primer elemento $this->offsetUnset($iterator->key()); // Reindexar el array para mantener los índices consecutivos $this->exchangeArray(array_values($this->getArrayCopy())); return $firstElement; } } ?> class Enigma { private static $key = "_#_#_#_|UpperMind|_#_#_#_"; public static function encrypt($dato){ return base64_encode($dato); }//end of encoded function public static function decrypt($dato) { return base64_decode($dato); } public static function generateValidator($dato){ return self::encrypt($dato.self::$key); } public static function validate($dato, $validator){ $dato = Enigma::decrypt($dato); if(is_numeric($dato)){ return ($validator == Enigma::generateValidator($dato)); } return false; } }