misuzu/src/Profile/ProfileFieldFormatInfo.php

57 lines
1.4 KiB
PHP

<?php
namespace Misuzu\Profile;
use Index\Data\IDbResult;
class ProfileFieldFormatInfo {
private string $id;
private string $fieldId;
private ?string $regex;
private ?string $linkFormat;
private string $displayFormat;
public function __construct(IDbResult $result) {
$this->id = (string)$result->getInteger(0);
$this->fieldId = (string)$result->getInteger(1);
$this->regex = $result->isNull(2) ? null : $result->getString(2);
$this->linkFormat = $result->isNull(3) ? null : $result->getString(3);
$this->displayFormat = $result->getString(4);
}
public function getId(): string {
return $this->id;
}
public function getFieldId(): string {
return $this->fieldId;
}
public function hasRegEx(): bool {
return $this->regex !== null;
}
public function getRegEx(): ?string {
return $this->regex;
}
public function hasLinkFormat(): bool {
return $this->linkFormat !== null;
}
public function getLinkFormat(): ?string {
return $this->linkFormat;
}
public function formatLink(string $value): ?string {
return $this->linkFormat === null ? null : sprintf($this->linkFormat, $value);
}
public function getDisplayFormat(): string {
return $this->displayFormat;
}
public function formatDisplay(string $value): string {
return sprintf($this->displayFormat, $value);
}
}