chore: Аннотации к типам
This commit is contained in:
parent
704e4e0bd5
commit
8588173079
9 changed files with 80 additions and 27 deletions
|
|
@ -6,6 +6,7 @@ use PDO;
|
||||||
class StatementIterator implements \Iterator
|
class StatementIterator implements \Iterator
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/** @var PDOStatement */
|
||||||
private $result;
|
private $result;
|
||||||
/** @var int */
|
/** @var int */
|
||||||
private $pos = 0;
|
private $pos = 0;
|
||||||
|
|
|
||||||
|
|
@ -4,5 +4,9 @@ namespace ctiso\Filter;
|
||||||
use ctiso\HttpRequest;
|
use ctiso\HttpRequest;
|
||||||
|
|
||||||
interface FilterInterface {
|
interface FilterInterface {
|
||||||
|
/**
|
||||||
|
* @param HttpRequest $request
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
function execute(HttpRequest $request);
|
function execute(HttpRequest $request);
|
||||||
}
|
}
|
||||||
|
|
@ -2,31 +2,34 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Фильтр для проверки авторизации
|
* Фильтр для проверки авторизации
|
||||||
*
|
|
||||||
* action: login(password, login)
|
|
||||||
* action: logout()
|
|
||||||
*/
|
*/
|
||||||
|
namespace ctiso\Filter;
|
||||||
|
|
||||||
|
use ctiso\Filter\Filter;
|
||||||
|
use ctiso\HttpRequest;
|
||||||
|
use ctiso\Settings;
|
||||||
|
use ctiso\Registry;
|
||||||
|
use ctiso\Database;
|
||||||
|
use ctiso\Role\User;
|
||||||
|
use ctiso\Collection;
|
||||||
|
use ctiso\Path;
|
||||||
|
use ctiso\Database\PDOStatement;
|
||||||
|
|
||||||
// В класс авторизации передавать обьект для управления пользователем
|
// В класс авторизации передавать обьект для управления пользователем
|
||||||
// Вынести в отдельный файл
|
// Вынести в отдельный файл
|
||||||
namespace ctiso\Filter;
|
|
||||||
use ctiso\Filter\Filter,
|
|
||||||
ctiso\HttpRequest,
|
|
||||||
ctiso\Settings,
|
|
||||||
ctiso\Registry,
|
|
||||||
ctiso\Database,
|
|
||||||
ctiso\Role\User,
|
|
||||||
ctiso\Collection,
|
|
||||||
ctiso\Path;
|
|
||||||
|
|
||||||
class Login extends Filter
|
class Login extends Filter
|
||||||
{
|
{
|
||||||
const SESSION_BROWSER_SIGN_SECRET = '@w3dsju45Msk#';
|
const SESSION_BROWSER_SIGN_SECRET = '@w3dsju45Msk#';
|
||||||
const SESSION_BROWSER_SIGN_KEYNAME = 'session.app.browser.sign';
|
const SESSION_BROWSER_SIGN_KEYNAME = 'session.app.browser.sign';
|
||||||
const AUTH_MAX_ATTEMPT = 10;
|
const AUTH_MAX_ATTEMPT = 10;
|
||||||
const AUTH_LAST_ATTEMPT_TIMER = 600;
|
const AUTH_LAST_ATTEMPT_TIMER = 600;
|
||||||
|
/** @var string */
|
||||||
public $mode = 'ajax';
|
public $mode = 'ajax';
|
||||||
|
/** @var PDOStatement */
|
||||||
public $user;
|
public $user;
|
||||||
|
/** @var User */
|
||||||
public $role;
|
public $role;
|
||||||
|
/** @var Registry */
|
||||||
public $config;
|
public $config;
|
||||||
|
|
||||||
function __construct($processor, User $role, Registry $config) {
|
function __construct($processor, User $role, Registry $config) {
|
||||||
|
|
@ -125,11 +128,15 @@ class Login extends Filter
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Вход в систему
|
||||||
|
* @param PDOStatement $result
|
||||||
|
*/
|
||||||
private function enter($result): void
|
private function enter($result): void
|
||||||
{
|
{
|
||||||
$this->user = $result;
|
$this->user = $result;
|
||||||
$random = rand(0, 1024 * 1024);
|
$random = rand(0, 1024 * 1024);
|
||||||
$this->role->setSID($random, $result);
|
$this->role->setSID((string)$random, $result);
|
||||||
|
|
||||||
$_SESSION["group"] = $result->getInt('access');
|
$_SESSION["group"] = $result->getInt('access');
|
||||||
$_SESSION["access"] = $result->getInt('id_user'); // id_user
|
$_SESSION["access"] = $result->getInt('id_user'); // id_user
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,12 @@ class right {
|
||||||
$this->params = $params;
|
$this->params = $params;
|
||||||
}
|
}
|
||||||
|
|
||||||
function apply() {
|
/**
|
||||||
$params = func_get_args();
|
* Применение функции
|
||||||
|
* @param mixed ...$params
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
function apply(...$params) {
|
||||||
array_splice($params, count($params), 0, $this->params);
|
array_splice($params, count($params), 0, $this->params);
|
||||||
return call_user_func_array($this->fn, $params);
|
return call_user_func_array($this->fn, $params);
|
||||||
}
|
}
|
||||||
|
|
@ -40,8 +44,12 @@ class left {
|
||||||
$this->params = $params;
|
$this->params = $params;
|
||||||
}
|
}
|
||||||
|
|
||||||
function apply() {
|
/**
|
||||||
$params = func_get_args();
|
* Применение функции
|
||||||
|
* @param mixed ...$params
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
function apply(...$params) {
|
||||||
array_splice ($params, 0, 0, $this->params);
|
array_splice ($params, 0, 0, $this->params);
|
||||||
return call_user_func_array ($this->fn, $params);
|
return call_user_func_array ($this->fn, $params);
|
||||||
}
|
}
|
||||||
|
|
@ -171,7 +179,7 @@ class Functions {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* @deprecated
|
||||||
* @param array $value
|
* @param array<string, mixed> $value
|
||||||
* @param string $name
|
* @param string $name
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
|
|
@ -182,6 +190,9 @@ class Functions {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* @deprecated
|
||||||
|
* @param mixed $value
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
static function identity($value) {
|
static function identity($value) {
|
||||||
return $value;
|
return $value;
|
||||||
|
|
@ -191,7 +202,7 @@ class Functions {
|
||||||
* @deprecated use fn and <=> operator
|
* @deprecated use fn and <=> operator
|
||||||
* @param array $a
|
* @param array $a
|
||||||
* @param array $b
|
* @param array $b
|
||||||
* @param $key
|
* @param string|int $key
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
|
|
@ -206,7 +217,7 @@ class Functions {
|
||||||
* @deprecated use fn and <=> operator
|
* @deprecated use fn and <=> operator
|
||||||
* @param array $a
|
* @param array $a
|
||||||
* @param array $b
|
* @param array $b
|
||||||
* @param $key
|
* @param string|int $key
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,10 @@ class HttpRequest extends Collection
|
||||||
parent::get('data')->set($key, $value);
|
parent::get('data')->set($key, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $key
|
||||||
|
* @return array<mixed>
|
||||||
|
*/
|
||||||
function export(string $key = 'data')
|
function export(string $key = 'data')
|
||||||
{
|
{
|
||||||
return parent::get($key)->export();
|
return parent::get($key)->export();
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,9 @@ use ctiso\Filter\Filter,
|
||||||
|
|
||||||
class Blank extends Filter
|
class Blank extends Filter
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
function execute(HttpRequest $request)
|
function execute(HttpRequest $request)
|
||||||
{
|
{
|
||||||
$text = $this->processor->execute($request);
|
$text = $this->processor->execute($request);
|
||||||
|
|
|
||||||
|
|
@ -8,21 +8,29 @@
|
||||||
namespace ctiso;
|
namespace ctiso;
|
||||||
|
|
||||||
class Primitive {
|
class Primitive {
|
||||||
// varchar
|
/**
|
||||||
|
* @param mixed $value
|
||||||
|
*/
|
||||||
public static function to_varchar($value): string
|
public static function to_varchar($value): string
|
||||||
{
|
{
|
||||||
return ((string) $value);
|
return ((string) $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed $value
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
public static function from_varchar($value)
|
public static function from_varchar($value)
|
||||||
{
|
{
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// int
|
/**
|
||||||
|
* @param mixed $value
|
||||||
|
*/
|
||||||
public static function to_bool($value): bool
|
public static function to_bool($value): bool
|
||||||
{
|
{
|
||||||
return filter_var($value, FILTER_VALIDATE_BOOLEAN);//(int)((bool) $value);
|
return filter_var($value, FILTER_VALIDATE_BOOLEAN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,10 @@ use ctiso\File,
|
||||||
Exception;
|
Exception;
|
||||||
|
|
||||||
class Registry {
|
class Registry {
|
||||||
|
/** @var array<string, array{path: string, data: mixed}> */
|
||||||
private array $namespace = [];
|
private array $namespace = [];
|
||||||
|
|
||||||
function importFile(string $namespace, ?string $filePath = null) {
|
function importFile(string $namespace, ?string $filePath = null): void {
|
||||||
$data = json_decode(File::getContents($filePath), true);
|
$data = json_decode(File::getContents($filePath), true);
|
||||||
$data['_file'] = $filePath;
|
$data['_file'] = $filePath;
|
||||||
$this->namespace[$namespace] = [
|
$this->namespace[$namespace] = [
|
||||||
|
|
@ -16,7 +17,7 @@ class Registry {
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
function importArray(string $namespace, array $data = []) {
|
function importArray(string $namespace, array $data = []): void {
|
||||||
if (isset($this->namespace[$namespace])) {
|
if (isset($this->namespace[$namespace])) {
|
||||||
$data = array_merge($this->namespace[$namespace]['data'], $data);
|
$data = array_merge($this->namespace[$namespace]['data'], $data);
|
||||||
}
|
}
|
||||||
|
|
@ -26,6 +27,12 @@ class Registry {
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $ns
|
||||||
|
* @param string $key
|
||||||
|
* @return mixed
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
public function get(string $ns, string $key) {
|
public function get(string $ns, string $key) {
|
||||||
if (isset($this->namespace[$ns]['data'][$key])) {
|
if (isset($this->namespace[$ns]['data'][$key])) {
|
||||||
return $this->namespace[$ns]['data'][$key];
|
return $this->namespace[$ns]['data'][$key];
|
||||||
|
|
|
||||||
|
|
@ -93,8 +93,16 @@ class User implements UserInterface
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $random
|
||||||
|
* @param PDOStatement $result
|
||||||
|
* @return PDOStatement
|
||||||
|
*/
|
||||||
function setSID(string $random, $result) {
|
function setSID(string $random, $result) {
|
||||||
return $this->db->executeQuery("UPDATE users SET sid = '$random', trie_count = 0 WHERE id_user = " . $result->getInt('id_user'));
|
return $this->db->executeQuery("UPDATE users SET sid = :sid, trie_count = 0 WHERE id_user = :user", [
|
||||||
|
'user' => $result->getInt('id_user'),
|
||||||
|
'sid' => $random
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetTries(string $login): void {
|
function resetTries(string $login): void {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue