*/ public static function active( mixed $stored, int $now ): array { $out = array(); foreach ( is_array( $stored ) ? $stored : array() as $r ) { if ( ! is_array( $r ) || ! isset( $r['seq'], $r['id'], $r['at'] ) || (int) $r['id'] <= 0 || $now - (int) $r['at'] >= self::TTL ) { continue; } $out[] = array( 'seq' => (int) $r['seq'], 'id' => (int) $r['id'], 'at' => (int) $r['at'] ); } return $out; } /** Pure: the queue after asking for $donationId again. The number never drops below the clock, so it cannot repeat after the queue empties. */ public static function push( mixed $stored, int $donationId, int $now ): array { $list = self::active( $stored, $now ); $last = $list ? max( array_column( $list, 'seq' ) ) : 0; $list[] = array( 'seq' => max( $last + 1, $now ), 'id' => $donationId, 'at' => $now ); return array_slice( $list, -self::MAX ); } public static function request( int $donationId ): void { update_option( self::OPTION, self::push( get_option( self::OPTION, array() ), $donationId, time() ), false ); } /** @return array */ public static function pending( int $now ): array { return self::active( get_option( self::OPTION, array() ), $now ); } }