This commit is contained in:
2024-06-14 15:55:36 +03:00
parent 5468b1d286
commit 987effd67f
35 changed files with 1808 additions and 245 deletions

71
src/Forms.php Normal file
View File

@ -0,0 +1,71 @@
<?php
//
//namespace src;
//
//class Forms
//{
// public string $infoForm;
// public string $forSearchForm;
//
// public function __construct()
// {
// $this->infoForm = '
// <form action="../info.php" target="_blank" method="post">
// Фамилия:<br>
// <input type = "text" name = "surname" required size="50" autofocus placeholder="Фамилия"> <br> <br>
//
// Имя:<br>
// <input type = "text" name = "name" required size="50" placeholder="Имя"> <br> <br>
//
// Отчество (если есть):<br>
// <input type = "text" name = "patronymic" size="50" placeholder="Отчество"> <br> <br>
//
// Дата Рождения: <br>
// <input type="date" name="dateOfBirth" required> <br> <br>
//
// Ваш пол: <br>
// <input type="radio" name="gender" value="Мужчина" checked> Мужчина
// <input type="radio" name="gender" value="Женжина"> Женжина<br> <br>
//
// Номер телефона (Например 1234567890): <br>
// <select name="countryCode">
// <option value="+7" >Russia +7</option>
// <option value="+38">Ukraine +38</option>
// </select>
// <input type="tel" name="phoneNumber" pattern="[0-9]{10}" maxlength="10" required placeholder="1234567890"> <br> <br>
//
// Email адрес: <br>
// <input type="Email" name="email" required> <br><br>
//
// <input type = "submit" value="Подтвердить">
// <input type="reset">
// </form>';
//
// $this->forSearchForm = '
// <form action="../search.php" target="_blank" method="post">
// <input type="search" placeholder="Поиск" name="result_search"> <br> <br>
// Среди чего найти? <br>
// <select name="key">
// <option value="surname">Фамилия</option>
// <option value="name">Имя</option>
// <option value="patronymic">Отчество</option>
// <option value="dateOfBirth">Дата рождения</option>
// <option value="gender">Пол</option>
// <option value="countryCode">Код страны</option>
// <option value="phoneNumber">Номер телефона</option>
// <option value="email">Email</option>
// </select> <br><br>
// <input type="submit" value="Поиск">
// </form>';
// }
//
// public function getInfoForm(): string
// {
// return $this->infoForm;
// }
//
// public function getForSearchForm(): string
// {
// return $this->forSearchForm;
// }
//}

View File

@ -1,6 +1,11 @@
<?php
namespace src;
use src\dto\BaseDTO;
/**
* @property int $id
* @property string $surname
* @property string $name
* @property string $patronymic
@ -10,8 +15,9 @@
* @property string $phoneNumber
* @property string $email
*/
class Information
class Information extends BaseDTO
{
public int $id;
public string $surname;
public string $name;
public string $patronymic;
@ -20,51 +26,22 @@ class Information
public string $countryCode;
public string $phoneNumber;
public string $email;
public function __construct()
{
}
/**
* @param array $dataArray
* @return void
* @return array
*/
public function load(array $dataArray): void
public function fillable(): array
{
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";
// return [
// 'surname', 'name', 'patronymic', 'dateOfBirth', 'gender', 'countryCode', 'phoneNumber', 'email'
// ];
return [
$this->surname, $this->name, $this->patronymic, $this->dateOfBirth, $this->gender, $this->countryCode, $this->phoneNumber, $this->email, "\n"
];
}
}

44
src/Processing.php Normal file
View File

@ -0,0 +1,44 @@
<?php
namespace src;
class Processing
{
public array $informationArray;
/**
* @param array $columns
* @param array $data
* @return string|null
*/
public function createJsonArray(array $columns, array $data, string $title): ?string
{
if($columns && $data) {
$this->informationArray = [
"meta" => [
"title" => $title,
"columns" => $columns,
"params" =>
[
"class" => "table table-bordered",
"border" => "1"
]
],
"data" => $data
];
return $this->toJson($this->informationArray);
}
return null;
}
/**
* @param array $infArr
* @return string|null
*/
protected function toJson(array $infArr): ?string
{
if($infArr)
return json_encode($infArr,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE);
return null;
}
}

View File

@ -0,0 +1,8 @@
<?php
namespace src\collections;
class BaseCollection
{
}

View File

@ -0,0 +1,10 @@
<?php
namespace src\collections;
class InformationCollection
{
public array $itemArr = [];
}

20
src/debug/Debug.php Normal file
View File

@ -0,0 +1,20 @@
<?php
namespace src\debug;
class Debug
{
public static function prn($content)
{
echo '<pre style="background: lightgray; border: 1px solid black; padding: 2px">';
print_r($content);
echo '</pre>';
}
public static function dd($content)
{
echo '<pre style="background: lightgray; border: 1px solid black; padding: 2px">';
print_r($content);
echo '</pre>';
die();
}
}

41
src/dto/BaseDTO.php Normal file
View File

@ -0,0 +1,41 @@
<?php
namespace src\dto;
class BaseDTO
{
public int $id;
public function fillable(): array
{
return [];
}
public function load(array $array): void
{
if (is_array($array)) {
foreach ($array as $key => $value) {
$this->{$key} = $value;
}
}
}
public function toString(): string
{
return implode(";", $this->fillable());
}
/**
* @param string $key
* @return string|null
*/
public function getByKey(string $key): ?string
{
if (isset($this->{$key})) {
return $this->{$key};
}
return null;
}
}

View File

@ -0,0 +1,164 @@
<?php
namespace src\file_db_driver;
use src\debug\Debug;
class FileDatabaseDriver
{
public string $filePath;
public $file;
public array $headKeys = [];
public array $headValues = [];
private array $resArr = [];
private array $query = [];
private int $limitInt = 10;
public array $serviceInfo = [];
public function connect(string $filePath): bool
{
$this->filePath = $filePath;
if (file_exists($this->filePath)) {
$this->file = fopen($this->filePath, "a+");
if ($this->file) {
$this->getServiceInfo();
$this->setHeadKeys();
$this->setHeadValues();
return true;
}
}
return false;
}
public function getServiceInfo(): void
{
$serviceInfo = explode(';', fgets($this->file));
foreach ($serviceInfo as $item){
$item = str_replace("\n", "", $item);
$item = str_replace("\r", "", $item);
$itemArr = explode("=", $item);
$this->serviceInfo[$itemArr[0]] = $itemArr[1];
}
}
public function setHeadKeys(): void
{
$headArr = explode(';', fgets($this->file));
foreach ($headArr as $item){
$item = str_replace("\n", "", $item);
$item = str_replace("\r", "", $item);
$this->headKeys[] = $item;
}
// $this->head = explode(';', fgets($this->file));
}
public function getHeadKeys(): array
{
return $this->headKeys;
}
public function setHeadValues(): void
{
$headArr = explode(';', fgets($this->file));
foreach ($headArr as $item){
$item = str_replace("\n", "", $item);
$item = str_replace("\r", "", $item);
$this->headValues[] = $item;
}
// $this->head = explode(';', fgets($this->file));
}
public function getHeadValues(): array
{
return $this->headValues;
}
public function find(array $query): self
{
$j = 0;
foreach ($query as $key => $value) {
if(strlen($value) > 0) {
$this->query['column'][$j] = $key;
$this->query['value'][$j] = $value;
$j++;
}
}
return $this;
}
public function limit(int $limit): self
{
$this->limitInt = $limit;
return $this;
}
public function search(): array
{
$resArr = [];
$i = 1;
while (!feof($this->file)) {
if ($i > $this->limitInt){
break;
}
$str = fgets($this->file);
if (!empty($str)){
$str = str_replace("\n", "", $str);
$str = str_replace("\r", "", $str);
$item = explode(";", $str);
$item = array_combine($this->headKeys, $item);
$cnt = count($this->query['column']);
for ($j = 0; $j < $cnt; $j++) {
if (strlen($this->searchInStr($this->query['value'][$j], $item, $this->query['column'][$j])) > 0) {
$flag = true;
} else {
$flag = false;
break;
}
}
if ($flag){
$resArr[] = $item;
$i++;
}
}
}
return $resArr;
}
protected function searchInStr(string $strForSearch, array $item, string $column): ?string
{
if (isset($item[$column])) {
if (preg_match("/" . $strForSearch . "/", $item[$column])) {
return $item[$column];
}
}
return null;
}
public function all(): array
{
$this->resArr = $this->search();
return $this->resArr;
}
public function close(): void
{
fclose($this->file);
}
public function save(string $string): void
{
// $file = fopen($fileName, "a");
fwrite($this->file, $string);
// fclose($file);
}
}