|
Server : Apache System : Linux server.mata-lashes.com 3.10.0-1160.90.1.el7.x86_64 #1 SMP Thu May 4 15:21:22 UTC 2023 x86_64 User : matalashes ( 1004) PHP Version : 8.1.29 Disable Function : NONE Directory : /home/matalashes/www/wp-content/plugins/security-malware-firewall/lib/CleantalkSP/Templates/ |
Upload File : |
<?php
namespace CleantalkSP\Templates;
/**
* Class DTO
*
* Data Transfer Object
*
* @since 2.83
* @version 1.1.0
* @package CleantalkSP\Templates
* @psalm-suppress UnusedClass
*/
class DTO
{
protected $obligatory_properties = [];
public function __construct($params = array())
{
if ( ! $this->isObligatoryParamsPresented($params) ) {
throw new \Exception('No go!');
}
foreach ( $params as $param_name => $param ) {
if ( property_exists(static::class, $param_name) ) {
$type = gettype($this->$param_name);
$this->$param_name = $param;
settype($this->$param_name, $type);
}
}
}
/**
* @param $params
*
* @return bool
* @since 1.1.0
*
*/
private function isObligatoryParamsPresented($params)
{
return empty($this->obligatory_properties) ||
count(array_intersect($this->obligatory_properties, array_keys($params))) === count(
$this->obligatory_properties
);
}
}