$mapper The mapper to deserialize JSON */ private function __construct(private ?PDO $pdo, private ?PDOStatement $result, private Mapper $mapper) { } /** * Construct a new document list * * @param string $query The query to run to retrieve results * @param array $parameters An associative array of parameters for the query * @param Mapper $mapper A mapper to deserialize JSON documents * @return static The document list instance * @throws DocumentException If any is encountered */ public static function create(string $query, array $parameters, Mapper $mapper): static { $pdo = Configuration::dbConn(); return new static($pdo, Custom::runQuery($query, $parameters, $pdo), $mapper); } /** * The items from the query result * * @return Generator The items from the document list */ public function items(): Generator { if ($this->result) { while ($row = $this->result->fetch(PDO::FETCH_ASSOC)) yield $this->mapper->map($row); } $this->result = null; $this->pdo = null; } }