Compare commits
9
Commits
v0.7
..
0da1d00c3d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0da1d00c3d
|
||
|
|
c57d1d40d4
|
||
|
|
6a35344210
|
||
|
|
9ade08d8bd
|
||
|
|
a982be6645
|
||
|
|
219b42f995
|
||
|
|
70a9e492e3
|
||
|
|
e9bfe4e4ad
|
||
|
|
cf329a20e5
|
No files matched your search
@@ -276,13 +276,12 @@ class Select
|
||||
return [(string) $table, $params];
|
||||
}
|
||||
|
||||
if ($table instanceof Select)
|
||||
{
|
||||
if ($table instanceof Select) {
|
||||
return $table->generateQuery();
|
||||
}
|
||||
|
||||
if (isset($this->tableAliases[$table])) {
|
||||
$queryString = ($defineAlias ? Utils::backtick($this->tableAliases[$table]) . ' ' . Utils::backtick($table) : Utils::backtick($table));
|
||||
$queryString = $defineAlias ? Utils::backtick($this->tableAliases[$table]) . ' ' . Utils::backtick($table) : Utils::backtick($table);
|
||||
return [$queryString, $params];
|
||||
}
|
||||
|
||||
@@ -295,24 +294,17 @@ class Select
|
||||
return (string) $column;
|
||||
}
|
||||
|
||||
if (is_array($column)) {
|
||||
$out = '';
|
||||
|
||||
if ($column[0]) {
|
||||
list($tableName, $params) = $this->generateTable($column[0]);
|
||||
$out .= $tableName . '.';
|
||||
}
|
||||
|
||||
$out .= Utils::backtick($column[1]);
|
||||
|
||||
if (!empty($column[2])) {
|
||||
$out .= ' ' . Utils::backtick($column[2]);
|
||||
}
|
||||
|
||||
return $out;
|
||||
} else {
|
||||
return Utils::backtick($column);
|
||||
if (!is_array($column)) {
|
||||
$column = [$this->table, $column];
|
||||
}
|
||||
|
||||
list($tableName, $params) = $this->generateTable($column[0]);
|
||||
$out = $tableName . '.' . Utils::backtick($column[1]);
|
||||
if (!empty($column[2])) {
|
||||
$out .= ' ' . Utils::backtick($column[2]);
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
private function generateColumns(): string
|
||||
|
||||
@@ -4,7 +4,7 @@ use SokoWeb\Interfaces\Authentication\IUser;
|
||||
|
||||
interface IRequest
|
||||
{
|
||||
public function setParsedRouteParams(array &$routeParams): void;
|
||||
public function setParsedRouteParams(array $routeParams): void;
|
||||
|
||||
public function getBase(): string;
|
||||
|
||||
|
||||
@@ -148,7 +148,7 @@ class PersistentDataManager implements IPersistentDataManager
|
||||
$relations = array_intersect_key($relations, array_flip($withRelations));
|
||||
}
|
||||
|
||||
$columns = array_merge($columns, $this->getRelationColumns($relations, $withRelations));
|
||||
$columns = array_merge($columns, $this->getRelationColumns($table, $relations, $withRelations));
|
||||
|
||||
$this->leftJoinRelations($select, $table, $relations, $withRelations);
|
||||
$select->columns($columns);
|
||||
@@ -159,21 +159,22 @@ class PersistentDataManager implements IPersistentDataManager
|
||||
return $select;
|
||||
}
|
||||
|
||||
private function getRelationColumns(array $relations, array $withRelations): array
|
||||
private function getRelationColumns(string $table, array $relations, array $withRelations): array
|
||||
{
|
||||
$columns = [];
|
||||
|
||||
foreach ($relations as $relation => $relationType) {
|
||||
$relationTableAlias = $table . '__' . $relation;
|
||||
$relationTable = call_user_func([$relationType, 'getTable']);
|
||||
foreach (call_user_func([$relationType, 'getFields']) as $relationField) {
|
||||
$columns[] = [$relationTable, $relationField, $relation . '__' . $relationField];
|
||||
$columns[] = [$relationTableAlias, $relationField, $relation . '__' . $relationField];
|
||||
}
|
||||
|
||||
$relationsOfRelation = call_user_func([$relationType, 'getRelations']);
|
||||
if (count($withRelations)) {
|
||||
$relationsOfRelation = array_intersect_key($relationsOfRelation, array_flip($withRelations));
|
||||
}
|
||||
$columns = array_merge($columns, $this->getRelationColumns($relationsOfRelation, $withRelations));
|
||||
$columns = array_merge($columns, $this->getRelationColumns($relationTable, $relationsOfRelation, $withRelations));
|
||||
}
|
||||
|
||||
return $columns;
|
||||
@@ -182,14 +183,16 @@ class PersistentDataManager implements IPersistentDataManager
|
||||
private function leftJoinRelations(Select $select, string $table, array $relations, array $withRelations): void
|
||||
{
|
||||
foreach ($relations as $relation => $relationType) {
|
||||
$relationTableAlias = $table . '__' . $relation;
|
||||
$relationTable = call_user_func([$relationType, 'getTable']);
|
||||
$select->leftJoin($relationTable, [$relationTable, 'id'], '=', [$table, $relation . '_id']);
|
||||
$select->setTableAliases([$relationTableAlias => $relationTable]);
|
||||
$select->leftJoin($relationTableAlias, [$relationTableAlias, 'id'], '=', [$table, $relation . '_id']);
|
||||
|
||||
$nextOrderRelations = call_user_func([$relationType, 'getRelations']);
|
||||
$relationsOfRelation = call_user_func([$relationType, 'getRelations']);
|
||||
if (count($withRelations)) {
|
||||
$nextOrderRelations = array_intersect_key($nextOrderRelations, array_flip($withRelations));
|
||||
$relationsOfRelation = array_intersect_key($relationsOfRelation, array_flip($withRelations));
|
||||
}
|
||||
$this->leftJoinRelations($select, $relationTable, $nextOrderRelations, $withRelations);
|
||||
$this->leftJoinRelations($select, $relationTable, $relationsOfRelation, $withRelations);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,12 +227,16 @@ class PersistentDataManager implements IPersistentDataManager
|
||||
|
||||
next($data);
|
||||
} else if (substr($key, 0, strlen($relation . '__')) === $relation . '__') {
|
||||
$relationType = current($relations);
|
||||
$relationModel = new $relationType();
|
||||
$this->fillWithData($data, $relationModel, $withRelations, $relation);
|
||||
if ($data[$relation . '__id'] !== null) {
|
||||
$relationType = current($relations);
|
||||
$relationModel = new $relationType();
|
||||
$this->fillWithData($data, $relationModel, $withRelations, $relation);
|
||||
|
||||
$method = 'set' . str_replace('_', '', ucwords($relation, '_'));
|
||||
$model->$method($relationModel);
|
||||
$method = 'set' . str_replace('_', '', ucwords($relation, '_'));
|
||||
$model->$method($relationModel);
|
||||
} else {
|
||||
next($data);
|
||||
}
|
||||
|
||||
next($relations);
|
||||
} else {
|
||||
|
||||
@@ -17,23 +17,23 @@ class Request implements IRequest
|
||||
|
||||
private array $headers;
|
||||
|
||||
private Session $session;
|
||||
private ISession $session;
|
||||
|
||||
private ?IUser $user = null;
|
||||
|
||||
public function __construct(
|
||||
string $base,
|
||||
array &$get,
|
||||
array &$post,
|
||||
array $get,
|
||||
array $post,
|
||||
array $headers,
|
||||
array &$session,
|
||||
ISession $session,
|
||||
IUserRepository $userRepository)
|
||||
{
|
||||
$this->base = $base;
|
||||
$this->get = &$get;
|
||||
$this->post = &$post;
|
||||
$this->get = $get;
|
||||
$this->post = $post;
|
||||
$this->headers = $headers;
|
||||
$this->session = new Session($session);
|
||||
$this->session = $session;
|
||||
|
||||
$userId = $this->session->get('userId');
|
||||
if ($userId !== null) {
|
||||
@@ -41,9 +41,9 @@ class Request implements IRequest
|
||||
}
|
||||
}
|
||||
|
||||
public function setParsedRouteParams(array &$routeParams): void
|
||||
public function setParsedRouteParams(array $routeParams): void
|
||||
{
|
||||
$this->routeParams = &$routeParams;
|
||||
$this->routeParams = $routeParams;
|
||||
}
|
||||
|
||||
public function getBase(): string
|
||||
|
||||
@@ -11,13 +11,16 @@ class DatabaseSessionHandler implements ISessionHandler
|
||||
{
|
||||
private IConnection $dbConnection;
|
||||
|
||||
private string $table;
|
||||
|
||||
private bool $exists = false;
|
||||
|
||||
private bool $written = false;
|
||||
|
||||
public function __construct(IConnection $dbConnection)
|
||||
public function __construct(IConnection $dbConnection, string $table)
|
||||
{
|
||||
$this->dbConnection = $dbConnection;
|
||||
$this->table = $table;
|
||||
}
|
||||
|
||||
public function open($savePath, $sessionName): bool
|
||||
@@ -32,7 +35,7 @@ class DatabaseSessionHandler implements ISessionHandler
|
||||
|
||||
public function read($id): string
|
||||
{
|
||||
$select = new Select($this->dbConnection, 'sessions');
|
||||
$select = new Select($this->dbConnection, $this->table);
|
||||
$select->columns(['data']);
|
||||
$select->whereId(substr($id, 0, 32));
|
||||
|
||||
@@ -49,7 +52,7 @@ class DatabaseSessionHandler implements ISessionHandler
|
||||
|
||||
public function write($id, $data): bool
|
||||
{
|
||||
$modify = new Modify($this->dbConnection, 'sessions');
|
||||
$modify = new Modify($this->dbConnection, $this->table);
|
||||
|
||||
if ($this->exists) {
|
||||
$modify->setId(substr($id, 0, 32));
|
||||
@@ -68,7 +71,7 @@ class DatabaseSessionHandler implements ISessionHandler
|
||||
|
||||
public function destroy($id): bool
|
||||
{
|
||||
$modify = new Modify($this->dbConnection, 'sessions');
|
||||
$modify = new Modify($this->dbConnection, $this->table);
|
||||
$modify->setId(substr($id, 0, 32));
|
||||
$modify->delete();
|
||||
|
||||
@@ -101,7 +104,7 @@ class DatabaseSessionHandler implements ISessionHandler
|
||||
return true;
|
||||
}
|
||||
|
||||
$modify = new Modify($this->dbConnection, 'sessions');
|
||||
$modify = new Modify($this->dbConnection, $this->table);
|
||||
|
||||
$modify->setId(substr($id, 0, 32));
|
||||
$modify->set('updated', (new DateTime())->format('Y-m-d H:i:s'));
|
||||
|
||||
@@ -14,7 +14,7 @@ Container::$routeCollection = new SokoWeb\Routing\RouteCollection();
|
||||
Container::$routeCollection->get('index', '', [{app}\Controller\HomeController::class, 'getIndex']);
|
||||
|
||||
if (isset($_COOKIE['COOKIES_CONSENT'])) {
|
||||
Container::$sessionHandler = new SokoWeb\Session\DatabaseSessionHandler(Container::$dbConnection);
|
||||
Container::$sessionHandler = new SokoWeb\Session\DatabaseSessionHandler(Container::$dbConnection, 'sessions');
|
||||
|
||||
session_set_save_handler(Container::$sessionHandler, true);
|
||||
session_start([
|
||||
|
||||
Reference in new issue
Block a user