index/src/Data/DbResultTrait.php

48 lines
1.3 KiB
PHP

<?php
// DbResultTrait.php
// Created: 2023-11-09
// Updated: 2024-02-06
namespace Index\Data;
/**
* Implements common IDbResult methods.
*/
trait DbResultTrait {
public function getString(int|string $index): string {
return (string)$this->getValue($index);
}
public function getStringOrNull(int|string $index): ?string {
return $this->isNull($index) ? null : (string)$this->getValue($index);
}
public function getInteger(int|string $index): int {
return (int)$this->getValue($index);
}
public function getIntegerOrNull(int|string $index): ?int {
return $this->isNull($index) ? null : (int)$this->getValue($index);
}
public function getFloat(int|string $index): float {
return (float)$this->getValue($index);
}
public function getFloatOrNull(int|string $index): ?float {
return $this->isNull($index) ? null : (float)$this->getValue($index);
}
public function getBoolean(int|string $index): bool {
return $this->getInteger($index) !== 0;
}
public function getBooleanOrNull(int|string $index): ?bool {
return $this->isNull($index) ? null : ($this->getInteger($index) !== 0);
}
public function getIterator(callable $construct): DbResultIterator {
return new DbResultIterator($this, $construct);
}
}