2023-07-20 19:36:43 +00:00
|
|
|
<?php
|
|
|
|
namespace Misuzu\Profile;
|
|
|
|
|
|
|
|
use Index\Data\IDbResult;
|
|
|
|
|
|
|
|
class ProfileFieldFormatInfo {
|
2024-02-07 00:04:45 +00:00
|
|
|
public function __construct(
|
|
|
|
private string $id,
|
|
|
|
private string $fieldId,
|
|
|
|
private ?string $regex,
|
|
|
|
private ?string $linkFormat,
|
|
|
|
private string $displayFormat,
|
|
|
|
) {}
|
|
|
|
|
|
|
|
public static function fromResult(IDbResult $result): ProfileFieldFormatInfo {
|
|
|
|
return new ProfileFieldFormatInfo(
|
|
|
|
id: $result->getString(0),
|
|
|
|
fieldId: $result->getString(1),
|
|
|
|
regex: $result->getStringOrNull(2),
|
|
|
|
linkFormat: $result->getStringOrNull(3),
|
|
|
|
displayFormat: $result->getString(4),
|
|
|
|
);
|
2023-07-20 19:36:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|