FormClasses/src/Information.php
2024-05-22 14:29:38 +03:00

92 lines
2.3 KiB
PHP

<?php
/**
* @property string $surname
* @property string $name
* @property string $patronymic
* @property string $dateOfBirth
* @property string $gender
* @property string $countryCode
* @property string $phoneNumber
* @property string $email
* @property string $tempString
*/
class Information
{
public string $surname;
public string $name;
public string $patronymic;
public string $dateOfBirth;
public string $gender;
public string $countryCode;
public string $phoneNumber;
public string $email;
public string $tempString;
public function __construct()
{
}
/**
* @param array $dataArray
* @return void
*/
public function load(array $dataArray): void
{
if ($dataArray) {
$this->surname = $dataArray['surname'] ?? '';
$this->name = $dataArray['name'] ?? '';
$this->patronymic = $dataArray['patronymic'] ?? '';
$this->dateOfBirth = $dataArray['dateOfBirth'] ?? '';
$this->gender = $dataArray['gender'] ?? '';
$this->countryCode = $dataArray['countryCode'] ?? '';
$this->phoneNumber = $dataArray['phoneNumber'] ?? '';
$this->email = $dataArray['email'] ?? '';
}
}
/**
* @param string $key
* @return string|null
*/
public function getByKey(string $key): ?string
{
if (isset($this->{$key})) {
return $this->{$key};
}
return null;
}
/**
* @return string
*/
public function toString(): string
{
return $this->surname . ';' . $this->name . ';' . $this->patronymic . ';' . $this->dateOfBirth . ';' .
$this->gender . ';' . $this->countryCode . ';' . $this->phoneNumber . ';' . $this->email . ";\n";
}
/**
* @param array $textArrayFromFile
* @param string $search
* @return string|null
*/
public function search(array $textArrayFromFile, string $search): ?string
{
if($textArrayFromFile) {
foreach ($textArrayFromFile as $str) {
if (str_contains($str, $search)) {
$this->tempString = strstr($str, $search);
return substr($this->tempString, 0, strlen($search));
}
}
}
return null;
}
}