45 lines
1.2 KiB
PHP
45 lines
1.2 KiB
PHP
|
|
<?php
|
||
|
|
abstract class BaseController
|
||
|
|
{
|
||
|
|
public $post = [];
|
||
|
|
public $query = [];
|
||
|
|
|
||
|
|
public function __construct()
|
||
|
|
{
|
||
|
|
$this->post = json_decode(file_get_contents("php://input"));
|
||
|
|
$url = $_SERVER['REQUEST_URI'];
|
||
|
|
$this->query = $_GET;
|
||
|
|
|
||
|
|
$this->files = $_FILES;
|
||
|
|
// var_dump($_FILES);die;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function response($data, $status = true)
|
||
|
|
{
|
||
|
|
$result = [
|
||
|
|
'status' => $status,
|
||
|
|
];
|
||
|
|
|
||
|
|
if (!$status) {
|
||
|
|
$result['errors'] = $data;
|
||
|
|
} else {
|
||
|
|
$result['data'] = $data;
|
||
|
|
}
|
||
|
|
echo json_encode($result, JSON_UNESCAPED_UNICODE);
|
||
|
|
exit;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function clearInput($string) { // очистка входящего элимента
|
||
|
|
$string = strip_tags($string); // от тегов
|
||
|
|
$string = htmlspecialchars($string); // от кавычек и прочего
|
||
|
|
$string = str_replace("\n", "<br>", $string);
|
||
|
|
$string = str_replace("\r", "", $string);
|
||
|
|
$string = mysql_real_escape_string($string); // от MySQL-инъекций
|
||
|
|
$string = trim($string); // от лишних пробелов
|
||
|
|
$string = stripslashes($string); // от слэшей
|
||
|
|
|
||
|
|
return $string;
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|