diff --git a/README.md b/README.md index 793a0f7..8b876eb 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,4 @@ [RU] Набор компонентов для сайта на PHP для работы с базами данных - - [EN] A set of components for PHP website for work with database \ No newline at end of file diff --git a/sources/attributes/ConvertToDB.php b/sources/attributes/ConvertToDB.php new file mode 100644 index 0000000..8ce37e4 --- /dev/null +++ b/sources/attributes/ConvertToDB.php @@ -0,0 +1,45 @@ +ConvertToDB = $fromType; + $this->ConvertFromDB = $toType; + } + } \ No newline at end of file diff --git a/sources/attributes/IgnoredInDB.php b/sources/attributes/IgnoredInDB.php new file mode 100644 index 0000000..d1d6878 --- /dev/null +++ b/sources/attributes/IgnoredInDB.php @@ -0,0 +1,47 @@ +IgnoredOperations = new ObjectArray($ignoredOperations); + } + } \ No newline at end of file diff --git a/sources/attributes/PrimaryKey.php b/sources/attributes/PrimaryKey.php new file mode 100644 index 0000000..0493e5f --- /dev/null +++ b/sources/attributes/PrimaryKey.php @@ -0,0 +1,29 @@ +Driver = $driver; - $this->Host = $host; - $this->Port = $port; - $this->Name = $name; - $this->UserName = $userName; - $this->Password = $password; - $this->Chipper = $chipper; - } - - /** - * @inheritDoc - */ - public function UnSerialize (string $serialized): void - { - // Десериализую массив - $array = json_decode($serialized, true); - - // Заполняю поля - if (isset($array["host"])) - $this->Host = $array["host"]; - if (isset($array["port"])) - $this->Port = $array["port"]; - if (isset($array["name"])) - $this->Name = $array["name"]; - if (isset($array["user"])) - $this->UserName = $array["user"]; - if (isset($array["password"])) - $this->Password = Encryptor::Decrypt($array["password"], $this->Chipper); - if (isset($array["driver"])) - $this->Driver = DBDriver::FromInt($array["driver"]); - } - - /** - * @inheritDoc - */ - public function Serialize (): string - { - // Создаю массив результата - $result = []; - - // Заполняю массив - $result["host"] = $this->Host; - $result["port"] = $this->Port; - $result["name"] = $this->Name; - $result["user"] = $this->UserName; - $result["password"] = Encryptor::Encrypt($this->Password, $this->Chipper); - $result["driver"] = $this->Driver->ToInt(); - - // Сериализую - return json_encode($result, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); - } -} \ No newline at end of file + /** + * @var string $Host Хост базы данных. + */ + public string $Host; + + /** + * @var int $Port Порт базы данных. + * @between 0...65535 + */ + public int $Port; + + /** + * @var string $Name Имя базы данных. + */ + public string $Name; + + /** + * @var string $UserName Имя пользователя базы данных. + */ + public string $UserName; + + /** + * @var string $Password Пароль пользователя базы данных. + */ + public string $Password; + + /** + * @var DBDriver $Driver Тип драйвера базы данных. + */ + public DBDriver $Driver; + + /** + * @var string $Chipper Пароль шифрования. + */ + private string $Chipper; + + /** + * Конструктор. + * + * @param DBDriver $driver Тип драйвера базы данных. + * @param string $host Хост базы данных. + * @param int $port Порт базы данных. + * @param string $name Имя базы данных. + * @param string $userName Имя пользователя базы данных. + * @param string $password Пароль пользователя базы данных. + * @param string $chipper Пароль шифрования. + */ + public function __construct (DBDriver $driver = DBDriver::MySQL, string $host = "", int $port = 0, + string $name = "", string $userName = "", string $password = "", string $chipper = "") + { + $this->Driver = $driver; + $this->Host = $host; + $this->Port = $port; + $this->Name = $name; + $this->UserName = $userName; + $this->Password = $password; + $this->Chipper = $chipper; + } + + /** + * @inheritDoc + */ + public function UnSerialize (string $serialized): void + { + // Десериализую массив + $array = json_decode($serialized, true); + + // Заполняю поля + if (isset($array["host"])) + $this->Host = $array["host"]; + if (isset($array["port"])) + $this->Port = $array["port"]; + if (isset($array["name"])) + $this->Name = $array["name"]; + if (isset($array["user"])) + $this->UserName = $array["user"]; + if (isset($array["password"])) + $this->Password = Encryptor::Decrypt($array["password"], $this->Chipper); + if (isset($array["driver"])) + $this->Driver = DBDriver::FromInt($array["driver"]); + } + + /** + * @inheritDoc + */ + public function Serialize (): string + { + // Создаю массив результата + $result = []; + + // Заполняю массив + $result["host"] = $this->Host; + $result["port"] = $this->Port; + $result["name"] = $this->Name; + $result["user"] = $this->UserName; + $result["password"] = Encryptor::Encrypt($this->Password, $this->Chipper); + $result["driver"] = $this->Driver->ToInt(); + + // Сериализую + return json_encode($result, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); + } + } \ No newline at end of file