This commit is contained in:
Ваше Имя 2025-07-28 01:31:25 +05:00
parent ab21e31a09
commit a257f257a0
68 changed files with 833 additions and 1286 deletions

View File

@ -10,7 +10,6 @@
"license": "MIT",
"require": {
"php": "^8.2",
"hrustbb2/arrayproc": "^1.0",
"intervention/image": "^3.11",
"laravel/framework": "^12.0",
"laravel/tinker": "^2.10.1"

52
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "5e576ac699c4de01e220426df03617e0",
"content-hash": "51576dda271759cce587475988cbe4e8",
"packages": [
{
"name": "brick/math",
@ -1054,56 +1054,6 @@
],
"time": "2025-02-03T10:55:03+00:00"
},
{
"name": "hrustbb2/arrayproc",
"version": "v1.0.0",
"source": {
"type": "git",
"url": "https://github.com/hrustbb2/arrayproc.git",
"reference": "5e55e374786061da44df086e9d51d02bcf77c519"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/hrustbb2/arrayproc/zipball/5e55e374786061da44df086e9d51d02bcf77c519",
"reference": "5e55e374786061da44df086e9d51d02bcf77c519",
"shasum": ""
},
"require": {
"php": ">=5.5.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.14",
"phpunit/phpunit": "^8.0"
},
"type": "library",
"autoload": {
"psr-4": {
"hrustbb2\\tests\\": "tests/",
"hrustbb2\\arrayproc\\": "arrayproc/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "hrustbb2",
"email": "hrustbb2@gmail.com",
"role": "Developer"
}
],
"description": "A PHP arrayprocessor",
"keywords": [
"arrayprocessor",
"orm"
],
"support": {
"issues": "https://github.com/hrustbb2/arrayproc/issues",
"source": "https://github.com/hrustbb2/arrayproc/tree/master"
},
"time": "2020-02-27T15:58:37+00:00"
},
{
"name": "intervention/gif",
"version": "4.2.2",

1
public/files-browser Symbolic link
View File

@ -0,0 +1 @@
../storage/uploads/files-browser

View File

@ -1,32 +0,0 @@
<?php
namespace Src\Lib\CategoriesTree\Application;
use Src\Lib\CategoriesTree\Interfaces\Application\IDataBuilder;
use Src\Lib\CategoriesTree\Interfaces\Infrastructure\IStorage;
class DataBuilder implements IDataBuilder {
protected IStorage $storage;
public function setStorage(IStorage $storage):void
{
$this->storage = $storage;
}
public function buildData(array $requestData):array
{
$dsl = [
'id', 'matherial_path',
'path' => ['id']
];
$parentData = $this->storage->getById($requestData['parent-dir'], $dsl);
if($parentData){
$requestData['parent'] = [
$parentData['id'] => $parentData,
];
}
return $requestData;
}
}

View File

@ -1,135 +0,0 @@
<?php
namespace Src\Lib\CategoriesTree\Application;
use Src\Common\Application\TraitDomain;
use Src\Common\Application\ResponsesCode;
use Src\Lib\CategoriesTree\Interfaces\Application\IDomain;
use Src\Lib\CategoriesTree\Interfaces\Application\IValidator;
use Src\Lib\CategoriesTree\Interfaces\Application\IDataBuilder;
use Src\Lib\CategoriesTree\Interfaces\Dto\IFactory as IDtoFactory;
use Src\Lib\CategoriesTree\Interfaces\Dto\IResource;
use Src\Lib\CategoriesTree\Interfaces\Infrastructure\IPersistLayer;
use Src\Lib\CategoriesTree\Interfaces\Infrastructure\IStorage;
use \Throwable;
use Illuminate\Support\Facades\Log;
class Domain implements IDomain
{
use TraitDomain;
protected IValidator $validator;
protected IDataBuilder $dataBuilder;
protected IDtoFactory $dtoFactory;
protected IPersistLayer $persistLayer;
protected IStorage $storage;
protected ?IResource $dir = null;
public function setValidator(IValidator $validator): void
{
$this->validator = $validator;
}
public function setDataBuilder(IDataBuilder $builder): void
{
$this->dataBuilder = $builder;
}
public function setDtoFactory(IDtoFactory $factory): void
{
$this->dtoFactory = $factory;
}
public function setPersistLayer(IPersistLayer $layer): void
{
$this->persistLayer = $layer;
}
public function setStorage(IStorage $storage): void
{
$this->storage = $storage;
}
public function createDir(array $data): bool
{
$this->dir = $this->dtoFactory->createResource();
if ($this->validator->createDir($data)) {
try {
$cleanData = $this->validator->getCleanData();
$dirData = $this->dataBuilder->buildData($cleanData);
$dirPersist = $this->dtoFactory->createPersist();
$dirPersist->load($dirData);
$this->persistLayer->newDir($dirPersist);
$this->dir->load($dirPersist->getAttributes());
return true;
} catch (Throwable $e) {
Log::error($e);
return false;
}
} else {
$this->errors = $this->validator->getErrors();
$this->responseCode = ResponsesCode::VALIDATION_FAILED_CODE;
return false;
}
}
public function renameDir(array $data): bool
{
$this->dir = $this->dtoFactory->createResource();
if ($this->validator->renameDir($data)) {
try {
$cleanData = $this->validator->getCleanData();
$dirData = $this->getDirData($cleanData['id']);
$dirPersist = $this->dtoFactory->createPersist();
$dirPersist->load($dirData);
$dirPersist->update($cleanData);
$this->persistLayer->updateDir($dirPersist);
$this->dir->load($dirPersist->getAttributes());
return true;
} catch (Throwable $e) {
Log::error($e);
return false;
}
} else {
$this->errors = $this->validator->getErrors();
$this->responseCode = ResponsesCode::VALIDATION_FAILED_CODE;
return false;
}
}
public function deleteDir(array $data): bool
{
if ($this->validator->deleteDir($data)) {
try {
$cleanData = $this->validator->getCleanData();
$dirsIds = $this->storage->getIdsInDir($cleanData['id']);
$dirsIds[] = $cleanData['id'];
$this->persistLayer->deleteDirs($dirsIds);
return true;
} catch (Throwable $e) {
Log::error($e);
return false;
}
} else {
$this->errors = $this->validator->getErrors();
$this->responseCode = ResponsesCode::VALIDATION_FAILED_CODE;
return false;
}
}
public function getDir(): IResource
{
return $this->dir;
}
protected function getDirData(string $dirId, array $dsl = [])
{
return $this->storage->getById($dirId, $dsl);
}
}

View File

@ -1,69 +0,0 @@
<?php
namespace Src\Lib\CategoriesTree\Application;
use Src\Lib\CategoriesTree\Interfaces\Application\IFactory;
use Src\Lib\CategoriesTree\Interfaces\IFactory as ILibFactory;
use Src\Lib\CategoriesTree\Interfaces\Application\IDomain;
use Src\Lib\CategoriesTree\Interfaces\Application\IValidator;
use Src\Lib\CategoriesTree\Interfaces\Application\IDataBuilder;
class Factory implements IFactory
{
protected ILibFactory $libFactory;
protected ?IDomain $domain = null;
protected array $conf;
public function init(array $conf = []): void
{
$this->conf[IDomain::class] = [
'class' => Domain::class,
];
$this->conf[IValidator::class] = [
'class' => Validator::class,
];
$this->conf[IDataBuilder::class] = [
'class' => DataBuilder::class,
];
array_replace($this->conf, $conf);
}
public function setLibFactory(ILibFactory $factory): void
{
$this->libFactory = $factory;
}
public function getDomain(): Domain
{
if ($this->domain === null) {
$this->domain = new $this->conf[IDomain::class]['class'];
$validator = $this->createValidator();
$this->domain->setValidator($validator);
$dataBuilder = $this->createDataBuilder();
$this->domain->setDataBuilder($dataBuilder);
$dtoFactory = $this->libFactory->getDtoFactory();
$this->domain->setDtoFactory($dtoFactory);
$persistLayer = $this->libFactory->getInfrastructureFactory()->getPersistLayer();
$this->domain->setPersistLayer($persistLayer);
$storage = $this->libFactory->getInfrastructureFactory()->getStorage();
$this->domain->setStorage($storage);
}
return $this->domain;
}
public function createValidator(): Validator
{
return new $this->conf[IValidator::class]['class'];
}
public function createDataBuilder(): DataBuilder
{
$dataBuilder = new $this->conf[IDataBuilder::class]['class'];
$storage = $this->libFactory->getInfrastructureFactory()->getStorage();
$dataBuilder->setStorage($storage);
return $dataBuilder;
}
}

View File

@ -1,65 +0,0 @@
<?php
namespace Src\Lib\CategoriesTree\Application;
use Src\Common\Application\TraitValidator;
use Src\Lib\CategoriesTree\Interfaces\Application\IValidator;
class Validator implements IValidator {
use TraitValidator;
public function createDir(array $data):bool
{
$rules = [
'parent-dir' => [
'max:36',
'nullable',
],
'name' => [
'max:36',
'required',
],
];
$messages = [
'max' => 'Слишком длинная строка',
'required' => 'Обязательное поле',
];
return $this->validate($data, $rules, $messages);
}
public function renameDir(array $data):bool
{
$rules = [
'id' => [
'max:36',
'nullable',
],
'name' => [
'max:36',
'required',
],
];
$messages = [
'max' => 'Слишком длинная строка',
'required' => 'Обязательное поле',
];
return $this->validate($data, $rules, $messages);
}
public function deleteDir(array $data):bool
{
$rules = [
'id' => [
'max:36',
'nullable',
],
];
$messages = [
'max' => 'Слишком длинная строка',
'required' => 'Обязательное поле',
];
return $this->validate($data, $rules, $messages);
}
}

View File

@ -1,47 +0,0 @@
<?php
namespace Src\Lib\CategoriesTree\Dto;
use Src\Lib\CategoriesTree\Interfaces\Dto\IFactory;
use Src\Lib\CategoriesTree\Interfaces\IFactory as ILibFactory;
use Src\Lib\CategoriesTree\Interfaces\Dto\IPersist;
use Src\Lib\CategoriesTree\Interfaces\Dto\IResource;
class Factory implements IFactory {
protected ILibFactory $libFactory;
protected array $conf;
public function init(array $conf = []): void
{
$this->conf[IPersist::class] = [
'class' => Persist::class,
];
$this->conf[IResource::class] = [
'class' => Resource::class,
];
array_replace($this->conf, $conf);
}
public function setLibFactory(ILibFactory $factory)
{
$this->libFactory = $factory;
}
public function createPersist():IPersist
{
$persist = new $this->conf[IPersist::class]['class'];
$persist->setDtoFactory($this);
$persist->init();
return $persist;
}
public function createResource():IResource
{
$resource = new $this->conf[IResource::class]['class'];
$resource->setDtoFactory($this);
return $resource;
}
}

View File

@ -1,108 +0,0 @@
<?php
namespace Src\Lib\CategoriesTree;
use Src\Lib\CategoriesTree\Interfaces\IFactory;
use Src\Common\Interfaces\IFactory as ICommonFactory;
use Src\Lib\CategoriesTree\Interfaces\Dto\IFactory as IDtoFactory;
use Src\Lib\CategoriesTree\Dto\Factory as DtoFactory;
use Src\Lib\CategoriesTree\Interfaces\Infrastructure\IFactory as IInfrastructureFactory;
use Src\Lib\CategoriesTree\Infrastructure\Factory as InfrastructureFactory;
use Src\Lib\CategoriesTree\Interfaces\Application\IFactory as IApplicationFactory;
use Src\Lib\CategoriesTree\Application\Factory as ApplicationFactory;
class Factory implements IFactory {
protected ICommonFactory $commonFactory;
protected ?IDtoFactory $dtoFactory = null;
protected ?IInfrastructureFactory $infrastructureFactory = null;
protected ?IApplicationFactory $applicationFactory = null;
protected array $settings;
protected array $conf;
public function init(array $conf = []): void
{
$this->conf[IDtoFactory::class] = [
'class' => DtoFactory::class,
'conf' => [],
];
$this->conf[IInfrastructureFactory::class] = [
'class' => InfrastructureFactory::class,
'conf' => [],
];
$this->conf[IApplicationFactory::class] = [
'class' => ApplicationFactory::class,
'conf' => [],
];
array_replace($this->conf, $conf);
}
public function setCommonFactory(ICommonFactory $factory)
{
$this->commonFactory = $factory;
}
public function getCommonFactory():ICommonFactory
{
return $this->commonFactory;
}
public function loadSettings(array $settings)
{
$this->settings = $settings;
}
public function setSetting(string $key, $val): void
{
$this->settings[$key] = $val;
}
public function getSetting(string $key)
{
return $this->settings[$key];
}
public function getSettings(): array
{
return $this->settings;
}
public function getDtoFactory():DtoFactory
{
if($this->dtoFactory === null){
$conf = $this->conf[IDtoFactory::class];
$this->dtoFactory = new $conf['class'];
$this->dtoFactory->init($conf['conf']);
$this->dtoFactory->setLibFactory($this);
}
return $this->dtoFactory;
}
public function getInfrastructureFactory():InfrastructureFactory
{
if($this->infrastructureFactory === null){
$conf = $this->conf[IInfrastructureFactory::class];
$this->infrastructureFactory = new $conf['class'];
$this->infrastructureFactory->init($conf['conf']);
$this->infrastructureFactory->setLibFactory($this);
}
return $this->infrastructureFactory;
}
public function getApplicationFactory():ApplicationFactory
{
if($this->applicationFactory === null){
$conf = $this->conf[IApplicationFactory::class];
$this->applicationFactory = new $conf['class'];
$this->applicationFactory->init($conf['conf']);
$this->applicationFactory->setLibFactory($this);
}
return $this->applicationFactory;
}
}

View File

@ -1,68 +0,0 @@
<?php
namespace Src\Lib\CategoriesTree\Infrastructure;
use Src\Lib\CategoriesTree\Interfaces\Infrastructure\IFactory;
use Src\Lib\CategoriesTree\Interfaces\IFactory as ILibFactory;
use Src\Lib\CategoriesTree\Interfaces\Infrastructure\IStorage;
use Src\Lib\CategoriesTree\Interfaces\Infrastructure\IQuery;
use Src\Lib\CategoriesTree\Interfaces\Infrastructure\IPersistLayer;
class Factory implements IFactory
{
protected ILibFactory $libFactory;
protected ?IStorage $storage = null;
protected ?IPersistLayer $persistLayer = null;
protected array $conf;
public function init(array $conf = []): void
{
$this->conf[IQuery::class] = [
'class' => Query::class,
];
$this->conf[IStorage::class] = [
'class' => Storage::class,
];
$this->conf[IPersistLayer::class] = [
'class' => PersistLayer::class,
];
array_replace($this->conf, $conf);
}
public function setLibFactory(ILibFactory $factory)
{
$this->libFactory = $factory;
}
protected function createQuery(): Query
{
$query = new $this->conf[IQuery::class]['class'];
$tableName = $this->libFactory->getSetting(ILibFactory::TABLE_NAME);
$query->setTableName($tableName);
return $query;
}
public function getStorage(): IStorage
{
if ($this->storage === null) {
$this->storage = new $this->conf[IStorage::class]['class'];
$query = $this->createQuery();
$this->storage->setQuery($query);
}
return $this->storage;
}
public function getPersistLayer(): IPersistLayer
{
if ($this->persistLayer === null) {
$this->persistLayer = new $this->conf[IPersistLayer::class]['class'];
$tableName = $this->libFactory->getSetting(ILibFactory::TABLE_NAME);
$this->persistLayer->setTableName($tableName);
}
return $this->persistLayer;
}
}

View File

@ -1,113 +0,0 @@
<?php
namespace Src\Lib\CategoriesTree\Infrastructure;
use Src\Lib\CategoriesTree\Interfaces\Infrastructure\IQuery;
use Src\Common\Infrastructure\TraitSqlQuery;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Query\Builder;
use hrustbb2\arrayproc\ArrayProcessor;
class Query implements IQuery {
use TraitSqlQuery {
TraitSqlQuery::getSelectSection as baseGetSelectSection;
}
protected string $tableName;
protected Builder $queryBuilder;
protected array $arrayProcConf = [];
protected bool $isParentJoined = false;
public function setTableName(string $tableName)
{
$this->tableName = $tableName;
}
protected function reset()
{
$this->queryBuilder = DB::table($this->tableName);
$this->isParentJoined = false;
}
protected function getSelectSection(array $fields, array $allowFields, string $table, string $prefix = ''): array
{
$segments = $this->baseGetSelectSection($fields, $allowFields, $table, $prefix);
$result = [];
foreach($segments as $field=>$alias){
$result[] = $field . ' AS ' . $alias;
}
return $result;
}
public function select(array $fields)
{
$this->reset();
$selectSection = $this->getSelectSection($fields, ['id', 'matherial_path', 'parent_id', 'name'], $this->tableName, 'category_');
$this->queryBuilder->select($selectSection);
$this->arrayProcConf = ['prefix' => 'category_'];
return $this;
}
public function whereId($id)
{
$this->queryBuilder->where($this->tableName . '.id', '=', $id);
return $this;
}
public function whereIdIn(array $ids)
{
$this->queryBuilder->whereIn($this->tableName . '.id', $ids);
return $this;
}
public function whereParentId($parentId)
{
$this->queryBuilder->where($this->tableName . '.parent_id', '=', $parentId);
return $this;
}
public function whereInPath(string $matherialPath)
{
$this->queryBuilder->where($this->tableName . '.matherial_path', 'like', $matherialPath . '%');
return $this;
}
public function withParent(array $fields)
{
$this->joinParend();
$selectSection = $this->getSelectSection($fields, ['id', 'matherial_path', 'parent_id', 'name'], $this->tableName, 'parent_');
$this->queryBuilder->addSelect($selectSection);
$this->arrayProcConf['parent'] = ['prefix' => 'parent_'];
return $this;
}
protected function joinParend()
{
if(!$this->isParentJoined){
$first = $this->tableName . '.id';
$two = $this->tableName . '.parent_id';
$this->queryBuilder->leftJoin($this->tableName . ' AS parent', $first, '=', $two);
$this->isParentJoined = true;
}
}
public function all(): array
{
$arrayProc = new ArrayProcessor();
$data = $this->queryBuilder->get()->toArray();
return $arrayProc->process($this->arrayProcConf, $data)->resultArray();
}
public function one(): array
{
$arrayProc = new ArrayProcessor();
$data = $this->queryBuilder->get()->toArray();
$d = $arrayProc->process($this->arrayProcConf, $data)->resultArray();
return array_pop($d) ?? [];
}
}

View File

@ -1,53 +0,0 @@
<?php
namespace Src\Lib\CategoriesTree\Infrastructure;
use Src\Lib\CategoriesTree\Interfaces\Infrastructure\IStorage;
use Src\Lib\CategoriesTree\Interfaces\Infrastructure\IQuery;
use Src\Common\Infrastructure\TraitStorage;
class Storage implements IStorage {
use TraitStorage;
protected IQuery $query;
public function setQuery(IQuery $query)
{
$this->query = $query;
}
public function getById($id, array $dsl = []):array
{
$this->query->select($dsl)->whereId($id);
if(key_exists('parent', $dsl)){
$this->query->withParent($dsl['parent']);
}
$data = $this->query->one();
if(key_exists('path', $dsl) && isset($data['matherial_path'])){
$ids = explode('|', $data['matherial_path']);
$path = $this->query->select($dsl['path'])->whereIdIn($ids)->all();
$data['path'] = $path;
}
return $data;
}
public function getByParentId($parentId, array $dsl = []):array
{
return $this->query->select($dsl)->whereParentId($parentId)->all();
}
public function getIdsInDir(string $dirId):array
{
$dirData = $this->query->select(['id', 'matherial_path'])->whereId($dirId)->one();
$pathIds = ($dirData['matherial_path']) ? explode('|', $dirData['matherial_path']) : [];
$pathIds[] = $dirId;
$matherialPath = join('|', $pathIds);
$dirs = $this->query->select(['id'])->whereInPath($matherialPath)->all();
$ids = array_map(function($dir){
return $dir['id'];
}, $dirs);
return array_values($ids);
}
}

View File

@ -1,10 +0,0 @@
<?php
namespace Src\Lib\CategoriesTree\Interfaces\Application;
use Src\Lib\CategoriesTree\Interfaces\Infrastructure\IStorage;
interface IDataBuilder {
public function setStorage(IStorage $storage):void;
public function buildData(array $requestData):array;
}

View File

@ -1,22 +0,0 @@
<?php
namespace Src\Lib\CategoriesTree\Interfaces\Application;
use Src\Common\Interfaces\Application\IBaseDomain;
use Src\Lib\CategoriesTree\Interfaces\Dto\IFactory as IDtoFactory;
use Src\Lib\CategoriesTree\Interfaces\Infrastructure\IPersistLayer;
use Src\Lib\CategoriesTree\Interfaces\Infrastructure\IStorage;
use Src\Lib\CategoriesTree\Interfaces\Dto\IResource;
interface IDomain extends IBaseDomain
{
public function setValidator(IValidator $validator): void;
public function setDataBuilder(IDataBuilder $builder): void;
public function setDtoFactory(IDtoFactory $factory): void;
public function setPersistLayer(IPersistLayer $layer): void;
public function setStorage(IStorage $storage): void;
public function createDir(array $data): bool;
public function renameDir(array $data): bool;
public function deleteDir(array $data): bool;
public function getDir(): IResource;
}

View File

@ -1,15 +0,0 @@
<?php
namespace Src\Lib\CategoriesTree\Interfaces\Application;
use Src\Lib\CategoriesTree\Interfaces\IFactory as ILibFactory;
use Src\Lib\CategoriesTree\Interfaces\Application\IDomain;
use Src\Lib\CategoriesTree\Interfaces\Application\IValidator;
interface IFactory {
public function init(array $conf = []): void;
public function setLibFactory(ILibFactory $factory):void;
public function getDomain():IDomain;
public function createValidator():IValidator;
public function createDataBuilder():IDataBuilder;
}

View File

@ -1,11 +0,0 @@
<?php
namespace Src\Lib\CategoriesTree\Interfaces\Application;
use Src\Common\Interfaces\Application\IBaseValidator;
interface IValidator extends IBaseValidator {
public function createDir(array $data):bool;
public function renameDir(array $data):bool;
public function deleteDir(array $data):bool;
}

View File

@ -1,12 +0,0 @@
<?php
namespace Src\Lib\CategoriesTree\Interfaces\Dto;
use Src\Lib\CategoriesTree\Interfaces\IFactory as ILibFactory;
interface IFactory {
public function init(array $conf = []): void;
public function setLibFactory(ILibFactory $factory);
public function createPersist():IPersist;
public function createResource():IResource;
}

View File

@ -1,14 +0,0 @@
<?php
namespace Src\Lib\CategoriesTree\Interfaces\Dto;
use Src\Lib\CategoriesTree\Interfaces\Dto\IFactory as IDtoFactory;
interface IPersist extends IAbstractCategory {
public function init():void;
public function setDtoFactory(IDtoFactory $factory);
public function update(array $data):void;
public function getInsertAttributes():array;
public function getPath():array;
public function getUpdatedAttrs():array;
}

View File

@ -1,16 +0,0 @@
<?php
namespace Src\Lib\CategoriesTree\Interfaces\Dto;
use Src\Lib\CategoriesTree\Interfaces\Dto\IFactory as IDtoFactory;
interface IResource extends IAbstractCategory {
public function setDtoFactory(IDtoFactory $factory);
public function toArray(array $fields = []):array;
/**
* @return IResource[]
*/
public function getPath():array;
public function getName():string;
public function getParent():?IResource;
}

View File

@ -1,33 +0,0 @@
<?php
namespace Src\Lib\CategoriesTree\Interfaces;
use Src\Common\Interfaces\IFactory as ICommonFactory;
use Src\Lib\CategoriesTree\Interfaces\Dto\IFactory as IDtoFactory;
use Src\Lib\CategoriesTree\Interfaces\Infrastructure\IFactory as IInfrastructureFactory;
use Src\Lib\CategoriesTree\Interfaces\Application\IFactory as IApplicationFactory;
interface IFactory {
const DB_HOST = 'db_host';
const DB_NAME = 'db_name';
const DB_USER = 'db_user';
const DB_PASS = 'db_pass';
const DB_CHARSET = 'db_charset';
const TABLE_NAME = 'table_name';
public function setCommonFactory(ICommonFactory $factory);
public function getCommonFactory():ICommonFactory;
public function loadSettings(array $settings);
public function setSetting(string $key, $val): void;
public function getSetting(string $key);
public function getSettings(): array;
public function getDtoFactory():IDtoFactory;
public function getInfrastructureFactory():IInfrastructureFactory;
public function getApplicationFactory():IApplicationFactory;
}

View File

@ -1,15 +0,0 @@
<?php
namespace Src\Lib\CategoriesTree\Interfaces\Infrastructure;
use Src\Lib\CategoriesTree\Interfaces\IFactory as ILibFactory;
use Src\Lib\CategoriesTree\Interfaces\Infrastructure\IStorage;
use Src\Lib\CategoriesTree\Interfaces\Infrastructure\IPersistLayer;
interface IFactory
{
public function init(array $conf = []): void;
public function setLibFactory(ILibFactory $factory);
public function getStorage(): IStorage;
public function getPersistLayer(): IPersistLayer;
}

View File

@ -1,11 +0,0 @@
<?php
namespace Src\Lib\CategoriesTree\Interfaces\Infrastructure;
interface IMigrations
{
public function init(array $settings): void;
public function create(string $migrationsPath): void;
public function migrate(string $migrationsPath): void;
public function rollback(string $migrationsPath): void;
}

View File

@ -1,12 +0,0 @@
<?php
namespace Src\Lib\CategoriesTree\Interfaces\Infrastructure;
use Src\Lib\CategoriesTree\Interfaces\Dto\IPersist;
interface IPersistLayer {
public function setTableName(string $tableName);
public function newDir(IPersist $dto):bool;
public function updateDir(IPersist $dto):int;
public function deleteDirs(array $ids):int;
}

View File

@ -1,12 +0,0 @@
<?php
namespace Src\Lib\CategoriesTree\Interfaces\Infrastructure;
use Src\Lib\CategoriesTree\Interfaces\Infrastructure\IQuery;
interface IStorage {
public function setQuery(IQuery $query);
public function getById($id, array $dsl = []):array;
public function getByParentId($parentId, array $dsl = []):array;
public function getIdsInDir(string $materialPath):array;
}

View File

@ -1 +0,0 @@
migrations.json

View File

@ -1,24 +0,0 @@
<?php
use Phinx\Db\Table;
use hrustbb2\Migrations\AbstractMigrate;
use Src\Lib\CategoriesTree\Interfaces\IFactory as ILibFactory;
class Migration_1652891836 extends AbstractMigrate
{
public function up(array $settings): void
{
$table = new Table($settings[ILibFactory::TABLE_NAME], ['id' => false, 'primary_key' => ['id']], $this->adapter);
$table ->addColumn('id', 'string')
->addColumn('matherial_path', 'string')
->addColumn('parent_id', 'string')
->addColumn('name', 'string')
->create();
}
public function down(array $settings): void
{
$table = new Table($settings[ILibFactory::TABLE_NAME], ['id' => false, 'primary_key' => ['id']], $this->adapter);
$table->drop()->save();
}
}

View File

@ -3,23 +3,24 @@
namespace Src\Modules\JsonObjects\Application;
use Src\Modules\JsonObjects\Interfaces\Application\IDataBuilder;
use Src\Lib\CategoriesTree\Interfaces\Infrastructure\IStorage as IDirStorage;
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IDirsStorage;
class DataBuilder implements IDataBuilder {
class DataBuilder implements IDataBuilder
{
protected IDirStorage $dirStorage;
protected IDirsStorage $dirStorage;
public function setDirStorage(IDirStorage $dirStorage):void
public function setDirStorage(IDirsStorage $dirStorage): void
{
$this->dirStorage = $dirStorage;
}
public function build(array $data):array
public function build(array $data): array
{
$dirData = [];
if(key_exists('dir-id', $data) && $data['dir-id']){
if (key_exists('dir-id', $data) && $data['dir-id']) {
$dirData = $this->dirStorage->getById($data['dir-id']);
if(!$dirData){
if (!$dirData) {
$dirData = ['id' => ''];
}
$data['dir'] = [
@ -29,4 +30,19 @@ class DataBuilder implements IDataBuilder {
return $data;
}
}
public function buildDirData(array $requestData): array
{
$dsl = [
'id',
'matherial_path',
'path' => ['id']
];
$parentData = $this->dirStorage->getById($requestData['parent-dir'], $dsl);
if ($parentData) {
$requestData['parent'] = [
$parentData['id'] => $parentData,
];
}
return $requestData;
}
}

View File

@ -11,11 +11,13 @@ use Src\Modules\JsonObjects\Interfaces\Dto\Item\IResourceItem;
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemPersistLayer;
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemStorage;
use Src\Modules\JsonObjects\Interfaces\Application\IDataBuilder;
use Src\Lib\CategoriesTree\Interfaces\Application\IValidator as IDirValidator;
use Src\Lib\CategoriesTree\Interfaces\Application\IDomain as IDirDomain;
use Src\Lib\CategoriesTree\Interfaces\Infrastructure\IStorage as IDirStorage;
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IDirsStorage;
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IDirsPersistLayer;
use Src\Modules\JsonObjects\Interfaces\Dto\Dir\IResource as IDirResource;
use Illuminate\Support\Facades\Log;
class Domain implements IDomain {
class Domain implements IDomain
{
use TraitDomain;
@ -31,103 +33,98 @@ class Domain implements IDomain {
protected IDataBuilder $dataBuilder;
protected IDirValidator $dirValidator;
protected IDirsStorage $dirsStorage;
protected IDirDomain $dirDomain;
protected IDirsPersistLayer $dirsPersistLayer;
protected IDirStorage $dirStorage;
protected IDirResource $dirResource;
public function setValidator(IValidator $validator):void
public function setValidator(IValidator $validator): void
{
$this->validator = $validator;
}
public function setDtoFactory(IDtoFactory $factory):void
public function setDtoFactory(IDtoFactory $factory): void
{
$this->dtoFactory = $factory;
}
public function setPersistLayer(IItemPersistLayer $layer):void
public function setPersistLayer(IItemPersistLayer $layer): void
{
$this->persistLayer = $layer;
}
public function setStorage(IItemStorage $storage):void
public function setStorage(IItemStorage $storage): void
{
$this->storage = $storage;
}
public function setDataBuilder(IDataBuilder $dataBuilder):void
public function setDataBuilder(IDataBuilder $dataBuilder): void
{
$this->dataBuilder = $dataBuilder;
}
public function setDirValidator(IDirValidator $validator):void
public function setDirStorage(IDirsStorage $storage): void
{
$this->dirValidator = $validator;
$this->dirsStorage = $storage;
}
public function setDirDomain(IDirDomain $domain):void
public function setDirsPersistLayer(IDirsPersistLayer $layer): void
{
$this->dirDomain = $domain;
$this->dirsPersistLayer = $layer;
}
public function setDirStorage(IDirStorage $storage):void
{
$this->dirStorage = $storage;
}
public function createObject(array $data):bool
public function createObject(array $data): bool
{
$this->item = $this->dtoFactory->getItemFactory()->createResource();
if($this->validator->createObject($data)){
if ($this->validator->createObject($data)) {
$cleanData = $this->validator->getCleanData();
$fullData = $this->dataBuilder->build($cleanData);
$item = $this->dtoFactory->getItemFactory()->createPersist();
$item->load($fullData);
$this->item->load($item->getAttributes());
if($this->item->validate()){
if ($this->item->validate()) {
$this->persistLayer->create($item);
$this->item->getObject()->onSave();
return true;
}
$this->responseCode = ResponsesCode::VALIDATION_FAILED_CODE;
return false;
}else{
} else {
$this->errors = $this->validator->getErrors();
$this->responseCode = ResponsesCode::VALIDATION_FAILED_CODE;
return false;
}
}
public function editObject(array $data):bool
public function editObject(array $data): bool
{
$this->item = $this->dtoFactory->getItemFactory()->createResource();
if($this->validator->editObject($data)){
if ($this->validator->editObject($data)) {
$cleanData = $this->validator->getCleanData();
$itemData = $this->storage->getById($cleanData['id']);
$item = $this->dtoFactory->getItemFactory()->createPersist();
$item->load($itemData);
$item->update($cleanData);
$this->item->load($item->getAttributes());
if($this->item->validate()){
if ($this->item->validate()) {
$this->persistLayer->update($item);
$this->item->getObject()->onSave();
return true;
}
$this->responseCode = ResponsesCode::VALIDATION_FAILED_CODE;
return false;
}else{
} else {
$this->errors = $this->validator->getErrors();
$this->responseCode = ResponsesCode::VALIDATION_FAILED_CODE;
return false;
}
}
public function renameObject(array $data):bool
public function renameObject(array $data): bool
{
$this->item = $this->dtoFactory->getItemFactory()->createResource();
if($this->validator->renameObject($data)){
if ($this->validator->renameObject($data)) {
$cleanData = $this->validator->getCleanData();
$itemData = $this->storage->getById($cleanData['id']);
$item = $this->dtoFactory->getItemFactory()->createPersist();
@ -136,49 +133,125 @@ class Domain implements IDomain {
$this->persistLayer->update($item);
$this->item->load($item->getAttributes());
return true;
}else{
} else {
$this->errors = $this->validator->getErrors();
$this->responseCode = ResponsesCode::VALIDATION_FAILED_CODE;
return false;
}
}
public function deleteObject(array $data):bool
public function deleteObject(array $data): bool
{
if($this->validator->deleteObject($data)){
if ($this->validator->deleteObject($data)) {
$cleanData = $this->validator->getCleanData();
$itemData = $this->storage->getById($cleanData['id']);
if(!$itemData['disabled']){
if (!$itemData['disabled']) {
$this->persistLayer->delete($cleanData['id']);
return true;
}
return false;
}else{
} else {
$this->errors = $this->validator->getErrors();
$this->responseCode = ResponsesCode::VALIDATION_FAILED_CODE;
return false;
}
}
public function deleteDir(array $data):bool
public function deleteDir(array $data): bool
{
if($this->dirValidator->deleteDir($data)){
$cleanData = $this->dirValidator->getCleanData();
$dirIds = $this->dirStorage->getIdsInDir($cleanData['id']);
if ($this->validator->deleteDir($data)) {
$cleanData = $this->validator->getCleanData();
$dirIds = $this->dirsStorage->getIdsInDir($cleanData['id']);
$dirIds[] = $cleanData['id'];
$this->persistLayer->deleteInDirs($dirIds);
$this->dirDomain->deleteDir($data);
$this->_deleteDir($data);
return true;
}else{
$this->errors = $this->dirValidator->getErrors();
} else {
$this->errors = $this->validator->getErrors();
$this->responseCode = ResponsesCode::VALIDATION_FAILED_CODE;
return false;
}
}
public function getItem():IResourceItem
public function createDir(array $data): bool
{
$this->dirResource = $this->dtoFactory->getDirFactory()->createResource();
if ($this->validator->createDir($data)) {
try {
$cleanData = $this->validator->getCleanData();
$dirData = $this->dataBuilder->buildDirData($cleanData);
$dirPersist = $this->dtoFactory->getDirFactory()->createPersist();
$dirPersist->load($dirData);
$this->dirsPersistLayer->newDir($dirPersist);
$this->dirResource->load($dirPersist->getAttributes());
return true;
} catch (\Throwable $e) {
Log::error($e);
return false;
}
} else {
$this->errors = $this->validator->getErrors();
$this->responseCode = ResponsesCode::VALIDATION_FAILED_CODE;
return false;
}
}
public function renameDir(array $data): bool
{
$this->dirResource = $this->dtoFactory->getDirFactory()->createResource();
if ($this->validator->renameDir($data)) {
try {
$cleanData = $this->validator->getCleanData();
$dirData = $this->getDirData($cleanData['id']);
$dirPersist = $this->dtoFactory->getDirFactory()->createPersist();
$dirPersist->load($dirData);
$dirPersist->update($cleanData);
$this->dirsPersistLayer->updateDir($dirPersist);
$this->dirResource->load($dirPersist->getAttributes());
return true;
} catch (\Throwable $e) {
Log::error($e);
return false;
}
} else {
$this->errors = $this->validator->getErrors();
$this->responseCode = ResponsesCode::VALIDATION_FAILED_CODE;
return false;
}
}
private function _deleteDir(array $data): bool
{
if ($this->validator->deleteDir($data)) {
try {
$cleanData = $this->validator->getCleanData();
$dirsIds = $this->dirsStorage->getIdsInDir($cleanData['id']);
$dirsIds[] = $cleanData['id'];
$this->dirsPersistLayer->deleteDirs($dirsIds);
return true;
} catch (\Throwable $e) {
Log::error($e);
return false;
}
} else {
$this->errors = $this->validator->getErrors();
$this->responseCode = ResponsesCode::VALIDATION_FAILED_CODE;
return false;
}
}
public function getDir(): IDirResource
{
return $this->dirResource;
}
protected function getDirData(string $dirId, array $dsl = [])
{
return $this->dirsStorage->getById($dirId, $dsl);
}
public function getItem(): IResourceItem
{
return $this->item;
}
}
}

View File

@ -8,7 +8,8 @@ use Src\Modules\JsonObjects\Interfaces\Application\IValidator;
use Src\Modules\JsonObjects\Interfaces\Application\IDomain;
use Src\Modules\JsonObjects\Interfaces\Application\IDataBuilder;
class Factory implements IFactory {
class Factory implements IFactory
{
protected IModuleFactory $moduleFactory;
@ -31,15 +32,15 @@ class Factory implements IFactory {
protected function createInstance($instance)
{
if(gettype($instance) == 'string'){
if (gettype($instance) == 'string') {
return new $instance;
}
if(gettype($instance) == 'object'){
if (gettype($instance) == 'object') {
return $instance;
}
}
public function setModuleFactory(IModuleFactory $factorory):void
public function setModuleFactory(IModuleFactory $factorory): void
{
$this->moduleFactory = $factorory;
}
@ -57,14 +58,14 @@ class Factory implements IFactory {
protected function creteDataBuilder(): DataBuilder
{
$dataBuilder = $this->createInstance($this->conf['dataBuilder']);
$storage = $this->moduleFactory->getDirsTreeFactory()->getInfrastructureFactory()->getStorage();
$storage = $this->moduleFactory->getInfrastructureFactory()->getDirsStorage();
$dataBuilder->setDirStorage($storage);
return $dataBuilder;
}
public function getDomain(): Domain
{
if($this->domain === null){
if ($this->domain === null) {
$this->domain = $this->createInstance($this->conf['domain']);
$validator = $this->createValidator();
$this->domain->setValidator($validator);
@ -76,22 +77,19 @@ class Factory implements IFactory {
$this->domain->setStorage($storage);
$dataBuilder = $this->creteDataBuilder();
$this->domain->setDataBuilder($dataBuilder);
$dirValidator = $this->moduleFactory->getDirsTreeFactory()->getApplicationFactory()->createValidator();
$this->domain->setDirValidator($dirValidator);
$dirDomain = $this->moduleFactory->getDirsTreeFactory()->getApplicationFactory()->getDomain();
$this->domain->setDirDomain($dirDomain);
$dirStorage = $this->moduleFactory->getDirsTreeFactory()->getInfrastructureFactory()->getStorage();
$dirStorage = $this->moduleFactory->getInfrastructureFactory()->getDirsStorage();
$this->domain->setDirStorage($dirStorage);
$dirsPersistLayer = $this->moduleFactory->getInfrastructureFactory()->getDirsPersistLayer();
$this->domain->setDirsPersistLayer($dirsPersistLayer);
}
return $this->domain;
}
public function getFilesBrowser(): FilesBrowser
{
if($this->filesBrowser === null){
if ($this->filesBrowser === null) {
$this->filesBrowser = $this->createInstance($this->conf['filesBrowser']);
}
return $this->filesBrowser;
}
}
}

View File

@ -5,13 +5,14 @@ namespace Src\Modules\JsonObjects\Application;
use Src\Common\Application\TraitValidator;
use Src\Modules\JsonObjects\Interfaces\Application\IValidator;
class Validator implements IValidator {
class Validator implements IValidator
{
use TraitValidator {
getCleanData as baseCleanData;
}
public function createObject(array $data):bool
public function createObject(array $data): bool
{
$rules = [
'dir-id' => [
@ -27,13 +28,11 @@ class Validator implements IValidator {
'max:32',
],
];
$messages = [
];
$messages = [];
return $this->validate($data, $rules, $messages);
}
public function editObject(array $data):bool
public function editObject(array $data): bool
{
$rules = [
'id' => [
@ -49,13 +48,11 @@ class Validator implements IValidator {
'array',
]
];
$messages = [
];
$messages = [];
return $this->validate($data, $rules, $messages);
}
public function renameObject(array $data):bool
public function renameObject(array $data): bool
{
$rules = [
'id' => [
@ -67,13 +64,11 @@ class Validator implements IValidator {
'max:32',
],
];
$messages = [
];
$messages = [];
return $this->validate($data, $rules, $messages);
}
public function deleteObject(array $data):bool
public function deleteObject(array $data): bool
{
$rules = [
'id' => [
@ -81,8 +76,59 @@ class Validator implements IValidator {
'max:32',
],
];
$messages = [
$messages = [];
return $this->validate($data, $rules, $messages);
}
public function createDir(array $data): bool
{
$rules = [
'parent-dir' => [
'max:36',
'nullable',
],
'name' => [
'max:36',
'required',
],
];
$messages = [
'max' => 'Слишком длинная строка',
'required' => 'Обязательное поле',
];
return $this->validate($data, $rules, $messages);
}
public function renameDir(array $data): bool
{
$rules = [
'id' => [
'max:36',
'nullable',
],
'name' => [
'max:36',
'required',
],
];
$messages = [
'max' => 'Слишком длинная строка',
'required' => 'Обязательное поле',
];
return $this->validate($data, $rules, $messages);
}
public function deleteDir(array $data): bool
{
$rules = [
'id' => [
'max:36',
'nullable',
],
];
$messages = [
'max' => 'Слишком длинная строка',
'required' => 'Обязательное поле',
];
return $this->validate($data, $rules, $messages);
}
@ -90,10 +136,9 @@ class Validator implements IValidator {
public function getCleanData()
{
$cleanData = $this->baseCleanData();
if(key_exists('object', $cleanData)){
if (key_exists('object', $cleanData)) {
$cleanData['object'] = json_encode($cleanData['object']);
}
return $cleanData;
}
}
}

View File

@ -1,8 +1,8 @@
<?php
namespace Src\Lib\CategoriesTree\Dto;
namespace Src\Modules\JsonObjects\Dto\Dir;
use Src\Lib\CategoriesTree\Interfaces\Dto\IAbstractCategory;
use Src\Modules\JsonObjects\Interfaces\Dto\Dir\IAbstractCategory;
trait CategoryTrait
{
@ -28,7 +28,7 @@ trait CategoryTrait
$this->loadPath($data['path']);
}
if (key_exists('parent', $data)) {
$parentData = array_pop($data['parent']);
$parentData = array_pop($data['parent']) ?? [];
$this->loadParent($parentData);
}
}

View File

@ -0,0 +1,47 @@
<?php
namespace Src\Modules\JsonObjects\Dto\Dir;
use Src\Modules\JsonObjects\Interfaces\Dto\Dir\IFactory;
use Src\Modules\JsonObjects\Interfaces\Dto\IFactory as IDtoFactory;
use Src\Modules\JsonObjects\Interfaces\Dto\Dir\IPersist;
use Src\Modules\JsonObjects\Interfaces\Dto\Dir\IResource;
class Factory implements IFactory
{
protected IDtoFactory $dtoFactory;
protected array $conf;
public function init(array $conf = []): void
{
$this->conf[IPersist::class] = [
'class' => Persist::class,
];
$this->conf[IResource::class] = [
'class' => Resource::class,
];
array_replace($this->conf, $conf);
}
public function setDtoFactory(IDtoFactory $factory): void
{
$this->dtoFactory = $factory;
}
public function createPersist(): IPersist
{
$persist = new $this->conf[IPersist::class]['class'];
$persist->setDtoFactory($this->dtoFactory);
$persist->init();
return $persist;
}
public function createResource(): IResource
{
$resource = new $this->conf[IResource::class]['class'];
$resource->setDtoFactory($this->dtoFactory);
return $resource;
}
}

View File

@ -1,10 +1,10 @@
<?php
namespace Src\Lib\CategoriesTree\Dto;
namespace Src\Modules\JsonObjects\Dto\Dir;
use Src\Lib\CategoriesTree\Interfaces\Dto\IPersist;
use Src\Lib\CategoriesTree\Interfaces\Dto\IFactory as IDtoFactory;
use Src\Lib\CategoriesTree\Interfaces\Dto\IAbstractCategory;
use Src\Modules\JsonObjects\Interfaces\Dto\Dir\IPersist;
use Src\Modules\JsonObjects\Interfaces\Dto\IFactory as IDtoFactory;
use Src\Modules\JsonObjects\Interfaces\Dto\Dir\IAbstractCategory;
/**
* @property IPersist $parent
@ -35,7 +35,7 @@ class Persist implements IPersist
{
$this->path = [];
foreach ($data as $itemData) {
$pathItem = $this->dtoFactory->createPersist();
$pathItem = $this->dtoFactory->getDirFactory()->createPersist();
$pathItem->load($itemData);
$this->path[] = $pathItem;
}
@ -48,7 +48,7 @@ class Persist implements IPersist
public function loadParent(array $data)
{
$this->parent = $this->dtoFactory->createPersist();
$this->parent = $this->dtoFactory->getDirFactory()->createPersist();
$this->parent->load($data);
}

View File

@ -1,10 +1,10 @@
<?php
namespace Src\Lib\CategoriesTree\Dto;
namespace Src\Modules\JsonObjects\Dto\Dir;
use Src\Lib\CategoriesTree\Interfaces\Dto\IResource;
use Src\Lib\CategoriesTree\Interfaces\Dto\IFactory as IDtoFactory;
use Src\Lib\CategoriesTree\Interfaces\Dto\IAbstractCategory;
use Src\Modules\JsonObjects\Interfaces\Dto\Dir\IResource;
use Src\Modules\JsonObjects\Interfaces\Dto\IFactory as IDtoFactory;
use Src\Modules\JsonObjects\Interfaces\Dto\Dir\IAbstractCategory;
class Resource implements IResource
{
@ -35,7 +35,7 @@ class Resource implements IResource
{
$this->path = [];
foreach ($data as $item) {
$pathItem = $this->dtoFactory->createResource();
$pathItem = $this->dtoFactory->getDirFactory()->createResource();
$pathItem->load($item);
$this->path[] = $pathItem;
}
@ -58,7 +58,10 @@ class Resource implements IResource
public function loadParent(array $data)
{
$this->parent = $this->dtoFactory->createResource();
if (!$data) {
return;
}
$this->parent = $this->dtoFactory->getDirFactory()->createResource();
$this->parent->load($data);
}

View File

@ -6,13 +6,18 @@ use Src\Modules\JsonObjects\Interfaces\Dto\IFactory;
use Src\Modules\JsonObjects\Interfaces\IFactory as IModulesFactory;
use Src\Modules\JsonObjects\Interfaces\Dto\Item\IFactory as IItemFactory;
use Src\Modules\JsonObjects\Dto\Item\Factory as ItemFactory;
use Src\Modules\JsonObjects\Interfaces\Dto\Dir\IFactory as IDirFactory;
use Src\Modules\JsonObjects\Dto\Dir\Factory as DirFactory;
class Factory implements IFactory {
class Factory implements IFactory
{
protected IModulesFactory $modulesFactory;
protected ?IItemFactory $itemFactory = null;
protected ?IDirFactory $dirFactory = null;
protected array $conf;
public function init(array $conf = []): void
@ -21,6 +26,9 @@ class Factory implements IFactory {
'item' => [
'factory' => ItemFactory::class,
],
'dir' => [
'factory' => DirFactory::class,
],
];
$this->conf = array_replace_recursive($this->conf, $conf);
}
@ -30,14 +38,14 @@ class Factory implements IFactory {
$this->modulesFactory = $factory;
}
public function getModulesFactory():IModulesFactory
public function getModulesFactory(): IModulesFactory
{
return $this->modulesFactory;
}
public function getItemFactory():ItemFactory
public function getItemFactory(): ItemFactory
{
if($this->itemFactory === null){
if ($this->itemFactory === null) {
$this->itemFactory = new $this->conf['item']['factory'];
$this->itemFactory->init($this->conf['item']);
$this->itemFactory->setDtoFactory($this);
@ -45,4 +53,13 @@ class Factory implements IFactory {
return $this->itemFactory;
}
}
public function getDirFactory(): DirFactory
{
if ($this->dirFactory === null) {
$this->dirFactory = new $this->conf['dir']['factory'];
$this->dirFactory->init($this->conf['dir']);
$this->dirFactory->setDtoFactory($this);
}
return $this->dirFactory;
}
}

View File

@ -6,7 +6,8 @@ use Src\Modules\JsonObjects\Interfaces\IFactory as IModuleFactory;
use Src\Modules\JsonObjects\Interfaces\Dto\Item\IFactory;
use Src\Modules\JsonObjects\Interfaces\Dto\IFactory as IDtoFactory;
class Factory implements IFactory {
class Factory implements IFactory
{
protected ?IDtoFactory $dtoFactory = null;
@ -21,31 +22,30 @@ class Factory implements IFactory {
$this->conf = array_replace_recursive($this->conf, $conf);
}
public function setDtoFactory(IDtoFactory $factory):void
public function setDtoFactory(IDtoFactory $factory): void
{
$this->dtoFactory = $factory;
}
public function createPersist(string $type = ''):PersistItem
public function createPersist(string $type = ''): PersistItem
{
$persist = new $this->conf['persistItem'];
$objFactory = $this->dtoFactory->getModulesFactory()->getSetting(IModuleFactory::OBJECTS_FACTORY);
$persist->setObjectsFactory($objFactory);
if($type){
if ($type) {
$obj = $objFactory->createObjectField($type);
$persist->setObject($obj);
}
return $persist;
}
public function createResource():ResourceItem
public function createResource(): ResourceItem
{
$resource = new $this->conf['resourceItem'];
$dirResource = $this->dtoFactory->getModulesFactory()->getDirsTreeFactory()->getDtoFactory()->createResource();
$dirResource = $this->dtoFactory->getModulesFactory()->getDtoFactory()->getDirFactory()->createResource();
$resource->setDir($dirResource);
$objFactory = $this->dtoFactory->getModulesFactory()->getSetting(IModuleFactory::OBJECTS_FACTORY);
$resource->setObjectsFactory($objFactory);
return $resource;
}
}
}

View File

@ -3,14 +3,15 @@
namespace Src\Modules\JsonObjects\Dto\Item;
use Src\Modules\JsonObjects\Interfaces\Dto\Item\IResourceItem;
use Src\Lib\CategoriesTree\Interfaces\Dto\IResource as IDirResource;
use Src\Modules\JsonObjects\Interfaces\Dto\Dir\IResource as IDirResource;
use Src\Common\Dto\Object\AbstractComposite;
class ResourceItem extends AbstractItem implements IResourceItem {
class ResourceItem extends AbstractItem implements IResourceItem
{
protected IDirResource $dir;
public function setDir(IDirResource $dir):void
public function setDir(IDirResource $dir): void
{
$this->dir = $dir;
}
@ -19,51 +20,50 @@ class ResourceItem extends AbstractItem implements IResourceItem {
{
$this->dir->load($dirData);
}
public function toArray(array $fields = []):array
public function toArray(array $fields = []): array
{
$result = [];
if(!$fields){
if (!$fields) {
$fields = ['id', 'key', 'name', 'description', 'object'];
}
foreach($fields as $key=>$field){
if($field == 'id'){
foreach ($fields as $key => $field) {
if ($field == 'id') {
$result['id'] = $this->id;
}
if($field == 'key'){
if ($field == 'key') {
$result['key'] = $this->key;
}
if($field == 'name'){
if ($field == 'name') {
$result['name'] = $this->name;
}
if($field == 'description'){
if ($field == 'description') {
$result['description'] = $this->description;
}
if($field == 'object'){
if ($field == 'object') {
$result['object'] = $this->object->getJson();
}
}
return $result;
}
public function getDir():IDirResource
public function getDir(): IDirResource
{
return $this->dir;
}
public function isDisabled():bool
public function isDisabled(): bool
{
return (bool) $this->disabled;
}
public function getObject():AbstractComposite
public function getObject(): AbstractComposite
{
return $this->object;
}
public function getName():string
public function getName(): string
{
return $this->name;
}
}
}

View File

@ -4,7 +4,7 @@ namespace Src\Modules\JsonObjects;
use Src\Modules\JsonObjects\Interfaces\IFactory;
use Src\Modules\JsonObjects\Interfaces\IModulesProvider;
use Src\Lib\CategoriesTree\Interfaces\IFactory as IDirsTreeFactory;
// use Src\Lib\CategoriesTree\Interfaces\IFactory as IDirsTreeFactory;
use Src\Sidebar\Interfaces\IFactory as ISidebarFactory;
use Src\Common\Interfaces\IFactory as ICommonFactory;
use Src\Modules\JsonObjects\Interfaces\Dto\IFactory as IDtoFactory;
@ -17,14 +17,15 @@ use Src\Modules\JsonObjects\Interfaces\Application\IFactory as IApplicationFacto
use Src\Modules\JsonObjects\Application\Factory as ApplicationFactory;
use Src\Common\Dto\Object\Factory as ObjectsFactory;
class Factory implements IFactory {
class Factory implements IFactory
{
protected IDirsTreeFactory $dirsTreeFactory;
// protected IDirsTreeFactory $dirsTreeFactory;
protected ISidebarFactory $sidebarFactory;
protected ICommonFactory $commonFactory;
protected ?IDtoFactory $dtoFactory = null;
protected ?IPagesFactory $pagesFactory = null;
@ -37,7 +38,7 @@ class Factory implements IFactory {
protected array $conf;
public function init(array $conf = []): void
{
$this->conf = [
@ -63,31 +64,31 @@ class Factory implements IFactory {
$this->commonFactory = $provider->getCommonFactory();
}
public function getSidebarFactory():ISidebarFactory
public function getSidebarFactory(): ISidebarFactory
{
return $this->sidebarFactory;
}
public function getCommonFactory():ICommonFactory
public function getCommonFactory(): ICommonFactory
{
return $this->commonFactory;
}
public function setDirsTreeFactory(IDirsTreeFactory $factory)
{
$this->dirsTreeFactory = $factory;
$this->dirsTreeFactory->setSetting(IDirsTreeFactory::TABLE_NAME, $this->settings[self::DIRS_TABLE]);
}
// public function setDirsTreeFactory(IDirsTreeFactory $factory)
// {
// $this->dirsTreeFactory = $factory;
// $this->dirsTreeFactory->setSetting(IDirsTreeFactory::TABLE_NAME, $this->settings[self::DIRS_TABLE]);
// }
public function setObjectsFactory(ObjectsFactory $factory): void
{
$this->settings[self::OBJECTS_FACTORY] = $factory;
}
public function getDirsTreeFactory():IDirsTreeFactory
{
return $this->dirsTreeFactory;
}
// public function getDirsTreeFactory():IDirsTreeFactory
// {
// return $this->dirsTreeFactory;
// }
public function loadSettings(array $settings)
{
@ -104,9 +105,9 @@ class Factory implements IFactory {
return $this->settings;
}
public function getDtoFactory():DtoFactory
public function getDtoFactory(): DtoFactory
{
if($this->dtoFactory === null){
if ($this->dtoFactory === null) {
$this->dtoFactory = new $this->conf['dto']['factory'];
$this->dtoFactory->setModulesFactory($this);
$this->dtoFactory->init($this->conf['dto']);
@ -114,9 +115,9 @@ class Factory implements IFactory {
return $this->dtoFactory;
}
public function getPagesFactory():PagesFactory
public function getPagesFactory(): PagesFactory
{
if($this->pagesFactory === null){
if ($this->pagesFactory === null) {
$this->pagesFactory = new $this->conf['pages']['factory'];
$this->pagesFactory->setModuleFactory($this);
$this->pagesFactory->init($this->conf['pages']);
@ -124,9 +125,9 @@ class Factory implements IFactory {
return $this->pagesFactory;
}
public function getInfrastructureFactory():InfrastructureFactory
public function getInfrastructureFactory(): InfrastructureFactory
{
if($this->infrastructureFactory === null){
if ($this->infrastructureFactory === null) {
$this->infrastructureFactory = new $this->conf['infrastructure']['factory'];
$this->infrastructureFactory->setModuleFactory($this);
$this->infrastructureFactory->init($this->conf['infrastructure']);
@ -134,14 +135,13 @@ class Factory implements IFactory {
return $this->infrastructureFactory;
}
public function getApplicationFactory():ApplicationFactory
public function getApplicationFactory(): ApplicationFactory
{
if($this->applicationFactory === null){
if ($this->applicationFactory === null) {
$this->applicationFactory = new $this->conf['application']['factory'];
$this->applicationFactory->setModuleFactory($this);
$this->applicationFactory->init($this->conf['application']);
}
return $this->applicationFactory;
}
}
}

View File

@ -1,12 +1,13 @@
<?php
namespace Src\Lib\CategoriesTree\Infrastructure;
namespace Src\Modules\JsonObjects\Infrastructure;
use Src\Lib\CategoriesTree\Interfaces\Infrastructure\IPersistLayer;
use Src\Lib\CategoriesTree\Interfaces\Dto\IPersist;
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IDirsPersistLayer;
use Src\Modules\JsonObjects\Interfaces\Dto\Dir\IPersist;
use Illuminate\Support\Facades\DB;
class PersistLayer implements IPersistLayer {
class DirsPersistLayer implements IDirsPersistLayer
{
protected string $tableName;
@ -15,27 +16,26 @@ class PersistLayer implements IPersistLayer {
$this->tableName = $tableName;
}
public function newDir(IPersist $dto):bool
public function newDir(IPersist $dto): bool
{
$attrs = $dto->getInsertAttributes();
$qb = DB::table($this->tableName);
return $qb->insert($attrs);
}
public function updateDir(IPersist $dto):int
public function updateDir(IPersist $dto): int
{
$attrs = $dto->getUpdatedAttrs();
if($attrs){
if ($attrs) {
$qb = DB::table($this->tableName);
return $qb->where($this->tableName . '.id', '=', $dto->getId())->update($attrs);
}
return 0;
}
public function deleteDirs(array $ids):int
public function deleteDirs(array $ids): int
{
$qb = DB::table($this->tableName);
return $qb->whereIn($this->tableName . '.id', $ids)->delete();
}
}
}

View File

@ -0,0 +1,106 @@
<?php
namespace Src\Modules\JsonObjects\Infrastructure;
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IDirsQuery;
use Src\Common\Infrastructure\TraitSqlQuery;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Query\Builder;
class DirsQuery implements IDirsQuery
{
use TraitSqlQuery {
TraitSqlQuery::getSelectSection as baseGetSelectSection;
}
protected string $tableName;
protected Builder $queryBuilder;
public function setTableName(string $tableName)
{
$this->tableName = $tableName;
}
protected function reset()
{
$this->queryBuilder = DB::table($this->tableName);
}
// protected function getSelectSection(array $fields, array $allowFields, string $table, string $prefix = ''): array
// {
// $segments = $this->baseGetSelectSection($fields, $allowFields, $table, $prefix);
// $result = [];
// foreach ($segments as $field => $alias) {
// $result[] = $field . ' AS ' . $alias;
// }
// return $result;
// }
public function select(array $fields)
{
$this->reset();
$selectSection = $this->_getSelectSection($fields, ['id', 'matherial_path', 'parent_id', 'name'], $this->tableName);
$this->queryBuilder->select($selectSection);
return $this;
}
public function whereId($id)
{
$this->queryBuilder->where($this->tableName . '.id', '=', $id);
return $this;
}
public function whereIdIn(array $ids)
{
$this->queryBuilder->whereIn($this->tableName . '.id', $ids);
return $this;
}
public function whereParentId($parentId)
{
$this->queryBuilder->where($this->tableName . '.parent_id', '=', $parentId);
return $this;
}
public function whereInPath(string $matherialPath)
{
$this->queryBuilder->where($this->tableName . '.matherial_path', 'like', $matherialPath . '%');
return $this;
}
// public function withParent(array $fields)
// {
// $this->joinParend();
// $selectSection = $this->getSelectSection($fields, ['id', 'matherial_path', 'parent_id', 'name'], $this->tableName, 'parent_');
// $this->queryBuilder->addSelect($selectSection);
// return $this;
// }
// protected function joinParend()
// {
// if (!$this->isParentJoined) {
// $first = $this->tableName . '.id';
// $two = $this->tableName . '.parent_id';
// $this->queryBuilder->leftJoin($this->tableName . ' AS parent', $first, '=', $two);
// $this->isParentJoined = true;
// }
// }
public function all(): array
{
$result = [];
foreach ($this->queryBuilder->get()->all() as $row) {
$result[$row->id] = $row;
}
return json_decode(json_encode($result), true);
}
public function one(): array
{
$result = $this->queryBuilder->first() ?? [];
$result = json_decode(json_encode($result), true);
return $result;
}
}

View File

@ -0,0 +1,64 @@
<?php
namespace Src\Modules\JsonObjects\Infrastructure;
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IDirsStorage;
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IDirsQuery;
use Src\Common\Infrastructure\TraitStorage;
class DirsStorage implements IDirsStorage
{
use TraitStorage;
protected IDirsQuery $query;
protected IDirsQuery $parentQuery;
public function setQuery(IDirsQuery $query)
{
$this->query = $query;
}
public function setParentQuery(IDirsQuery $query)
{
$this->parentQuery = $query;
}
public function getById($id, array $dsl = []): array
{
$this->query->select($dsl)->whereId($id);
$data = $this->query->one();
if (!$data) {
return [];
}
if (key_exists('parent', $dsl)) {
$parentData = $this->parentQuery->select($dsl['parent'])->whereId($data['parent_id'])->all();
$data['parent'] = $parentData;
}
if (key_exists('path', $dsl) && isset($data['matherial_path'])) {
$ids = explode('|', $data['matherial_path']);
$path = $this->query->select($dsl['path'])->whereIdIn($ids)->all();
$data['path'] = $path;
}
return $data;
}
public function getByParentId($parentId, array $dsl = []): array
{
return $this->query->select($dsl)->whereParentId($parentId)->all();
}
public function getIdsInDir(string $dirId): array
{
$dirData = $this->query->select(['id', 'matherial_path'])->whereId($dirId)->one();
$pathIds = ($dirData['matherial_path']) ? explode('|', $dirData['matherial_path']) : [];
$pathIds[] = $dirId;
$matherialPath = join('|', $pathIds);
$dirs = $this->query->select(['id'])->whereInPath($matherialPath)->all();
$ids = array_map(function ($dir) {
return $dir['id'];
}, $dirs);
return array_values($ids);
}
}

View File

@ -4,13 +4,17 @@ namespace Src\Modules\JsonObjects\Infrastructure;
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IFactory;
use Src\Modules\JsonObjects\Interfaces\IFactory as IModuleFactory;
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemQuery;
use Src\Modules\JsonObjects\Infrastructure\ItemQuery;
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemStorage;
use Src\Modules\JsonObjects\Infrastructure\ItemStorage;
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemPersistLayer;
use Src\Modules\JsonObjects\Infrastructure\ItemPersistLayer;
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IMigrations;
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IDirsStorage;
use Src\Modules\JsonObjects\Infrastructure\DirsStorage;
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IDirsQuery;
use Src\Modules\JsonObjects\Infrastructure\DirsQuery;
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IDirsPersistLayer;
use Src\Modules\JsonObjects\Infrastructure\DirsPersistLayer;
class Factory implements IFactory
{
@ -21,7 +25,9 @@ class Factory implements IFactory
protected ?IItemPersistLayer $persistLayer = null;
protected ?IMigrations $migration = null;
protected ?IDirsStorage $dirsStorage = null;
protected ?IDirsPersistLayer $dirsPersistLayer = null;
protected array $conf;
@ -31,6 +37,9 @@ class Factory implements IFactory
'itemQuery' => ItemQuery::class,
'itemStorage' => ItemStorage::class,
'itemPersistLayer' => ItemPersistLayer::class,
'dirsStorage' => DirsStorage::class,
'dirsQuery' => DirsQuery::class,
'dirPersistLayer' => DirsPersistLayer::class,
];
$this->conf = array_replace_recursive($this->conf, $conf);
}
@ -54,8 +63,8 @@ class Factory implements IFactory
$this->storage = new $this->conf['itemStorage'];
$query = $this->createQuery();
$this->storage->setObjectsQuery($query);
$dirStorage = $this->moduleFactory->getDirsTreeFactory()->getInfrastructureFactory()->getStorage();
$this->storage->setDirStorage($dirStorage);
$dirsStorage = $this->getDirsStorage();
$this->storage->setDirStorage($dirsStorage);
}
return $this->storage;
}
@ -69,4 +78,34 @@ class Factory implements IFactory
}
return $this->persistLayer;
}
public function createDirsQuery(): IDirsQuery
{
$query = new $this->conf['dirsQuery'];
$tableName = $this->moduleFactory->getSetting(IModuleFactory::DIRS_TABLE);
$query->setTableName($tableName);
return $query;
}
public function getDirsStorage(): IDirsStorage
{
if ($this->dirsStorage === null) {
$this->dirsStorage = new $this->conf['dirsStorage'];
$query = $this->createDirsQuery();
$this->dirsStorage->setQuery($query);
$query = $this->createDirsQuery();
$this->dirsStorage->setParentQuery($query);
}
return $this->dirsStorage;
}
public function getDirsPersistLayer(): IDirsPersistLayer
{
if ($this->dirsPersistLayer === null) {
$this->dirsPersistLayer = new $this->conf['dirPersistLayer'];
$tableName = $this->moduleFactory->getSetting(IModuleFactory::DIRS_TABLE);
$this->dirsPersistLayer->setTableName($tableName);
}
return $this->dirsPersistLayer;
}
}

View File

@ -6,9 +6,9 @@ use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemQuery;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Query\Builder;
use Src\Common\Infrastructure\TraitSqlQuery;
use hrustbb2\arrayproc\ArrayProcessor;
class ItemQuery implements IItemQuery {
class ItemQuery implements IItemQuery
{
use TraitSqlQuery {
TraitSqlQuery::getSelectSection as baseGetSelectSection;
@ -18,29 +18,16 @@ class ItemQuery implements IItemQuery {
protected Builder $queryBuilder;
protected array $arrayProcConf = [];
public function setTableName(string $tableName)
{
$this->tableName = $tableName;
}
protected function getSelectSection(array $fields, array $allowFields, string $table, string $prefix = ''): array
{
$segments = $this->baseGetSelectSection($fields, $allowFields, $table, $prefix);
$result = [];
foreach($segments as $field=>$alias){
$result[] = $field . ' AS ' . $alias;
}
return $result;
}
public function select(array $fields = [])
{
$this->queryBuilder = DB::table($this->tableName);
$select = $this->getSelectSection($fields, ['id', 'dir_id', 'key', 'name', 'description', 'object', 'disabled'], $this->tableName, 'object_');
$select = $this->_getSelectSection($fields, ['id', 'dir_id', 'key', 'name', 'description', 'object', 'disabled'], $this->tableName);
$this->queryBuilder->select($select);
$this->arrayProcConf = ['prefix' => 'object_'];
return $this;
}
@ -89,20 +76,17 @@ class ItemQuery implements IItemQuery {
public function all(): array
{
$arrayProc = new ArrayProcessor();
// DB::enableQueryLog();
$data = $this->queryBuilder->get()->toArray();
// $log = DB::getQueryLog();
// dd($log);
return $arrayProc->process($this->arrayProcConf, $data)->resultArray();
$result = [];
foreach ($this->queryBuilder->get()->all() as $row) {
$result[$row->id] = $row;
}
return json_decode(json_encode($result), true);
}
public function one(): array
{
$arrayProc = new ArrayProcessor();
$data = $this->queryBuilder->get()->toArray();
$d = $arrayProc->process($this->arrayProcConf, $data)->resultArray();
return array_pop($d) ?? [];
$result = $this->queryBuilder->first() ?? [];
$result = json_decode(json_encode($result), true);
return $result;
}
}
}

View File

@ -4,36 +4,37 @@ namespace Src\Modules\JsonObjects\Infrastructure;
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemStorage;
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemQuery;
use Src\Lib\CategoriesTree\Interfaces\Infrastructure\IStorage as IDirStorage;
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IDirsStorage;
use Src\Common\Infrastructure\TraitStorage;
class ItemStorage implements IItemStorage {
class ItemStorage implements IItemStorage
{
use TraitStorage;
protected IItemQuery $objectsQuery;
protected IDirStorage $dirStorage;
protected IDirsStorage $dirsStorage;
public function setObjectsQuery(IItemQuery $query)
{
$this->objectsQuery = $query;
}
public function setDirStorage(IDirStorage $storage):void
public function setDirStorage(IDirsStorage $storage): void
{
$this->dirStorage = $storage;
$this->dirsStorage = $storage;
}
public function getById(string $itemId, array $dsl = []):array
public function getById(string $itemId, array $dsl = []): array
{
$itemData = $this->objectsQuery->select($dsl)->whereId($itemId)->one();
if(empty($itemData)){
if (empty($itemData)) {
return [];
}
if(key_exists('dir', $dsl)){
if (key_exists('dir', $dsl)) {
$dirId = $itemData['dir_id'];
$dirData = $this->dirStorage->getById($dirId, $dsl['dir']);
$dirData = $this->dirsStorage->getById($dirId, $dsl['dir']);
$itemData['dir'] = [
$dirId => $dirData,
];
@ -41,26 +42,25 @@ class ItemStorage implements IItemStorage {
return $itemData;
}
public function getByIds(array $ids, array $dsl = []):array
public function getByIds(array $ids, array $dsl = []): array
{
$itemsData = $this->objectsQuery->select($dsl)->whereIdIn($ids)->all();
return $itemsData;
}
}
public function getByType(string $type, int $limit, int $offset, array $dsl = []):array
public function getByType(string $type, int $limit, int $offset, array $dsl = []): array
{
$itemsData = $this->objectsQuery->select($dsl)->limit($limit, $offset)->whereType($type)->all();
return $itemsData;
}
public function getByKey(string $key, array $dsl = []):array
public function getByKey(string $key, array $dsl = []): array
{
return $this->objectsQuery->select($dsl)->whereKey($key)->one();
}
public function getByDirId(string $dirId, array $dsl = []):array
public function getByDirId(string $dirId, array $dsl = []): array
{
return $this->objectsQuery->select($dsl)->whereDirId($dirId)->all();
}
}
}

View File

@ -2,9 +2,11 @@
namespace Src\Modules\JsonObjects\Interfaces\Application;
use Src\Lib\CategoriesTree\Interfaces\Infrastructure\IStorage as IDirStorage;
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IDirsStorage;
interface IDataBuilder {
public function setDirStorage(IDirStorage $dirStorage):void;
public function build(array $data):array;
}
interface IDataBuilder
{
public function setDirStorage(IDirsStorage $dirStorage): void;
public function build(array $data): array;
public function buildDirData(array $requestData): array;
}

View File

@ -9,23 +9,26 @@ use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemPersistLayer;
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemStorage;
use Src\Modules\JsonObjects\Interfaces\Dto\Item\IResourceItem;
use Src\Modules\JsonObjects\Interfaces\Application\IDataBuilder;
use Src\Lib\CategoriesTree\Interfaces\Application\IValidator as IDirValidator;
use Src\Lib\CategoriesTree\Interfaces\Application\IDomain as IDirDomain;
use Src\Lib\CategoriesTree\Interfaces\Infrastructure\IStorage as IDirStorage;
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IDirsStorage;
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IDirsPersistLayer;
use Src\Modules\JsonObjects\Interfaces\Dto\Dir\IResource as IDirResource;
interface IDomain extends IBaseDomain {
public function setValidator(IValidator $validator):void;
public function setDtoFactory(IDtoFactory $factory):void;
public function setPersistLayer(IItemPersistLayer $layer):void;
public function setStorage(IItemStorage $storage):void;
public function setDataBuilder(IDataBuilder $dataBuilder):void;
public function setDirValidator(IDirValidator $validator):void;
public function setDirDomain(IDirDomain $domain):void;
public function setDirStorage(IDirStorage $storage):void;
public function createObject(array $data):bool;
public function editObject(array $data):bool;
public function renameObject(array $data):bool;
public function deleteObject(array $data):bool;
public function deleteDir(array $data):bool;
public function getItem():IResourceItem;
}
interface IDomain extends IBaseDomain
{
public function setValidator(IValidator $validator): void;
public function setDtoFactory(IDtoFactory $factory): void;
public function setPersistLayer(IItemPersistLayer $layer): void;
public function setStorage(IItemStorage $storage): void;
public function setDataBuilder(IDataBuilder $dataBuilder): void;
public function setDirStorage(IDirsStorage $storage): void;
public function setDirsPersistLayer(IDirsPersistLayer $layer): void;
public function createObject(array $data): bool;
public function editObject(array $data): bool;
public function renameObject(array $data): bool;
public function deleteObject(array $data): bool;
public function deleteDir(array $data): bool;
public function getItem(): IResourceItem;
public function createDir(array $data): bool;
public function renameDir(array $data): bool;
public function getDir(): IDirResource;
}

View File

@ -4,9 +4,13 @@ namespace Src\Modules\JsonObjects\Interfaces\Application;
use Src\Common\Interfaces\Application\IBaseValidator;
interface IValidator extends IBaseValidator {
public function createObject(array $data):bool;
public function editObject(array $data):bool;
public function renameObject(array $data):bool;
public function deleteObject(array $data):bool;
}
interface IValidator extends IBaseValidator
{
public function createObject(array $data): bool;
public function editObject(array $data): bool;
public function renameObject(array $data): bool;
public function deleteObject(array $data): bool;
public function createDir(array $data): bool;
public function renameDir(array $data): bool;
public function deleteDir(array $data): bool;
}

View File

@ -1,11 +1,12 @@
<?php
namespace Src\Lib\CategoriesTree\Interfaces\Dto;
namespace Src\Modules\JsonObjects\Interfaces\Dto\Dir;
interface IAbstractCategory {
interface IAbstractCategory
{
public function getId();
public function load(array $data);
public function loadPath(array $data);
public function loadParent(array $data);
public function getAttributes();
}
}

View File

@ -0,0 +1,13 @@
<?php
namespace Src\Modules\JsonObjects\Interfaces\Dto\Dir;
use Src\Modules\JsonObjects\Interfaces\Dto\IFactory as IDtoFactory;
interface IFactory
{
public function init(array $conf = []): void;
public function setDtoFactory(IDtoFactory $factory): void;
public function createPersist(): IPersist;
public function createResource(): IResource;
}

View File

@ -0,0 +1,15 @@
<?php
namespace Src\Modules\JsonObjects\Interfaces\Dto\Dir;
use Src\Modules\JsonObjects\Interfaces\Dto\IFactory as IDtoFactory;
interface IPersist extends IAbstractCategory
{
public function init(): void;
public function setDtoFactory(IDtoFactory $factory);
public function update(array $data): void;
public function getInsertAttributes(): array;
public function getPath(): array;
public function getUpdatedAttrs(): array;
}

View File

@ -0,0 +1,17 @@
<?php
namespace Src\Modules\JsonObjects\Interfaces\Dto\Dir;
use Src\Modules\JsonObjects\Interfaces\Dto\IFactory as IDtoFactory;
interface IResource extends IAbstractCategory
{
public function setDtoFactory(IDtoFactory $factory);
public function toArray(array $fields = []): array;
/**
* @return IResource[]
*/
public function getPath(): array;
public function getName(): string;
public function getParent(): ?IResource;
}

View File

@ -4,10 +4,13 @@ namespace Src\Modules\JsonObjects\Interfaces\Dto;
use Src\Modules\JsonObjects\Interfaces\IFactory as IModulesFactory;
use Src\Modules\JsonObjects\Interfaces\Dto\Item\IFactory as IItemFactory;
use Src\Modules\JsonObjects\Interfaces\Dto\Dir\IFactory as IDirFactory;
interface IFactory {
interface IFactory
{
public function init(array $conf = []): void;
public function setModulesFactory(IModulesFactory $factory);
public function getModulesFactory():IModulesFactory;
public function getItemFactory():IItemFactory;
}
public function getModulesFactory(): IModulesFactory;
public function getItemFactory(): IItemFactory;
public function getDirFactory(): IDirFactory;
}

View File

@ -2,14 +2,15 @@
namespace Src\Modules\JsonObjects\Interfaces\Dto\Item;
use Src\Lib\CategoriesTree\Interfaces\Dto\IResource as IDirResource;
use Src\Modules\JsonObjects\Interfaces\Dto\Dir\IResource as IDirResource;
use Src\Common\Dto\Object\AbstractComposite;
interface IResourceItem extends IAbstractItem {
public function setDir(IDirResource $dir):void;
public function toArray(array $fields = []):array;
public function getDir():IDirResource;
public function isDisabled():bool;
public function getObject():AbstractComposite;
public function getName():string;
}
interface IResourceItem extends IAbstractItem
{
public function setDir(IDirResource $dir): void;
public function toArray(array $fields = []): array;
public function getDir(): IDirResource;
public function isDisabled(): bool;
public function getObject(): AbstractComposite;
public function getName(): string;
}

View File

@ -5,14 +5,15 @@ namespace Src\Modules\JsonObjects\Interfaces;
use Src\Modules\JsonObjects\Interfaces\IModulesProvider;
use Src\Common\Interfaces\IFactory as ICommonFactory;
use Src\Sidebar\Interfaces\IFactory as ISidebarFactory;
use Src\Lib\CategoriesTree\Interfaces\IFactory as IDirsTreeFactory;
// use Src\Lib\CategoriesTree\Interfaces\IFactory as IDirsTreeFactory;
use Src\Modules\JsonObjects\Interfaces\Dto\IFactory as IDtoFactory;
use Src\Modules\JsonObjects\Interfaces\Pages\IFactory as IPagesFactory;
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IFactory as IInfrastructureFactory;
use Src\Modules\JsonObjects\Interfaces\Application\IFactory as IApplicationFactory;
use Src\Common\Dto\Object\Factory as ObjectsFactory;
interface IFactory {
interface IFactory
{
const DB_HOST = 'db_host';
@ -38,16 +39,16 @@ interface IFactory {
public function init(array $conf = []): void;
public function injectModules(IModulesProvider $provider);
public function getSidebarFactory():ISidebarFactory;
public function getCommonFactory():ICommonFactory;
public function setDirsTreeFactory(IDirsTreeFactory $factory);
public function getDirsTreeFactory():IDirsTreeFactory;
public function getSidebarFactory(): ISidebarFactory;
public function getCommonFactory(): ICommonFactory;
// public function setDirsTreeFactory(IDirsTreeFactory $factory);
// public function getDirsTreeFactory():IDirsTreeFactory;
public function loadSettings(array $settings);
public function getSetting(string $key);
public function getSettings(): array;
public function setObjectsFactory(ObjectsFactory $factory): void;
public function getDtoFactory():IDtoFactory;
public function getPagesFactory():IPagesFactory;
public function getInfrastructureFactory():IInfrastructureFactory;
public function getApplicationFactory():IApplicationFactory;
}
public function getDtoFactory(): IDtoFactory;
public function getPagesFactory(): IPagesFactory;
public function getInfrastructureFactory(): IInfrastructureFactory;
public function getApplicationFactory(): IApplicationFactory;
}

View File

@ -0,0 +1,13 @@
<?php
namespace Src\Modules\JsonObjects\Interfaces\Infrastructure;
use Src\Modules\JsonObjects\Interfaces\Dto\Dir\IPersist;
interface IDirsPersistLayer
{
public function setTableName(string $tableName);
public function newDir(IPersist $dto): bool;
public function updateDir(IPersist $dto): int;
public function deleteDirs(array $ids): int;
}

View File

@ -1,10 +1,11 @@
<?php
namespace Src\Lib\CategoriesTree\Interfaces\Infrastructure;
namespace Src\Modules\JsonObjects\Interfaces\Infrastructure;
use Src\Common\Interfaces\Infrastructure\IQueryBase;
interface IQuery extends IQueryBase {
interface IDirsQuery extends IQueryBase
{
/**
* @return $this
*/
@ -29,9 +30,4 @@ interface IQuery extends IQueryBase {
* @return $this
*/
public function whereInPath(string $matherialPath);
/**
* @return $this
*/
public function withParent(array $fields);
}
}

View File

@ -0,0 +1,14 @@
<?php
namespace Src\Modules\JsonObjects\Interfaces\Infrastructure;
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IDirsQuery;
interface IDirsStorage
{
public function setQuery(IDirsQuery $query);
public function setParentQuery(IDirsQuery $query);
public function getById($id, array $dsl = []): array;
public function getByParentId($parentId, array $dsl = []): array;
public function getIdsInDir(string $materialPath): array;
}

View File

@ -5,6 +5,9 @@ namespace Src\Modules\JsonObjects\Interfaces\Infrastructure;
use Src\Modules\JsonObjects\Interfaces\IFactory as IModuleFactory;
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemStorage;
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemPersistLayer;
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IDirsStorage;
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IDirsQuery;
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IDirsPersistLayer;
interface IFactory
{
@ -12,4 +15,7 @@ interface IFactory
public function setModuleFactory(IModuleFactory $factory);
public function getStorage(): IItemStorage;
public function getPersistLayer(): IItemPersistLayer;
public function createDirsQuery(): IDirsQuery;
public function getDirsStorage(): IDirsStorage;
public function getDirsPersistLayer(): IDirsPersistLayer;
}

View File

@ -3,14 +3,15 @@
namespace Src\Modules\JsonObjects\Interfaces\Infrastructure;
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemQuery;
use Src\Lib\CategoriesTree\Interfaces\Infrastructure\IStorage as IDirStorage;
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IDirsStorage;
interface IItemStorage {
interface IItemStorage
{
public function setObjectsQuery(IItemQuery $query);
public function setDirStorage(IDirStorage $storage):void;
public function getById(string $itemId, array $dsl = []):array;
public function getByIds(array $ids, array $dsl = []):array;
public function getByType(string $type, int $limit, int $offset, array $dsl = []):array;
public function getByKey(string $key, array $dsl = []):array;
public function getByDirId(string $dirId, array $dsl = []):array;
}
public function setDirStorage(IDirsStorage $storage): void;
public function getById(string $itemId, array $dsl = []): array;
public function getByIds(array $ids, array $dsl = []): array;
public function getByType(string $type, int $limit, int $offset, array $dsl = []): array;
public function getByKey(string $key, array $dsl = []): array;
public function getByDirId(string $dirId, array $dsl = []): array;
}

View File

@ -3,18 +3,19 @@
namespace Src\Modules\JsonObjects\Interfaces\Pages;
use Src\Common\Interfaces\Pages\IAbstractPage;
use Src\Lib\CategoriesTree\Interfaces\Infrastructure\IStorage as IDirsStorage;
use Src\Lib\CategoriesTree\Interfaces\Dto\IFactory as IDirsDtoFactory;
use Src\Modules\JsonObjects\Interfaces\Dto\Dir\IFactory as IDirsDtoFactory;
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IDirsStorage;
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemStorage;
use Src\Modules\JsonObjects\Interfaces\Dto\Item\IFactory as IItemDtoFactory;
interface IDir extends IAbstractPage {
public function setDirsStorage(IDirsStorage $storage):void;
public function setDirsDtoFactory(IDirsDtoFactory $factory):void;
public function setItemStorage(IItemStorage $storage):void;
public function setItemDtoFactory(IItemDtoFactory $factory):void;
public function setItemsDropdown(array $dropDown):void;
public function init(string $currentDirId):void;
public function getBreadcrumbs():array;
public function getItemsDropdown():array;
}
interface IDir extends IAbstractPage
{
public function setDirsStorage(IDirsStorage $storage): void;
public function setDirsDtoFactory(IDirsDtoFactory $factory): void;
public function setItemStorage(IItemStorage $storage): void;
public function setItemDtoFactory(IItemDtoFactory $factory): void;
public function setItemsDropdown(array $dropDown): void;
public function init(string $currentDirId): void;
public function getBreadcrumbs(): array;
public function getItemsDropdown(): array;
}

View File

@ -8,7 +8,8 @@ use Src\Modules\JsonObjects\Interfaces\IFactory as IModuleFactory;
use Illuminate\Support\Facades\View;
use Illuminate\Http\Request;
class DirController extends Controller {
class DirController extends Controller
{
/**
* @var IModuleFactory
@ -33,7 +34,7 @@ class DirController extends Controller {
public function newDir(Request $request)
{
$domain = $this->factory->getDirsTreeFactory()->getApplicationFactory()->getDomain();
$domain = $this->factory->getApplicationFactory()->getDomain();
$data = $request->all();
$resp = [
'success' => $domain->createDir($data),
@ -45,7 +46,7 @@ class DirController extends Controller {
public function renameDir(Request $request)
{
$domain = $this->factory->getDirsTreeFactory()->getApplicationFactory()->getDomain();
$domain = $this->factory->getApplicationFactory()->getDomain();
$data = $request->all();
$resp = [
'success' => $domain->renameDir($data),
@ -65,5 +66,4 @@ class DirController extends Controller {
];
return response()->json($resp, $domain->getResponseCode());
}
}
}

View File

@ -4,9 +4,9 @@ namespace Src\Modules\JsonObjects\Pages;
use Src\Common\Pages\Page;
use Src\Modules\JsonObjects\Interfaces\Pages\IDir;
use Src\Lib\CategoriesTree\Interfaces\Infrastructure\IStorage as IDirsStorage;
use Src\Lib\CategoriesTree\Interfaces\Dto\IFactory as IDirsDtoFactory;
use Src\Lib\CategoriesTree\Interfaces\Dto\IResource as IDirResource;
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IDirsStorage;
use Src\Modules\JsonObjects\Interfaces\Dto\Dir\IFactory as IDirsDtoFactory;
use Src\Modules\JsonObjects\Interfaces\Dto\Dir\IResource as IDirResource;
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemStorage;
use Src\Modules\JsonObjects\Interfaces\Dto\Item\IFactory as IItemDtoFactory;
use Src\Modules\JsonObjects\Interfaces\Dto\Item\IResourceItem;
@ -144,6 +144,10 @@ class Dir extends Page implements IDir
'href' => route('admin.jsonObjects.dir', ['dir-id' => $this->currentDir->getParent()->getId()], false),
];
}
$bc[] = [
'title' => $this->currentDir->getName(),
'href' => route('admin.jsonObjects.dir', ['dir-id' => $this->currentDir->getId()], false),
];
return $bc;
}

View File

@ -33,9 +33,9 @@ class Factory implements IFactory
$page = new $this->conf['dir'];
$sidebarMenu = $this->moduleFactory->getSidebarFactory()->getMenu();
$page->setSidebar($sidebarMenu);
$dirsStorage = $this->moduleFactory->getDirsTreeFactory()->getInfrastructureFactory()->getStorage();
$dirsStorage = $this->moduleFactory->getInfrastructureFactory()->getDirsStorage();
$page->setDirsStorage($dirsStorage);
$dirsDtoFactory = $this->moduleFactory->getDirsTreeFactory()->getDtoFactory();
$dirsDtoFactory = $this->moduleFactory->getDtoFactory()->getDirFactory();
$page->setDirsDtoFactory($dirsDtoFactory);
$itemStorage = $this->moduleFactory->getInfrastructureFactory()->getStorage();
$page->setItemStorage($itemStorage);

View File

@ -118,6 +118,10 @@ class Item extends Page implements IItem
'href' => route('admin.jsonObjects.dir', ['dir-id' => $this->item->getDir()->getParent()->getId()], false),
];
}
$bc[] = [
'title' => $this->item->getDir()->getName(),
'href' => route('admin.jsonObjects.dir', ['dir-id' => $this->item->getDir()->getId()], false),
];
$bc[] = [
'title' => $this->item->getName(),
'href' => route('admin.jsonObjects.editItem', ['item-id' => $this->item->getId()], false),

View File

@ -18,8 +18,8 @@ use Src\Modules\JsonObjects\Interfaces\IModulesProvider as IJSONProvider;
use Src\Modules\JsonObjects\Interfaces\IFactory as IJSONFactory;
use Src\Modules\JsonObjects\Factory as JSONFactory;
use Src\Lib\CategoriesTree\Interfaces\IFactory as IDirTreeFactory;
use Src\Lib\CategoriesTree\Factory as DirTreeFactory;
// use Src\Lib\CategoriesTree\Interfaces\IFactory as IDirTreeFactory;
// use Src\Lib\CategoriesTree\Factory as DirTreeFactory;
use Src\Common\Interfaces\Dto\Object\IFactory as IObjFactory;
@ -45,17 +45,17 @@ class ModulesProvider implements ICommonProvider, ISidebarProvider, IJSONProvide
'common' => [
'factory' => CommonFactory::class,
],
'jsonObjectsDirs' => [
'factory' => DirTreeFactory::class,
'settings' => [
IDirTreeFactory::DB_CHARSET => 'utf8',
IDirTreeFactory::DB_HOST => env('DB_HOST'),
IDirTreeFactory::DB_NAME => env('DB_DATABASE'),
IDirTreeFactory::DB_PASS => env('DB_PASSWORD'),
IDirTreeFactory::DB_USER => env('DB_USERNAME'),
// IDirTreeFactory::TABLE_NAME => $dirsTable,
],
],
// 'jsonObjectsDirs' => [
// 'factory' => DirTreeFactory::class,
// 'settings' => [
// IDirTreeFactory::DB_CHARSET => 'utf8',
// IDirTreeFactory::DB_HOST => env('DB_HOST'),
// IDirTreeFactory::DB_NAME => env('DB_DATABASE'),
// IDirTreeFactory::DB_PASS => env('DB_PASSWORD'),
// IDirTreeFactory::DB_USER => env('DB_USERNAME'),
// // IDirTreeFactory::TABLE_NAME => $dirsTable,
// ],
// ],
'jsonObjects' => [
'factory' => JSONFactory::class,
'settings' => [
@ -108,14 +108,14 @@ class ModulesProvider implements ICommonProvider, ISidebarProvider, IJSONProvide
return $this->commonFactory;
}
protected function createDirTreeFactory(): DirTreeFactory
{
$factory = $this->createInstance($this->conf['jsonObjectsDirs']['factory']);
$factory->loadSettings($this->conf['jsonObjectsDirs']['settings']);
$factory->init();
$factory->setCommonFactory($this->getCommonFactory());
return $factory;
}
// protected function createDirTreeFactory(): DirTreeFactory
// {
// $factory = $this->createInstance($this->conf['jsonObjectsDirs']['factory']);
// $factory->loadSettings($this->conf['jsonObjectsDirs']['settings']);
// $factory->init();
// $factory->setCommonFactory($this->getCommonFactory());
// return $factory;
// }
public function getJsonObjectsFactory(): JSONFactory
{
@ -123,8 +123,8 @@ class ModulesProvider implements ICommonProvider, ISidebarProvider, IJSONProvide
$this->jsonFactory = $this->createInstance($this->conf['jsonObjects']['factory']);
$this->jsonFactory->init();
$this->jsonFactory->loadSettings($this->conf['jsonObjects']['settings']);
$dirTreeFactory = $this->createDirTreeFactory();
$this->jsonFactory->setDirsTreeFactory($dirTreeFactory);
// $dirTreeFactory = $this->createDirTreeFactory();
// $this->jsonFactory->setDirsTreeFactory($dirTreeFactory);
$this->jsonFactory->injectModules($this);
}
return $this->jsonFactory;

4
storage/uploads/.gitignore vendored Executable file
View File

@ -0,0 +1,4 @@
*
!_thumb/
!files-browser
!.gitignore

Binary file not shown.

Before

Width:  |  Height:  |  Size: 364 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.2 KiB