/var/www/html_de/wp-content/plugins/wp-smtp/src/Mail/Connectors/ConnectionPool.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php

namespace SolidWP\Mail\Connectors;

use 
ArrayIterator;
use 
InvalidArgumentException;

/**
 * A class representing a pool of connections.
 * Manages unique connections and ensures only valid ConnectorSMTP instances can be added.
 * 
 * @extends ArrayIterator<int, ConnectorSMTP>
 */
class ConnectionPool extends ArrayIterator {

    private array 
$connection_ids = [];

    public function 
offsetSet$key$value ): void {
        if ( 
$key !== null ) {
            throw new 
InvalidArgumentException'The pool must have sequential integer keys. Overriding connections is not allowed.' );
        }

        if ( ! 
$value instanceof ConnectorSMTP || ! $value->validation() ) {
            return;
        }

        if ( 
array_key_exists$value->get_id(), $this->connection_ids ) ) {
            return;
        }

        
$this->connection_ids$value->get_id() ] = $value->get_id();

        
parent::offsetSet$key$value );
    }

    public function 
key(): ?int {
        
$index parent::key();
        if ( 
$index === null ) {
            return 
null;
        }

        if ( ! 
is_int$index ) || $index ) {
            throw new 
InvalidArgumentException'Invalid offset.' );
        }

        return 
$index;
    }

    public function 
hasNext(): bool {
        if ( 
$this->key() === null ) {
            return 
false;
        }

        return 
$this->offsetExists$this->key() + );
    }
}