class Comparator
{
private $value;
private $compareValue;
public function __construct($value, $compareValue = null)
{
$this->value = $value;
$this->compareValue = $compareValue;
// for float comparison
if (is_numeric($this->value) && is_numeric($this->compareValue)) {
$this->value *= 100;
$this->compareValue *= 100;
}
}
public function equals(): bool
{
return $this->value === $this->compareValue;
}
public function notEquals(): bool
{
return $this->value !== $this->compareValue;
}
public function greaterThan(): bool
{
return $this->value > $this->compareValue;
}
public function greaterThanOrEqual(): bool
{
return $this->value >= $this->compareValue;
}
public function lessThan(): bool
{
return $this->value < $this->compareValue;
}
public function lessThanOrEqual(): bool
{
return $this->value <= $this->compareValue;
}
public function isNull(): bool
{
return $this->value === null;
}
public function isNotNull(): bool
{
return $this->value !== null;
}
public function isTrue(): bool
{
return $this->value === true;
}
public function isFalse(): bool
{
return !$this->isTrue();
}
public function and(): bool
{
return $this->value && $this->compareValue;
}
public function or(): bool
{
return $this->value || $this->compareValue;
}
}
/*
"{value} >= 5 || {value} < 6.7",
"{value} !== 'test' && {value} === true'
*/
$compare = new Comparator(10, 5);
$c1 = $compare->greaterThanOrEqual();
$compare = new Comparator(10.3, 6.7);
$c2 = $compare->lessThan();
var_dump($c1);
var_dump($c2);
$compare = new Comparator($c1, $c2);
$c3 = $compare->or();
var_dump($c3);
class Core{
private $db; // подключаем бд
// Даем переменные
private $userData = array(); // Все данные пользователя
// Главные функции тут
public function __construct() {
$this->authorize(); // Авторизация пользователя
}
// Проверка авторизации
private function authorize() {
if (isset($_COOKIE['autes'])):
$cookieToken = $_COOKIE['autes'];
$req = DB::$dbs->query('SELECT * FROM `user` WHERE `autes` = ? LIMIT 1',[$cookieToken]);
if ($req->rowCount()):
$this->userData = $req->fetch();
else:
setcookie('autes','',time()-3600,'/');
endif;
endif;
}
public function getData()
{
return $this->userData ?? null;
}
}
$core = new Core();
$data = $core->getData():