Compare commits
25
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8bf495c89b
|
||
|
|
74cb576a2e
|
||
|
|
4283bc9bb1
|
||
|
|
fc4c3234a7
|
||
|
|
8d490e48aa
|
||
|
|
1dcab1abe2
|
||
|
|
bda12177eb
|
||
|
|
f037de014e
|
||
|
|
8a1820275d
|
||
|
|
da2801560d
|
||
|
|
dd855a6d6b
|
||
|
|
25548176bb
|
||
|
|
f31b801c03
|
||
|
|
346b1a0ca9
|
||
|
|
6fdd25ae4b
|
||
|
|
754a23706a
|
||
|
|
78f891fbff
|
||
|
|
6989e1dcf3
|
||
|
|
1288a33ff6
|
||
|
|
a5bfc61db8
|
||
|
|
9637ebc52b
|
||
|
|
585d469b69
|
||
|
|
a17db2c79c
|
||
|
|
fd286c9cff
|
||
|
|
72fc78220f
|
No files matched your search
+2
-1
@@ -6,7 +6,8 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"vlucas/phpdotenv": "^5.5",
|
"vlucas/phpdotenv": "^5.5",
|
||||||
"symfony/console": "^5.4",
|
"symfony/console": "^5.4",
|
||||||
"phpmailer/phpmailer": "^6.8"
|
"phpmailer/phpmailer": "^6.8",
|
||||||
|
"cocur/slugify": "^4.3"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "^9.6",
|
"phpunit/phpunit": "^9.6",
|
||||||
|
|||||||
Generated
+75
-1
@@ -4,8 +4,82 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "079e8a8443fdc25cbe3b03322494b73b",
|
"content-hash": "d873b245eaaf660d70c21e06ee4bcf0a",
|
||||||
"packages": [
|
"packages": [
|
||||||
|
{
|
||||||
|
"name": "cocur/slugify",
|
||||||
|
"version": "v4.3.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/cocur/slugify.git",
|
||||||
|
"reference": "652234ef5f1be844a2ae1c36ad1b4c88b05160f9"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/cocur/slugify/zipball/652234ef5f1be844a2ae1c36ad1b4c88b05160f9",
|
||||||
|
"reference": "652234ef5f1be844a2ae1c36ad1b4c88b05160f9",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"ext-mbstring": "*",
|
||||||
|
"php": "^7.1 || ~8.0.0 || ~8.1.0 || ~8.2.0"
|
||||||
|
},
|
||||||
|
"conflict": {
|
||||||
|
"symfony/config": "<3.4 || >=4,<4.3",
|
||||||
|
"symfony/dependency-injection": "<3.4 || >=4,<4.3",
|
||||||
|
"symfony/http-kernel": "<3.4 || >=4,<4.3",
|
||||||
|
"twig/twig": "<2.12.1"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"laravel/framework": "^5.0|^6.0|^7.0|^8.0",
|
||||||
|
"latte/latte": "~2.2",
|
||||||
|
"league/container": "^2.2.0",
|
||||||
|
"mikey179/vfsstream": "~1.6.8",
|
||||||
|
"mockery/mockery": "^1.3",
|
||||||
|
"nette/di": "~2.4",
|
||||||
|
"pimple/pimple": "~1.1",
|
||||||
|
"plumphp/plum": "~0.1",
|
||||||
|
"symfony/config": "^3.4 || ^4.3 || ^5.0 || ^6.0",
|
||||||
|
"symfony/dependency-injection": "^3.4 || ^4.3 || ^5.0 || ^6.0",
|
||||||
|
"symfony/http-kernel": "^3.4 || ^4.3 || ^5.0 || ^6.0",
|
||||||
|
"symfony/phpunit-bridge": "^5.4 || ^6.0",
|
||||||
|
"twig/twig": "^2.12.1 || ~3.0",
|
||||||
|
"zendframework/zend-modulemanager": "~2.2",
|
||||||
|
"zendframework/zend-servicemanager": "~2.2",
|
||||||
|
"zendframework/zend-view": "~2.2"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Cocur\\Slugify\\": "src"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Florian Eckerstorfer",
|
||||||
|
"email": "florian@eckerstorfer.co",
|
||||||
|
"homepage": "https://florian.ec"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Ivo Bathke",
|
||||||
|
"email": "ivo.bathke@gmail.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Converts a string into a slug.",
|
||||||
|
"keywords": [
|
||||||
|
"slug",
|
||||||
|
"slugify"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/cocur/slugify/issues",
|
||||||
|
"source": "https://github.com/cocur/slugify/tree/v4.3.0"
|
||||||
|
},
|
||||||
|
"time": "2022-12-07T19:48:48+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "graham-campbell/result-type",
|
"name": "graham-campbell/result-type",
|
||||||
"version": "v1.1.1",
|
"version": "v1.1.1",
|
||||||
|
|||||||
@@ -97,28 +97,28 @@ class Select
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function where($column, string $relation = null, $value = null): Select
|
public function where($column, ?string $relation = null, $value = null): Select
|
||||||
{
|
{
|
||||||
$this->addWhereCondition('AND', $column, $relation, $value);
|
$this->addWhereCondition('AND', $column, $relation, $value);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function orWhere($column, string $relation = null, $value = null): Select
|
public function orWhere($column, ?string $relation = null, $value = null): Select
|
||||||
{
|
{
|
||||||
$this->addWhereCondition('OR', $column, $relation, $value);
|
$this->addWhereCondition('OR', $column, $relation, $value);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function having($column, string $relation = null, $value = null): Select
|
public function having($column, ?string $relation = null, $value = null): Select
|
||||||
{
|
{
|
||||||
$this->addHavingCondition('AND', $column, $relation, $value);
|
$this->addHavingCondition('AND', $column, $relation, $value);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function orHaving($column, string $relation = null, $value = null): Select
|
public function orHaving($column, ?string $relation = null, $value = null): Select
|
||||||
{
|
{
|
||||||
$this->addHavingCondition('OR', $column, $relation, $value);
|
$this->addHavingCondition('OR', $column, $relation, $value);
|
||||||
|
|
||||||
@@ -211,12 +211,12 @@ class Select
|
|||||||
$this->joins[] = [$type, $table, $column1, $relation, $column2];
|
$this->joins[] = [$type, $table, $column1, $relation, $column2];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function addWhereCondition(string $logic, $column, string $relation, $value): void
|
private function addWhereCondition(string $logic, $column, ?string $relation, $value): void
|
||||||
{
|
{
|
||||||
$this->conditions[self::CONDITION_WHERE][] = [$logic, $column, $relation, $value];
|
$this->conditions[self::CONDITION_WHERE][] = [$logic, $column, $relation, $value];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function addHavingCondition(string $logic, $column, string $relation, $value): void
|
private function addHavingCondition(string $logic, $column, ?string $relation, $value): void
|
||||||
{
|
{
|
||||||
$this->conditions[self::CONDITION_HAVING][] = [$logic, $column, $relation, $value];
|
$this->conditions[self::CONDITION_HAVING][] = [$logic, $column, $relation, $value];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,8 +12,12 @@ interface IPersistentDataManager
|
|||||||
|
|
||||||
public function selectFromDbById($id, string $type, bool $useRelations = false, array $withRelations = []);
|
public function selectFromDbById($id, string $type, bool $useRelations = false, array $withRelations = []);
|
||||||
|
|
||||||
|
public function selectFromDbBySlug(string $slug, string $type, bool $useRelations = false, array $withRelations = []);
|
||||||
|
|
||||||
public function loadRelationsFromDb(Model $model, bool $recursive = false, array $withRelations = []): void;
|
public function loadRelationsFromDb(Model $model, bool $recursive = false, array $withRelations = []): void;
|
||||||
|
|
||||||
|
public function loadMultiRelationsFromDb(array $models, string $relation, bool $useRelations = false, array $withRelations = []): void;
|
||||||
|
|
||||||
public function saveToDb(Model $model): void;
|
public function saveToDb(Model $model): void;
|
||||||
|
|
||||||
public function deleteFromDb(Model $model): void;
|
public function deleteFromDb(Model $model): void;
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ abstract class Model
|
|||||||
|
|
||||||
protected static array $relations = [];
|
protected static array $relations = [];
|
||||||
|
|
||||||
|
protected static array $multiRelations = [];
|
||||||
|
|
||||||
protected $id = null;
|
protected $id = null;
|
||||||
|
|
||||||
private array $snapshot = [];
|
private array $snapshot = [];
|
||||||
@@ -27,6 +29,11 @@ abstract class Model
|
|||||||
return static::$relations;
|
return static::$relations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getMultiRelations(): array
|
||||||
|
{
|
||||||
|
return static::$multiRelations;
|
||||||
|
}
|
||||||
|
|
||||||
public function setId($id): void
|
public function setId($id): void
|
||||||
{
|
{
|
||||||
$this->id = $id;
|
$this->id = $id;
|
||||||
@@ -41,7 +48,7 @@ abstract class Model
|
|||||||
{
|
{
|
||||||
$array = [];
|
$array = [];
|
||||||
|
|
||||||
foreach (self::getFields() as $key) {
|
foreach (static::getFields() as $key) {
|
||||||
$method = 'get' . str_replace('_', '', ucwords($key, '_'));
|
$method = 'get' . str_replace('_', '', ucwords($key, '_'));
|
||||||
|
|
||||||
if (method_exists($this, $method)) {
|
if (method_exists($this, $method)) {
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?php namespace SokoWeb\PersistentData\Model;
|
||||||
|
|
||||||
|
use Cocur\Slugify\Slugify;
|
||||||
|
|
||||||
|
abstract class ModelWithSlug extends Model
|
||||||
|
{
|
||||||
|
protected static string $slugSource;
|
||||||
|
|
||||||
|
protected ?string $slug = null;
|
||||||
|
|
||||||
|
public static function getFields(): array
|
||||||
|
{
|
||||||
|
return array_merge(['id', 'slug'], static::$fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSlug(?string $slug): void
|
||||||
|
{
|
||||||
|
$this->slug = $slug;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSlug(): ?string
|
||||||
|
{
|
||||||
|
return $this->slug;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function generateSlug(): string
|
||||||
|
{
|
||||||
|
$slugSourceGetMethod = 'get' . str_replace('_', '', ucwords(static::$slugSource, '_'));
|
||||||
|
$this->slug = Slugify::create()->slugify($this->$slugSourceGetMethod());
|
||||||
|
return $this->slug;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,9 +8,12 @@ use SokoWeb\Interfaces\Database\IAuditLogger;
|
|||||||
use SokoWeb\Interfaces\Database\IResultSet;
|
use SokoWeb\Interfaces\Database\IResultSet;
|
||||||
use SokoWeb\Interfaces\PersistentData\IPersistentDataManager;
|
use SokoWeb\Interfaces\PersistentData\IPersistentDataManager;
|
||||||
use SokoWeb\PersistentData\Model\Model;
|
use SokoWeb\PersistentData\Model\Model;
|
||||||
|
use SokoWeb\PersistentData\Model\ModelWithSlug;
|
||||||
|
|
||||||
class PersistentDataManager implements IPersistentDataManager
|
class PersistentDataManager implements IPersistentDataManager
|
||||||
{
|
{
|
||||||
|
const SLUG_MAX_LENGTH = 255;
|
||||||
|
|
||||||
private IConnection $dbConnection;
|
private IConnection $dbConnection;
|
||||||
|
|
||||||
private ?IAuditLogger $auditLogger;
|
private ?IAuditLogger $auditLogger;
|
||||||
@@ -58,6 +61,14 @@ class PersistentDataManager implements IPersistentDataManager
|
|||||||
return $this->selectFromDb($select, $type, $useRelations, $withRelations);
|
return $this->selectFromDb($select, $type, $useRelations, $withRelations);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function selectFromDbBySlug(string $slug, string $type, bool $useRelations = false, array $withRelations = [])
|
||||||
|
{
|
||||||
|
$select = new Select($this->dbConnection);
|
||||||
|
$select->where('slug', '=', $slug);
|
||||||
|
|
||||||
|
return $this->selectFromDb($select, $type, $useRelations, $withRelations);
|
||||||
|
}
|
||||||
|
|
||||||
public function loadRelationsFromDb(Model $model, bool $recursive = false, array $withRelations = []): void
|
public function loadRelationsFromDb(Model $model, bool $recursive = false, array $withRelations = []): void
|
||||||
{
|
{
|
||||||
$relations = $model::getRelations();
|
$relations = $model::getRelations();
|
||||||
@@ -81,6 +92,40 @@ class PersistentDataManager implements IPersistentDataManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function loadMultiRelationsFromDb(array $models, string $relation, bool $useRelations = false, array $withRelations = []): void
|
||||||
|
{
|
||||||
|
if (count($models) === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$parentModelType = get_class($models[0]);
|
||||||
|
$relationModelsSetter = 'set' . str_replace('_', '', ucwords($relation, '_'));
|
||||||
|
[$relationModelType, $reverseRelation] = call_user_func([$parentModelType, 'getMultiRelations'])[$relation];
|
||||||
|
$reverseRelationIdGetter = 'get' . str_replace('_', '', ucwords($reverseRelation, '_')) . 'Id';
|
||||||
|
|
||||||
|
$parentModelsById = [];
|
||||||
|
foreach ($models as $model) {
|
||||||
|
$parentModelsById[$model->getId()] = $model;
|
||||||
|
}
|
||||||
|
|
||||||
|
$select = new Select($this->dbConnection);
|
||||||
|
$select->where($reverseRelation . '_id', 'IN', array_keys($parentModelsById));
|
||||||
|
|
||||||
|
$relationsByParentModelId = [];
|
||||||
|
foreach ($this->selectMultipleFromDb($select, $relationModelType, $useRelations, $withRelations) as $relationModel) {
|
||||||
|
$reverseRelationId = $relationModel->$reverseRelationIdGetter();
|
||||||
|
if (!isset($relationsByParentModelId[$reverseRelationId])) {
|
||||||
|
$relationsByParentModelId[$reverseRelationId] = [];
|
||||||
|
}
|
||||||
|
$relationsByParentModelId[$reverseRelationId][] = $relationModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($parentModelsById as $parentModelId => $parentModel) {
|
||||||
|
$relationModels = $relationsByParentModelId[$parentModelId] ?? [];
|
||||||
|
$parentModel->$relationModelsSetter($relationModels);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function saveToDb(Model $model): void
|
public function saveToDb(Model $model): void
|
||||||
{
|
{
|
||||||
$this->syncRelations($model);
|
$this->syncRelations($model);
|
||||||
@@ -103,12 +148,21 @@ class PersistentDataManager implements IPersistentDataManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (count($modified) > 0) {
|
if (count($modified) > 0) {
|
||||||
|
if ($model instanceof ModelWithSlug && isset($modified['slug'])) {
|
||||||
|
$diff['slug']['new'] = $modified['slug'] = $this->generateUniqueSlug($model, $modified['slug']);
|
||||||
|
}
|
||||||
|
|
||||||
$modify->setId($id);
|
$modify->setId($id);
|
||||||
$modify->setDiff($diff);
|
$modify->setDiff($diff);
|
||||||
$modify->fill($modified);
|
$modify->fill($modified);
|
||||||
$modify->save();
|
$modify->save();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if ($model instanceof ModelWithSlug) {
|
||||||
|
$slug = $model->generateSlug();
|
||||||
|
$modified['slug'] = $this->generateUniqueSlug($model, $slug);
|
||||||
|
}
|
||||||
|
|
||||||
$modify->fill($modified);
|
$modify->fill($modified);
|
||||||
$modify->save();
|
$modify->save();
|
||||||
|
|
||||||
@@ -129,6 +183,29 @@ class PersistentDataManager implements IPersistentDataManager
|
|||||||
$model->resetSnapshot();
|
$model->resetSnapshot();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function generateUniqueSlug(ModelWithSlug $model, string $notUniqueSlug): string
|
||||||
|
{
|
||||||
|
$numbered = 1;
|
||||||
|
|
||||||
|
do {
|
||||||
|
if ($numbered > 1) {
|
||||||
|
$slug = substr($notUniqueSlug, 0, static::SLUG_MAX_LENGTH - (strlen((string)$numbered) + 1));
|
||||||
|
$slug = $notUniqueSlug . '_' . (string)$numbered;
|
||||||
|
} else {
|
||||||
|
$slug = substr($notUniqueSlug, 0, static::SLUG_MAX_LENGTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
$select = new Select($this->dbConnection, $model::getTable());
|
||||||
|
$select->where('slug', '=', $slug);
|
||||||
|
|
||||||
|
$numbered++;
|
||||||
|
} while ($select->count() != 0);
|
||||||
|
|
||||||
|
$model->setSlug($slug);
|
||||||
|
|
||||||
|
return $slug;
|
||||||
|
}
|
||||||
|
|
||||||
private function createSelect(Select $select, string $type, bool $useRelations = false, array $withRelations = []): Select
|
private function createSelect(Select $select, string $type, bool $useRelations = false, array $withRelations = []): Select
|
||||||
{
|
{
|
||||||
$table = call_user_func([$type, 'getTable']);
|
$table = call_user_func([$type, 'getTable']);
|
||||||
@@ -150,7 +227,7 @@ class PersistentDataManager implements IPersistentDataManager
|
|||||||
|
|
||||||
$columns = array_merge($columns, $this->getRelationColumns($table, $relations, $withRelations));
|
$columns = array_merge($columns, $this->getRelationColumns($table, $relations, $withRelations));
|
||||||
|
|
||||||
$this->leftJoinRelations($select, $table, $relations, $withRelations);
|
$this->leftJoinRelations($select, $table, $table, $relations, $withRelations);
|
||||||
$select->columns($columns);
|
$select->columns($columns);
|
||||||
} else {
|
} else {
|
||||||
$select->columns($columns);
|
$select->columns($columns);
|
||||||
@@ -180,19 +257,19 @@ class PersistentDataManager implements IPersistentDataManager
|
|||||||
return $columns;
|
return $columns;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function leftJoinRelations(Select $select, string $table, array $relations, array $withRelations): void
|
private function leftJoinRelations(Select $select, string $table, string $tableAlias, array $relations, array $withRelations): void
|
||||||
{
|
{
|
||||||
foreach ($relations as $relation => $relationType) {
|
foreach ($relations as $relation => $relationType) {
|
||||||
$relationTableAlias = $table . '__' . $relation;
|
$relationTableAlias = $table . '__' . $relation;
|
||||||
$relationTable = call_user_func([$relationType, 'getTable']);
|
$relationTable = call_user_func([$relationType, 'getTable']);
|
||||||
$select->setTableAliases([$relationTableAlias => $relationTable]);
|
$select->setTableAliases([$relationTableAlias => $relationTable]);
|
||||||
$select->leftJoin($relationTableAlias, [$relationTableAlias, 'id'], '=', [$table, $relation . '_id']);
|
$select->leftJoin($relationTableAlias, [$relationTableAlias, 'id'], '=', [$tableAlias, $relation . '_id']);
|
||||||
|
|
||||||
$relationsOfRelation = call_user_func([$relationType, 'getRelations']);
|
$relationsOfRelation = call_user_func([$relationType, 'getRelations']);
|
||||||
if (count($withRelations)) {
|
if (count($withRelations)) {
|
||||||
$relationsOfRelation = array_intersect_key($relationsOfRelation, array_flip($withRelations));
|
$relationsOfRelation = array_intersect_key($relationsOfRelation, array_flip($withRelations));
|
||||||
}
|
}
|
||||||
$this->leftJoinRelations($select, $relationTable, $relationsOfRelation, $withRelations);
|
$this->leftJoinRelations($select, $relationTable, $relationTableAlias, $relationsOfRelation, $withRelations);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,7 +312,10 @@ class PersistentDataManager implements IPersistentDataManager
|
|||||||
$method = 'set' . str_replace('_', '', ucwords($relation, '_'));
|
$method = 'set' . str_replace('_', '', ucwords($relation, '_'));
|
||||||
$model->$method($relationModel);
|
$model->$method($relationModel);
|
||||||
} else {
|
} else {
|
||||||
next($data);
|
while (substr($key, 0, strlen($relation . '__')) === $relation . '__') {
|
||||||
|
next($data);
|
||||||
|
$key = key($data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
next($relations);
|
next($relations);
|
||||||
|
|||||||
@@ -13,14 +13,17 @@ class DatabaseSessionHandler implements ISessionHandler
|
|||||||
|
|
||||||
private string $table;
|
private string $table;
|
||||||
|
|
||||||
|
private DateTime $shouldBeNewerThan;
|
||||||
|
|
||||||
private bool $exists = false;
|
private bool $exists = false;
|
||||||
|
|
||||||
private bool $written = false;
|
private bool $written = false;
|
||||||
|
|
||||||
public function __construct(IConnection $dbConnection, string $table)
|
public function __construct(IConnection $dbConnection, string $table, DateTime $shouldBeNewerThan)
|
||||||
{
|
{
|
||||||
$this->dbConnection = $dbConnection;
|
$this->dbConnection = $dbConnection;
|
||||||
$this->table = $table;
|
$this->table = $table;
|
||||||
|
$this->shouldBeNewerThan = $shouldBeNewerThan;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function open($savePath, $sessionName): bool
|
public function open($savePath, $sessionName): bool
|
||||||
@@ -36,17 +39,20 @@ class DatabaseSessionHandler implements ISessionHandler
|
|||||||
public function read($id): string
|
public function read($id): string
|
||||||
{
|
{
|
||||||
$select = new Select($this->dbConnection, $this->table);
|
$select = new Select($this->dbConnection, $this->table);
|
||||||
$select->columns(['data']);
|
$select->columns(['data', 'updated']);
|
||||||
$select->whereId(substr($id, 0, 32));
|
$select->whereId(substr($id, 0, 32));
|
||||||
|
|
||||||
$result = $select->execute()->fetch(IResultSet::FETCH_ASSOC);
|
$result = $select->execute()->fetch(IResultSet::FETCH_ASSOC);
|
||||||
|
|
||||||
if ($result === null) {
|
if ($result === null) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->exists = true;
|
$this->exists = true;
|
||||||
|
|
||||||
|
if (new DateTime($result['updated']) < $this->shouldBeNewerThan) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
return $result['data'];
|
return $result['data'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-2
@@ -97,7 +97,12 @@ class Linker
|
|||||||
|
|
||||||
fwrite($outputFileHandle, $extra[0]);
|
fwrite($outputFileHandle, $extra[0]);
|
||||||
while (($line = fgets($inputFileHandle)) !== false) {
|
while (($line = fgets($inputFileHandle)) !== false) {
|
||||||
fwrite($outputFileHandle, $line);
|
if (preg_match('/^\s*@include\((.*)\)\s*$/', $line, $matches) === 1) {
|
||||||
|
$include = file_get_contents(ROOT . '/views/' . $matches[1] . '.php');
|
||||||
|
fwrite($outputFileHandle, $include);
|
||||||
|
} else {
|
||||||
|
fwrite($outputFileHandle, $line);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fwrite($outputFileHandle, $extra[1]);
|
fwrite($outputFileHandle, $extra[1]);
|
||||||
|
|
||||||
@@ -134,7 +139,7 @@ class Linker
|
|||||||
{
|
{
|
||||||
$output = [];
|
$output = [];
|
||||||
|
|
||||||
if (preg_match('/^[\w\/\.]+$/', $asset) === 1) {
|
if (preg_match('/^http(s)?/', $asset) !== 1) {
|
||||||
if (
|
if (
|
||||||
empty($_ENV['DEV']) &&
|
empty($_ENV['DEV']) &&
|
||||||
filesize(ROOT . '/public/static/' . $asset) < self::INLINE_ASSET_LIMIT
|
filesize(ROOT . '/public/static/' . $asset) < self::INLINE_ASSET_LIMIT
|
||||||
|
|||||||
Reference in new issue
Block a user