refactor
This commit is contained in:
parent
ab21e31a09
commit
a257f257a0
|
|
@ -10,7 +10,6 @@
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^8.2",
|
"php": "^8.2",
|
||||||
"hrustbb2/arrayproc": "^1.0",
|
|
||||||
"intervention/image": "^3.11",
|
"intervention/image": "^3.11",
|
||||||
"laravel/framework": "^12.0",
|
"laravel/framework": "^12.0",
|
||||||
"laravel/tinker": "^2.10.1"
|
"laravel/tinker": "^2.10.1"
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
"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": "5e576ac699c4de01e220426df03617e0",
|
"content-hash": "51576dda271759cce587475988cbe4e8",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "brick/math",
|
"name": "brick/math",
|
||||||
|
|
@ -1054,56 +1054,6 @@
|
||||||
],
|
],
|
||||||
"time": "2025-02-03T10:55:03+00:00"
|
"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",
|
"name": "intervention/gif",
|
||||||
"version": "4.2.2",
|
"version": "4.2.2",
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
../storage/uploads/files-browser
|
||||||
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -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) ?? [];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
migrations.json
|
|
||||||
|
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -3,13 +3,14 @@
|
||||||
namespace Src\Modules\JsonObjects\Application;
|
namespace Src\Modules\JsonObjects\Application;
|
||||||
|
|
||||||
use Src\Modules\JsonObjects\Interfaces\Application\IDataBuilder;
|
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;
|
$this->dirStorage = $dirStorage;
|
||||||
}
|
}
|
||||||
|
|
@ -29,4 +30,19 @@ class DataBuilder implements IDataBuilder {
|
||||||
return $data;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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\IItemPersistLayer;
|
||||||
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemStorage;
|
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemStorage;
|
||||||
use Src\Modules\JsonObjects\Interfaces\Application\IDataBuilder;
|
use Src\Modules\JsonObjects\Interfaces\Application\IDataBuilder;
|
||||||
use Src\Lib\CategoriesTree\Interfaces\Application\IValidator as IDirValidator;
|
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IDirsStorage;
|
||||||
use Src\Lib\CategoriesTree\Interfaces\Application\IDomain as IDirDomain;
|
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IDirsPersistLayer;
|
||||||
use Src\Lib\CategoriesTree\Interfaces\Infrastructure\IStorage as IDirStorage;
|
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;
|
use TraitDomain;
|
||||||
|
|
||||||
|
|
@ -31,11 +33,11 @@ class Domain implements IDomain {
|
||||||
|
|
||||||
protected IDataBuilder $dataBuilder;
|
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
|
||||||
{
|
{
|
||||||
|
|
@ -62,19 +64,14 @@ class Domain implements IDomain {
|
||||||
$this->dataBuilder = $dataBuilder;
|
$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
|
||||||
|
|
@ -162,23 +159,99 @@ class Domain implements IDomain {
|
||||||
|
|
||||||
public function deleteDir(array $data): bool
|
public function deleteDir(array $data): bool
|
||||||
{
|
{
|
||||||
if($this->dirValidator->deleteDir($data)){
|
if ($this->validator->deleteDir($data)) {
|
||||||
$cleanData = $this->dirValidator->getCleanData();
|
$cleanData = $this->validator->getCleanData();
|
||||||
$dirIds = $this->dirStorage->getIdsInDir($cleanData['id']);
|
$dirIds = $this->dirsStorage->getIdsInDir($cleanData['id']);
|
||||||
$dirIds[] = $cleanData['id'];
|
$dirIds[] = $cleanData['id'];
|
||||||
$this->persistLayer->deleteInDirs($dirIds);
|
$this->persistLayer->deleteInDirs($dirIds);
|
||||||
$this->dirDomain->deleteDir($data);
|
$this->_deleteDir($data);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
$this->errors = $this->dirValidator->getErrors();
|
$this->errors = $this->validator->getErrors();
|
||||||
$this->responseCode = ResponsesCode::VALIDATION_FAILED_CODE;
|
$this->responseCode = ResponsesCode::VALIDATION_FAILED_CODE;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
public function getItem(): IResourceItem
|
||||||
{
|
{
|
||||||
return $this->item;
|
return $this->item;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -8,7 +8,8 @@ use Src\Modules\JsonObjects\Interfaces\Application\IValidator;
|
||||||
use Src\Modules\JsonObjects\Interfaces\Application\IDomain;
|
use Src\Modules\JsonObjects\Interfaces\Application\IDomain;
|
||||||
use Src\Modules\JsonObjects\Interfaces\Application\IDataBuilder;
|
use Src\Modules\JsonObjects\Interfaces\Application\IDataBuilder;
|
||||||
|
|
||||||
class Factory implements IFactory {
|
class Factory implements IFactory
|
||||||
|
{
|
||||||
|
|
||||||
protected IModuleFactory $moduleFactory;
|
protected IModuleFactory $moduleFactory;
|
||||||
|
|
||||||
|
|
@ -57,7 +58,7 @@ class Factory implements IFactory {
|
||||||
protected function creteDataBuilder(): DataBuilder
|
protected function creteDataBuilder(): DataBuilder
|
||||||
{
|
{
|
||||||
$dataBuilder = $this->createInstance($this->conf['dataBuilder']);
|
$dataBuilder = $this->createInstance($this->conf['dataBuilder']);
|
||||||
$storage = $this->moduleFactory->getDirsTreeFactory()->getInfrastructureFactory()->getStorage();
|
$storage = $this->moduleFactory->getInfrastructureFactory()->getDirsStorage();
|
||||||
$dataBuilder->setDirStorage($storage);
|
$dataBuilder->setDirStorage($storage);
|
||||||
return $dataBuilder;
|
return $dataBuilder;
|
||||||
}
|
}
|
||||||
|
|
@ -76,12 +77,10 @@ class Factory implements IFactory {
|
||||||
$this->domain->setStorage($storage);
|
$this->domain->setStorage($storage);
|
||||||
$dataBuilder = $this->creteDataBuilder();
|
$dataBuilder = $this->creteDataBuilder();
|
||||||
$this->domain->setDataBuilder($dataBuilder);
|
$this->domain->setDataBuilder($dataBuilder);
|
||||||
$dirValidator = $this->moduleFactory->getDirsTreeFactory()->getApplicationFactory()->createValidator();
|
$dirStorage = $this->moduleFactory->getInfrastructureFactory()->getDirsStorage();
|
||||||
$this->domain->setDirValidator($dirValidator);
|
|
||||||
$dirDomain = $this->moduleFactory->getDirsTreeFactory()->getApplicationFactory()->getDomain();
|
|
||||||
$this->domain->setDirDomain($dirDomain);
|
|
||||||
$dirStorage = $this->moduleFactory->getDirsTreeFactory()->getInfrastructureFactory()->getStorage();
|
|
||||||
$this->domain->setDirStorage($dirStorage);
|
$this->domain->setDirStorage($dirStorage);
|
||||||
|
$dirsPersistLayer = $this->moduleFactory->getInfrastructureFactory()->getDirsPersistLayer();
|
||||||
|
$this->domain->setDirsPersistLayer($dirsPersistLayer);
|
||||||
}
|
}
|
||||||
return $this->domain;
|
return $this->domain;
|
||||||
}
|
}
|
||||||
|
|
@ -93,5 +92,4 @@ class Factory implements IFactory {
|
||||||
}
|
}
|
||||||
return $this->filesBrowser;
|
return $this->filesBrowser;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -5,7 +5,8 @@ namespace Src\Modules\JsonObjects\Application;
|
||||||
use Src\Common\Application\TraitValidator;
|
use Src\Common\Application\TraitValidator;
|
||||||
use Src\Modules\JsonObjects\Interfaces\Application\IValidator;
|
use Src\Modules\JsonObjects\Interfaces\Application\IValidator;
|
||||||
|
|
||||||
class Validator implements IValidator {
|
class Validator implements IValidator
|
||||||
|
{
|
||||||
|
|
||||||
use TraitValidator {
|
use TraitValidator {
|
||||||
getCleanData as baseCleanData;
|
getCleanData as baseCleanData;
|
||||||
|
|
@ -27,9 +28,7 @@ class Validator implements IValidator {
|
||||||
'max:32',
|
'max:32',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
$messages = [
|
$messages = [];
|
||||||
|
|
||||||
];
|
|
||||||
return $this->validate($data, $rules, $messages);
|
return $this->validate($data, $rules, $messages);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -49,9 +48,7 @@ class Validator implements IValidator {
|
||||||
'array',
|
'array',
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
$messages = [
|
$messages = [];
|
||||||
|
|
||||||
];
|
|
||||||
return $this->validate($data, $rules, $messages);
|
return $this->validate($data, $rules, $messages);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -67,9 +64,7 @@ class Validator implements IValidator {
|
||||||
'max:32',
|
'max:32',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
$messages = [
|
$messages = [];
|
||||||
|
|
||||||
];
|
|
||||||
return $this->validate($data, $rules, $messages);
|
return $this->validate($data, $rules, $messages);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -81,8 +76,59 @@ class Validator implements IValidator {
|
||||||
'max:32',
|
'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);
|
return $this->validate($data, $rules, $messages);
|
||||||
}
|
}
|
||||||
|
|
@ -95,5 +141,4 @@ class Validator implements IValidator {
|
||||||
}
|
}
|
||||||
return $cleanData;
|
return $cleanData;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
<?php
|
<?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
|
trait CategoryTrait
|
||||||
{
|
{
|
||||||
|
|
@ -28,7 +28,7 @@ trait CategoryTrait
|
||||||
$this->loadPath($data['path']);
|
$this->loadPath($data['path']);
|
||||||
}
|
}
|
||||||
if (key_exists('parent', $data)) {
|
if (key_exists('parent', $data)) {
|
||||||
$parentData = array_pop($data['parent']);
|
$parentData = array_pop($data['parent']) ?? [];
|
||||||
$this->loadParent($parentData);
|
$this->loadParent($parentData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Src\Lib\CategoriesTree\Dto;
|
namespace Src\Modules\JsonObjects\Dto\Dir;
|
||||||
|
|
||||||
use Src\Lib\CategoriesTree\Interfaces\Dto\IPersist;
|
use Src\Modules\JsonObjects\Interfaces\Dto\Dir\IPersist;
|
||||||
use Src\Lib\CategoriesTree\Interfaces\Dto\IFactory as IDtoFactory;
|
use Src\Modules\JsonObjects\Interfaces\Dto\IFactory as IDtoFactory;
|
||||||
use Src\Lib\CategoriesTree\Interfaces\Dto\IAbstractCategory;
|
use Src\Modules\JsonObjects\Interfaces\Dto\Dir\IAbstractCategory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property IPersist $parent
|
* @property IPersist $parent
|
||||||
|
|
@ -35,7 +35,7 @@ class Persist implements IPersist
|
||||||
{
|
{
|
||||||
$this->path = [];
|
$this->path = [];
|
||||||
foreach ($data as $itemData) {
|
foreach ($data as $itemData) {
|
||||||
$pathItem = $this->dtoFactory->createPersist();
|
$pathItem = $this->dtoFactory->getDirFactory()->createPersist();
|
||||||
$pathItem->load($itemData);
|
$pathItem->load($itemData);
|
||||||
$this->path[] = $pathItem;
|
$this->path[] = $pathItem;
|
||||||
}
|
}
|
||||||
|
|
@ -48,7 +48,7 @@ class Persist implements IPersist
|
||||||
|
|
||||||
public function loadParent(array $data)
|
public function loadParent(array $data)
|
||||||
{
|
{
|
||||||
$this->parent = $this->dtoFactory->createPersist();
|
$this->parent = $this->dtoFactory->getDirFactory()->createPersist();
|
||||||
$this->parent->load($data);
|
$this->parent->load($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Src\Lib\CategoriesTree\Dto;
|
namespace Src\Modules\JsonObjects\Dto\Dir;
|
||||||
|
|
||||||
use Src\Lib\CategoriesTree\Interfaces\Dto\IResource;
|
use Src\Modules\JsonObjects\Interfaces\Dto\Dir\IResource;
|
||||||
use Src\Lib\CategoriesTree\Interfaces\Dto\IFactory as IDtoFactory;
|
use Src\Modules\JsonObjects\Interfaces\Dto\IFactory as IDtoFactory;
|
||||||
use Src\Lib\CategoriesTree\Interfaces\Dto\IAbstractCategory;
|
use Src\Modules\JsonObjects\Interfaces\Dto\Dir\IAbstractCategory;
|
||||||
|
|
||||||
class Resource implements IResource
|
class Resource implements IResource
|
||||||
{
|
{
|
||||||
|
|
@ -35,7 +35,7 @@ class Resource implements IResource
|
||||||
{
|
{
|
||||||
$this->path = [];
|
$this->path = [];
|
||||||
foreach ($data as $item) {
|
foreach ($data as $item) {
|
||||||
$pathItem = $this->dtoFactory->createResource();
|
$pathItem = $this->dtoFactory->getDirFactory()->createResource();
|
||||||
$pathItem->load($item);
|
$pathItem->load($item);
|
||||||
$this->path[] = $pathItem;
|
$this->path[] = $pathItem;
|
||||||
}
|
}
|
||||||
|
|
@ -58,7 +58,10 @@ class Resource implements IResource
|
||||||
|
|
||||||
public function loadParent(array $data)
|
public function loadParent(array $data)
|
||||||
{
|
{
|
||||||
$this->parent = $this->dtoFactory->createResource();
|
if (!$data) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->parent = $this->dtoFactory->getDirFactory()->createResource();
|
||||||
$this->parent->load($data);
|
$this->parent->load($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -6,13 +6,18 @@ use Src\Modules\JsonObjects\Interfaces\Dto\IFactory;
|
||||||
use Src\Modules\JsonObjects\Interfaces\IFactory as IModulesFactory;
|
use Src\Modules\JsonObjects\Interfaces\IFactory as IModulesFactory;
|
||||||
use Src\Modules\JsonObjects\Interfaces\Dto\Item\IFactory as IItemFactory;
|
use Src\Modules\JsonObjects\Interfaces\Dto\Item\IFactory as IItemFactory;
|
||||||
use Src\Modules\JsonObjects\Dto\Item\Factory as ItemFactory;
|
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 IModulesFactory $modulesFactory;
|
||||||
|
|
||||||
protected ?IItemFactory $itemFactory = null;
|
protected ?IItemFactory $itemFactory = null;
|
||||||
|
|
||||||
|
protected ?IDirFactory $dirFactory = null;
|
||||||
|
|
||||||
protected array $conf;
|
protected array $conf;
|
||||||
|
|
||||||
public function init(array $conf = []): void
|
public function init(array $conf = []): void
|
||||||
|
|
@ -21,6 +26,9 @@ class Factory implements IFactory {
|
||||||
'item' => [
|
'item' => [
|
||||||
'factory' => ItemFactory::class,
|
'factory' => ItemFactory::class,
|
||||||
],
|
],
|
||||||
|
'dir' => [
|
||||||
|
'factory' => DirFactory::class,
|
||||||
|
],
|
||||||
];
|
];
|
||||||
$this->conf = array_replace_recursive($this->conf, $conf);
|
$this->conf = array_replace_recursive($this->conf, $conf);
|
||||||
}
|
}
|
||||||
|
|
@ -45,4 +53,13 @@ class Factory implements IFactory {
|
||||||
return $this->itemFactory;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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\Item\IFactory;
|
||||||
use Src\Modules\JsonObjects\Interfaces\Dto\IFactory as IDtoFactory;
|
use Src\Modules\JsonObjects\Interfaces\Dto\IFactory as IDtoFactory;
|
||||||
|
|
||||||
class Factory implements IFactory {
|
class Factory implements IFactory
|
||||||
|
{
|
||||||
|
|
||||||
protected ?IDtoFactory $dtoFactory = null;
|
protected ?IDtoFactory $dtoFactory = null;
|
||||||
|
|
||||||
|
|
@ -41,11 +42,10 @@ class Factory implements IFactory {
|
||||||
public function createResource(): ResourceItem
|
public function createResource(): ResourceItem
|
||||||
{
|
{
|
||||||
$resource = new $this->conf['resourceItem'];
|
$resource = new $this->conf['resourceItem'];
|
||||||
$dirResource = $this->dtoFactory->getModulesFactory()->getDirsTreeFactory()->getDtoFactory()->createResource();
|
$dirResource = $this->dtoFactory->getModulesFactory()->getDtoFactory()->getDirFactory()->createResource();
|
||||||
$resource->setDir($dirResource);
|
$resource->setDir($dirResource);
|
||||||
$objFactory = $this->dtoFactory->getModulesFactory()->getSetting(IModuleFactory::OBJECTS_FACTORY);
|
$objFactory = $this->dtoFactory->getModulesFactory()->getSetting(IModuleFactory::OBJECTS_FACTORY);
|
||||||
$resource->setObjectsFactory($objFactory);
|
$resource->setObjectsFactory($objFactory);
|
||||||
return $resource;
|
return $resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -3,10 +3,11 @@
|
||||||
namespace Src\Modules\JsonObjects\Dto\Item;
|
namespace Src\Modules\JsonObjects\Dto\Item;
|
||||||
|
|
||||||
use Src\Modules\JsonObjects\Interfaces\Dto\Item\IResourceItem;
|
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;
|
use Src\Common\Dto\Object\AbstractComposite;
|
||||||
|
|
||||||
class ResourceItem extends AbstractItem implements IResourceItem {
|
class ResourceItem extends AbstractItem implements IResourceItem
|
||||||
|
{
|
||||||
|
|
||||||
protected IDirResource $dir;
|
protected IDirResource $dir;
|
||||||
|
|
||||||
|
|
@ -65,5 +66,4 @@ class ResourceItem extends AbstractItem implements IResourceItem {
|
||||||
{
|
{
|
||||||
return $this->name;
|
return $this->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -4,7 +4,7 @@ namespace Src\Modules\JsonObjects;
|
||||||
|
|
||||||
use Src\Modules\JsonObjects\Interfaces\IFactory;
|
use Src\Modules\JsonObjects\Interfaces\IFactory;
|
||||||
use Src\Modules\JsonObjects\Interfaces\IModulesProvider;
|
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\Sidebar\Interfaces\IFactory as ISidebarFactory;
|
||||||
use Src\Common\Interfaces\IFactory as ICommonFactory;
|
use Src\Common\Interfaces\IFactory as ICommonFactory;
|
||||||
use Src\Modules\JsonObjects\Interfaces\Dto\IFactory as IDtoFactory;
|
use Src\Modules\JsonObjects\Interfaces\Dto\IFactory as IDtoFactory;
|
||||||
|
|
@ -17,9 +17,10 @@ use Src\Modules\JsonObjects\Interfaces\Application\IFactory as IApplicationFacto
|
||||||
use Src\Modules\JsonObjects\Application\Factory as ApplicationFactory;
|
use Src\Modules\JsonObjects\Application\Factory as ApplicationFactory;
|
||||||
use Src\Common\Dto\Object\Factory as ObjectsFactory;
|
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 ISidebarFactory $sidebarFactory;
|
||||||
|
|
||||||
|
|
@ -73,21 +74,21 @@ class Factory implements IFactory {
|
||||||
return $this->commonFactory;
|
return $this->commonFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setDirsTreeFactory(IDirsTreeFactory $factory)
|
// public function setDirsTreeFactory(IDirsTreeFactory $factory)
|
||||||
{
|
// {
|
||||||
$this->dirsTreeFactory = $factory;
|
// $this->dirsTreeFactory = $factory;
|
||||||
$this->dirsTreeFactory->setSetting(IDirsTreeFactory::TABLE_NAME, $this->settings[self::DIRS_TABLE]);
|
// $this->dirsTreeFactory->setSetting(IDirsTreeFactory::TABLE_NAME, $this->settings[self::DIRS_TABLE]);
|
||||||
}
|
// }
|
||||||
|
|
||||||
public function setObjectsFactory(ObjectsFactory $factory): void
|
public function setObjectsFactory(ObjectsFactory $factory): void
|
||||||
{
|
{
|
||||||
$this->settings[self::OBJECTS_FACTORY] = $factory;
|
$this->settings[self::OBJECTS_FACTORY] = $factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDirsTreeFactory():IDirsTreeFactory
|
// public function getDirsTreeFactory():IDirsTreeFactory
|
||||||
{
|
// {
|
||||||
return $this->dirsTreeFactory;
|
// return $this->dirsTreeFactory;
|
||||||
}
|
// }
|
||||||
|
|
||||||
public function loadSettings(array $settings)
|
public function loadSettings(array $settings)
|
||||||
{
|
{
|
||||||
|
|
@ -143,5 +144,4 @@ class Factory implements IFactory {
|
||||||
}
|
}
|
||||||
return $this->applicationFactory;
|
return $this->applicationFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,12 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Src\Lib\CategoriesTree\Infrastructure;
|
namespace Src\Modules\JsonObjects\Infrastructure;
|
||||||
|
|
||||||
use Src\Lib\CategoriesTree\Interfaces\Infrastructure\IPersistLayer;
|
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IDirsPersistLayer;
|
||||||
use Src\Lib\CategoriesTree\Interfaces\Dto\IPersist;
|
use Src\Modules\JsonObjects\Interfaces\Dto\Dir\IPersist;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
class PersistLayer implements IPersistLayer {
|
class DirsPersistLayer implements IDirsPersistLayer
|
||||||
|
{
|
||||||
|
|
||||||
protected string $tableName;
|
protected string $tableName;
|
||||||
|
|
||||||
|
|
@ -37,5 +38,4 @@ class PersistLayer implements IPersistLayer {
|
||||||
$qb = DB::table($this->tableName);
|
$qb = DB::table($this->tableName);
|
||||||
return $qb->whereIn($this->tableName . '.id', $ids)->delete();
|
return $qb->whereIn($this->tableName . '.id', $ids)->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,13 +4,17 @@ namespace Src\Modules\JsonObjects\Infrastructure;
|
||||||
|
|
||||||
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IFactory;
|
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IFactory;
|
||||||
use Src\Modules\JsonObjects\Interfaces\IFactory as IModuleFactory;
|
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\Infrastructure\ItemQuery;
|
||||||
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemStorage;
|
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemStorage;
|
||||||
use Src\Modules\JsonObjects\Infrastructure\ItemStorage;
|
use Src\Modules\JsonObjects\Infrastructure\ItemStorage;
|
||||||
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemPersistLayer;
|
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemPersistLayer;
|
||||||
use Src\Modules\JsonObjects\Infrastructure\ItemPersistLayer;
|
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
|
class Factory implements IFactory
|
||||||
{
|
{
|
||||||
|
|
@ -21,7 +25,9 @@ class Factory implements IFactory
|
||||||
|
|
||||||
protected ?IItemPersistLayer $persistLayer = null;
|
protected ?IItemPersistLayer $persistLayer = null;
|
||||||
|
|
||||||
protected ?IMigrations $migration = null;
|
protected ?IDirsStorage $dirsStorage = null;
|
||||||
|
|
||||||
|
protected ?IDirsPersistLayer $dirsPersistLayer = null;
|
||||||
|
|
||||||
protected array $conf;
|
protected array $conf;
|
||||||
|
|
||||||
|
|
@ -31,6 +37,9 @@ class Factory implements IFactory
|
||||||
'itemQuery' => ItemQuery::class,
|
'itemQuery' => ItemQuery::class,
|
||||||
'itemStorage' => ItemStorage::class,
|
'itemStorage' => ItemStorage::class,
|
||||||
'itemPersistLayer' => ItemPersistLayer::class,
|
'itemPersistLayer' => ItemPersistLayer::class,
|
||||||
|
'dirsStorage' => DirsStorage::class,
|
||||||
|
'dirsQuery' => DirsQuery::class,
|
||||||
|
'dirPersistLayer' => DirsPersistLayer::class,
|
||||||
];
|
];
|
||||||
$this->conf = array_replace_recursive($this->conf, $conf);
|
$this->conf = array_replace_recursive($this->conf, $conf);
|
||||||
}
|
}
|
||||||
|
|
@ -54,8 +63,8 @@ class Factory implements IFactory
|
||||||
$this->storage = new $this->conf['itemStorage'];
|
$this->storage = new $this->conf['itemStorage'];
|
||||||
$query = $this->createQuery();
|
$query = $this->createQuery();
|
||||||
$this->storage->setObjectsQuery($query);
|
$this->storage->setObjectsQuery($query);
|
||||||
$dirStorage = $this->moduleFactory->getDirsTreeFactory()->getInfrastructureFactory()->getStorage();
|
$dirsStorage = $this->getDirsStorage();
|
||||||
$this->storage->setDirStorage($dirStorage);
|
$this->storage->setDirStorage($dirsStorage);
|
||||||
}
|
}
|
||||||
return $this->storage;
|
return $this->storage;
|
||||||
}
|
}
|
||||||
|
|
@ -69,4 +78,34 @@ class Factory implements IFactory
|
||||||
}
|
}
|
||||||
return $this->persistLayer;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,9 @@ use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemQuery;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Database\Query\Builder;
|
use Illuminate\Database\Query\Builder;
|
||||||
use Src\Common\Infrastructure\TraitSqlQuery;
|
use Src\Common\Infrastructure\TraitSqlQuery;
|
||||||
use hrustbb2\arrayproc\ArrayProcessor;
|
|
||||||
|
|
||||||
class ItemQuery implements IItemQuery {
|
class ItemQuery implements IItemQuery
|
||||||
|
{
|
||||||
|
|
||||||
use TraitSqlQuery {
|
use TraitSqlQuery {
|
||||||
TraitSqlQuery::getSelectSection as baseGetSelectSection;
|
TraitSqlQuery::getSelectSection as baseGetSelectSection;
|
||||||
|
|
@ -18,29 +18,16 @@ class ItemQuery implements IItemQuery {
|
||||||
|
|
||||||
protected Builder $queryBuilder;
|
protected Builder $queryBuilder;
|
||||||
|
|
||||||
protected array $arrayProcConf = [];
|
|
||||||
|
|
||||||
public function setTableName(string $tableName)
|
public function setTableName(string $tableName)
|
||||||
{
|
{
|
||||||
$this->tableName = $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 = [])
|
public function select(array $fields = [])
|
||||||
{
|
{
|
||||||
$this->queryBuilder = DB::table($this->tableName);
|
$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->queryBuilder->select($select);
|
||||||
$this->arrayProcConf = ['prefix' => 'object_'];
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -89,20 +76,17 @@ class ItemQuery implements IItemQuery {
|
||||||
|
|
||||||
public function all(): array
|
public function all(): array
|
||||||
{
|
{
|
||||||
$arrayProc = new ArrayProcessor();
|
$result = [];
|
||||||
// DB::enableQueryLog();
|
foreach ($this->queryBuilder->get()->all() as $row) {
|
||||||
$data = $this->queryBuilder->get()->toArray();
|
$result[$row->id] = $row;
|
||||||
// $log = DB::getQueryLog();
|
}
|
||||||
// dd($log);
|
return json_decode(json_encode($result), true);
|
||||||
return $arrayProc->process($this->arrayProcConf, $data)->resultArray();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function one(): array
|
public function one(): array
|
||||||
{
|
{
|
||||||
$arrayProc = new ArrayProcessor();
|
$result = $this->queryBuilder->first() ?? [];
|
||||||
$data = $this->queryBuilder->get()->toArray();
|
$result = json_decode(json_encode($result), true);
|
||||||
$d = $arrayProc->process($this->arrayProcConf, $data)->resultArray();
|
return $result;
|
||||||
return array_pop($d) ?? [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -4,25 +4,26 @@ namespace Src\Modules\JsonObjects\Infrastructure;
|
||||||
|
|
||||||
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemStorage;
|
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemStorage;
|
||||||
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemQuery;
|
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;
|
use Src\Common\Infrastructure\TraitStorage;
|
||||||
|
|
||||||
class ItemStorage implements IItemStorage {
|
class ItemStorage implements IItemStorage
|
||||||
|
{
|
||||||
|
|
||||||
use TraitStorage;
|
use TraitStorage;
|
||||||
|
|
||||||
protected IItemQuery $objectsQuery;
|
protected IItemQuery $objectsQuery;
|
||||||
|
|
||||||
protected IDirStorage $dirStorage;
|
protected IDirsStorage $dirsStorage;
|
||||||
|
|
||||||
public function setObjectsQuery(IItemQuery $query)
|
public function setObjectsQuery(IItemQuery $query)
|
||||||
{
|
{
|
||||||
$this->objectsQuery = $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
|
||||||
|
|
@ -33,7 +34,7 @@ class ItemStorage implements IItemStorage {
|
||||||
}
|
}
|
||||||
if (key_exists('dir', $dsl)) {
|
if (key_exists('dir', $dsl)) {
|
||||||
$dirId = $itemData['dir_id'];
|
$dirId = $itemData['dir_id'];
|
||||||
$dirData = $this->dirStorage->getById($dirId, $dsl['dir']);
|
$dirData = $this->dirsStorage->getById($dirId, $dsl['dir']);
|
||||||
$itemData['dir'] = [
|
$itemData['dir'] = [
|
||||||
$dirId => $dirData,
|
$dirId => $dirData,
|
||||||
];
|
];
|
||||||
|
|
@ -62,5 +63,4 @@ class ItemStorage implements IItemStorage {
|
||||||
{
|
{
|
||||||
return $this->objectsQuery->select($dsl)->whereDirId($dirId)->all();
|
return $this->objectsQuery->select($dsl)->whereDirId($dirId)->all();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -2,9 +2,11 @@
|
||||||
|
|
||||||
namespace Src\Modules\JsonObjects\Interfaces\Application;
|
namespace Src\Modules\JsonObjects\Interfaces\Application;
|
||||||
|
|
||||||
use Src\Lib\CategoriesTree\Interfaces\Infrastructure\IStorage as IDirStorage;
|
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IDirsStorage;
|
||||||
|
|
||||||
interface IDataBuilder {
|
interface IDataBuilder
|
||||||
public function setDirStorage(IDirStorage $dirStorage):void;
|
{
|
||||||
|
public function setDirStorage(IDirsStorage $dirStorage): void;
|
||||||
public function build(array $data): array;
|
public function build(array $data): array;
|
||||||
|
public function buildDirData(array $requestData): array;
|
||||||
}
|
}
|
||||||
|
|
@ -9,23 +9,26 @@ use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemPersistLayer;
|
||||||
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemStorage;
|
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemStorage;
|
||||||
use Src\Modules\JsonObjects\Interfaces\Dto\Item\IResourceItem;
|
use Src\Modules\JsonObjects\Interfaces\Dto\Item\IResourceItem;
|
||||||
use Src\Modules\JsonObjects\Interfaces\Application\IDataBuilder;
|
use Src\Modules\JsonObjects\Interfaces\Application\IDataBuilder;
|
||||||
use Src\Lib\CategoriesTree\Interfaces\Application\IValidator as IDirValidator;
|
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IDirsStorage;
|
||||||
use Src\Lib\CategoriesTree\Interfaces\Application\IDomain as IDirDomain;
|
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IDirsPersistLayer;
|
||||||
use Src\Lib\CategoriesTree\Interfaces\Infrastructure\IStorage as IDirStorage;
|
use Src\Modules\JsonObjects\Interfaces\Dto\Dir\IResource as IDirResource;
|
||||||
|
|
||||||
interface IDomain extends IBaseDomain {
|
interface IDomain extends IBaseDomain
|
||||||
|
{
|
||||||
public function setValidator(IValidator $validator): void;
|
public function setValidator(IValidator $validator): void;
|
||||||
public function setDtoFactory(IDtoFactory $factory): void;
|
public function setDtoFactory(IDtoFactory $factory): void;
|
||||||
public function setPersistLayer(IItemPersistLayer $layer): void;
|
public function setPersistLayer(IItemPersistLayer $layer): void;
|
||||||
public function setStorage(IItemStorage $storage): void;
|
public function setStorage(IItemStorage $storage): void;
|
||||||
public function setDataBuilder(IDataBuilder $dataBuilder): void;
|
public function setDataBuilder(IDataBuilder $dataBuilder): void;
|
||||||
public function setDirValidator(IDirValidator $validator):void;
|
public function setDirStorage(IDirsStorage $storage): void;
|
||||||
public function setDirDomain(IDirDomain $domain):void;
|
public function setDirsPersistLayer(IDirsPersistLayer $layer): void;
|
||||||
public function setDirStorage(IDirStorage $storage):void;
|
|
||||||
public function createObject(array $data): bool;
|
public function createObject(array $data): bool;
|
||||||
public function editObject(array $data): bool;
|
public function editObject(array $data): bool;
|
||||||
public function renameObject(array $data): bool;
|
public function renameObject(array $data): bool;
|
||||||
public function deleteObject(array $data): bool;
|
public function deleteObject(array $data): bool;
|
||||||
public function deleteDir(array $data): bool;
|
public function deleteDir(array $data): bool;
|
||||||
public function getItem(): IResourceItem;
|
public function getItem(): IResourceItem;
|
||||||
|
public function createDir(array $data): bool;
|
||||||
|
public function renameDir(array $data): bool;
|
||||||
|
public function getDir(): IDirResource;
|
||||||
}
|
}
|
||||||
|
|
@ -4,9 +4,13 @@ namespace Src\Modules\JsonObjects\Interfaces\Application;
|
||||||
|
|
||||||
use Src\Common\Interfaces\Application\IBaseValidator;
|
use Src\Common\Interfaces\Application\IBaseValidator;
|
||||||
|
|
||||||
interface IValidator extends IBaseValidator {
|
interface IValidator extends IBaseValidator
|
||||||
|
{
|
||||||
public function createObject(array $data): bool;
|
public function createObject(array $data): bool;
|
||||||
public function editObject(array $data): bool;
|
public function editObject(array $data): bool;
|
||||||
public function renameObject(array $data): bool;
|
public function renameObject(array $data): bool;
|
||||||
public function deleteObject(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;
|
||||||
}
|
}
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Src\Lib\CategoriesTree\Interfaces\Dto;
|
namespace Src\Modules\JsonObjects\Interfaces\Dto\Dir;
|
||||||
|
|
||||||
interface IAbstractCategory {
|
interface IAbstractCategory
|
||||||
|
{
|
||||||
public function getId();
|
public function getId();
|
||||||
public function load(array $data);
|
public function load(array $data);
|
||||||
public function loadPath(array $data);
|
public function loadPath(array $data);
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
@ -4,10 +4,13 @@ namespace Src\Modules\JsonObjects\Interfaces\Dto;
|
||||||
|
|
||||||
use Src\Modules\JsonObjects\Interfaces\IFactory as IModulesFactory;
|
use Src\Modules\JsonObjects\Interfaces\IFactory as IModulesFactory;
|
||||||
use Src\Modules\JsonObjects\Interfaces\Dto\Item\IFactory as IItemFactory;
|
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 init(array $conf = []): void;
|
||||||
public function setModulesFactory(IModulesFactory $factory);
|
public function setModulesFactory(IModulesFactory $factory);
|
||||||
public function getModulesFactory(): IModulesFactory;
|
public function getModulesFactory(): IModulesFactory;
|
||||||
public function getItemFactory(): IItemFactory;
|
public function getItemFactory(): IItemFactory;
|
||||||
|
public function getDirFactory(): IDirFactory;
|
||||||
}
|
}
|
||||||
|
|
@ -2,10 +2,11 @@
|
||||||
|
|
||||||
namespace Src\Modules\JsonObjects\Interfaces\Dto\Item;
|
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;
|
use Src\Common\Dto\Object\AbstractComposite;
|
||||||
|
|
||||||
interface IResourceItem extends IAbstractItem {
|
interface IResourceItem extends IAbstractItem
|
||||||
|
{
|
||||||
public function setDir(IDirResource $dir): void;
|
public function setDir(IDirResource $dir): void;
|
||||||
public function toArray(array $fields = []): array;
|
public function toArray(array $fields = []): array;
|
||||||
public function getDir(): IDirResource;
|
public function getDir(): IDirResource;
|
||||||
|
|
|
||||||
|
|
@ -5,14 +5,15 @@ namespace Src\Modules\JsonObjects\Interfaces;
|
||||||
use Src\Modules\JsonObjects\Interfaces\IModulesProvider;
|
use Src\Modules\JsonObjects\Interfaces\IModulesProvider;
|
||||||
use Src\Common\Interfaces\IFactory as ICommonFactory;
|
use Src\Common\Interfaces\IFactory as ICommonFactory;
|
||||||
use Src\Sidebar\Interfaces\IFactory as ISidebarFactory;
|
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\Dto\IFactory as IDtoFactory;
|
||||||
use Src\Modules\JsonObjects\Interfaces\Pages\IFactory as IPagesFactory;
|
use Src\Modules\JsonObjects\Interfaces\Pages\IFactory as IPagesFactory;
|
||||||
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IFactory as IInfrastructureFactory;
|
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IFactory as IInfrastructureFactory;
|
||||||
use Src\Modules\JsonObjects\Interfaces\Application\IFactory as IApplicationFactory;
|
use Src\Modules\JsonObjects\Interfaces\Application\IFactory as IApplicationFactory;
|
||||||
use Src\Common\Dto\Object\Factory as ObjectsFactory;
|
use Src\Common\Dto\Object\Factory as ObjectsFactory;
|
||||||
|
|
||||||
interface IFactory {
|
interface IFactory
|
||||||
|
{
|
||||||
|
|
||||||
const DB_HOST = 'db_host';
|
const DB_HOST = 'db_host';
|
||||||
|
|
||||||
|
|
@ -40,8 +41,8 @@ interface IFactory {
|
||||||
public function injectModules(IModulesProvider $provider);
|
public function injectModules(IModulesProvider $provider);
|
||||||
public function getSidebarFactory(): ISidebarFactory;
|
public function getSidebarFactory(): ISidebarFactory;
|
||||||
public function getCommonFactory(): ICommonFactory;
|
public function getCommonFactory(): ICommonFactory;
|
||||||
public function setDirsTreeFactory(IDirsTreeFactory $factory);
|
// public function setDirsTreeFactory(IDirsTreeFactory $factory);
|
||||||
public function getDirsTreeFactory():IDirsTreeFactory;
|
// public function getDirsTreeFactory():IDirsTreeFactory;
|
||||||
public function loadSettings(array $settings);
|
public function loadSettings(array $settings);
|
||||||
public function getSetting(string $key);
|
public function getSetting(string $key);
|
||||||
public function getSettings(): array;
|
public function getSettings(): array;
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Src\Lib\CategoriesTree\Interfaces\Infrastructure;
|
namespace Src\Modules\JsonObjects\Interfaces\Infrastructure;
|
||||||
|
|
||||||
use Src\Common\Interfaces\Infrastructure\IQueryBase;
|
use Src\Common\Interfaces\Infrastructure\IQueryBase;
|
||||||
|
|
||||||
interface IQuery extends IQueryBase {
|
interface IDirsQuery extends IQueryBase
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
|
|
@ -29,9 +30,4 @@ interface IQuery extends IQueryBase {
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function whereInPath(string $matherialPath);
|
public function whereInPath(string $matherialPath);
|
||||||
|
|
||||||
/**
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function withParent(array $fields);
|
|
||||||
}
|
}
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
@ -5,6 +5,9 @@ namespace Src\Modules\JsonObjects\Interfaces\Infrastructure;
|
||||||
use Src\Modules\JsonObjects\Interfaces\IFactory as IModuleFactory;
|
use Src\Modules\JsonObjects\Interfaces\IFactory as IModuleFactory;
|
||||||
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemStorage;
|
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemStorage;
|
||||||
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemPersistLayer;
|
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
|
interface IFactory
|
||||||
{
|
{
|
||||||
|
|
@ -12,4 +15,7 @@ interface IFactory
|
||||||
public function setModuleFactory(IModuleFactory $factory);
|
public function setModuleFactory(IModuleFactory $factory);
|
||||||
public function getStorage(): IItemStorage;
|
public function getStorage(): IItemStorage;
|
||||||
public function getPersistLayer(): IItemPersistLayer;
|
public function getPersistLayer(): IItemPersistLayer;
|
||||||
|
public function createDirsQuery(): IDirsQuery;
|
||||||
|
public function getDirsStorage(): IDirsStorage;
|
||||||
|
public function getDirsPersistLayer(): IDirsPersistLayer;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,12 @@
|
||||||
namespace Src\Modules\JsonObjects\Interfaces\Infrastructure;
|
namespace Src\Modules\JsonObjects\Interfaces\Infrastructure;
|
||||||
|
|
||||||
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemQuery;
|
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 setObjectsQuery(IItemQuery $query);
|
||||||
public function setDirStorage(IDirStorage $storage):void;
|
public function setDirStorage(IDirsStorage $storage): void;
|
||||||
public function getById(string $itemId, array $dsl = []): array;
|
public function getById(string $itemId, array $dsl = []): array;
|
||||||
public function getByIds(array $ids, 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 getByType(string $type, int $limit, int $offset, array $dsl = []): array;
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,13 @@
|
||||||
namespace Src\Modules\JsonObjects\Interfaces\Pages;
|
namespace Src\Modules\JsonObjects\Interfaces\Pages;
|
||||||
|
|
||||||
use Src\Common\Interfaces\Pages\IAbstractPage;
|
use Src\Common\Interfaces\Pages\IAbstractPage;
|
||||||
use Src\Lib\CategoriesTree\Interfaces\Infrastructure\IStorage as IDirsStorage;
|
use Src\Modules\JsonObjects\Interfaces\Dto\Dir\IFactory as IDirsDtoFactory;
|
||||||
use Src\Lib\CategoriesTree\Interfaces\Dto\IFactory as IDirsDtoFactory;
|
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IDirsStorage;
|
||||||
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemStorage;
|
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemStorage;
|
||||||
use Src\Modules\JsonObjects\Interfaces\Dto\Item\IFactory as IItemDtoFactory;
|
use Src\Modules\JsonObjects\Interfaces\Dto\Item\IFactory as IItemDtoFactory;
|
||||||
|
|
||||||
interface IDir extends IAbstractPage {
|
interface IDir extends IAbstractPage
|
||||||
|
{
|
||||||
public function setDirsStorage(IDirsStorage $storage): void;
|
public function setDirsStorage(IDirsStorage $storage): void;
|
||||||
public function setDirsDtoFactory(IDirsDtoFactory $factory): void;
|
public function setDirsDtoFactory(IDirsDtoFactory $factory): void;
|
||||||
public function setItemStorage(IItemStorage $storage): void;
|
public function setItemStorage(IItemStorage $storage): void;
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,8 @@ use Src\Modules\JsonObjects\Interfaces\IFactory as IModuleFactory;
|
||||||
use Illuminate\Support\Facades\View;
|
use Illuminate\Support\Facades\View;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
class DirController extends Controller {
|
class DirController extends Controller
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var IModuleFactory
|
* @var IModuleFactory
|
||||||
|
|
@ -33,7 +34,7 @@ class DirController extends Controller {
|
||||||
|
|
||||||
public function newDir(Request $request)
|
public function newDir(Request $request)
|
||||||
{
|
{
|
||||||
$domain = $this->factory->getDirsTreeFactory()->getApplicationFactory()->getDomain();
|
$domain = $this->factory->getApplicationFactory()->getDomain();
|
||||||
$data = $request->all();
|
$data = $request->all();
|
||||||
$resp = [
|
$resp = [
|
||||||
'success' => $domain->createDir($data),
|
'success' => $domain->createDir($data),
|
||||||
|
|
@ -45,7 +46,7 @@ class DirController extends Controller {
|
||||||
|
|
||||||
public function renameDir(Request $request)
|
public function renameDir(Request $request)
|
||||||
{
|
{
|
||||||
$domain = $this->factory->getDirsTreeFactory()->getApplicationFactory()->getDomain();
|
$domain = $this->factory->getApplicationFactory()->getDomain();
|
||||||
$data = $request->all();
|
$data = $request->all();
|
||||||
$resp = [
|
$resp = [
|
||||||
'success' => $domain->renameDir($data),
|
'success' => $domain->renameDir($data),
|
||||||
|
|
@ -65,5 +66,4 @@ class DirController extends Controller {
|
||||||
];
|
];
|
||||||
return response()->json($resp, $domain->getResponseCode());
|
return response()->json($resp, $domain->getResponseCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -4,9 +4,9 @@ namespace Src\Modules\JsonObjects\Pages;
|
||||||
|
|
||||||
use Src\Common\Pages\Page;
|
use Src\Common\Pages\Page;
|
||||||
use Src\Modules\JsonObjects\Interfaces\Pages\IDir;
|
use Src\Modules\JsonObjects\Interfaces\Pages\IDir;
|
||||||
use Src\Lib\CategoriesTree\Interfaces\Infrastructure\IStorage as IDirsStorage;
|
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IDirsStorage;
|
||||||
use Src\Lib\CategoriesTree\Interfaces\Dto\IFactory as IDirsDtoFactory;
|
use Src\Modules\JsonObjects\Interfaces\Dto\Dir\IFactory as IDirsDtoFactory;
|
||||||
use Src\Lib\CategoriesTree\Interfaces\Dto\IResource as IDirResource;
|
use Src\Modules\JsonObjects\Interfaces\Dto\Dir\IResource as IDirResource;
|
||||||
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemStorage;
|
use Src\Modules\JsonObjects\Interfaces\Infrastructure\IItemStorage;
|
||||||
use Src\Modules\JsonObjects\Interfaces\Dto\Item\IFactory as IItemDtoFactory;
|
use Src\Modules\JsonObjects\Interfaces\Dto\Item\IFactory as IItemDtoFactory;
|
||||||
use Src\Modules\JsonObjects\Interfaces\Dto\Item\IResourceItem;
|
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),
|
'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;
|
return $bc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,9 +33,9 @@ class Factory implements IFactory
|
||||||
$page = new $this->conf['dir'];
|
$page = new $this->conf['dir'];
|
||||||
$sidebarMenu = $this->moduleFactory->getSidebarFactory()->getMenu();
|
$sidebarMenu = $this->moduleFactory->getSidebarFactory()->getMenu();
|
||||||
$page->setSidebar($sidebarMenu);
|
$page->setSidebar($sidebarMenu);
|
||||||
$dirsStorage = $this->moduleFactory->getDirsTreeFactory()->getInfrastructureFactory()->getStorage();
|
$dirsStorage = $this->moduleFactory->getInfrastructureFactory()->getDirsStorage();
|
||||||
$page->setDirsStorage($dirsStorage);
|
$page->setDirsStorage($dirsStorage);
|
||||||
$dirsDtoFactory = $this->moduleFactory->getDirsTreeFactory()->getDtoFactory();
|
$dirsDtoFactory = $this->moduleFactory->getDtoFactory()->getDirFactory();
|
||||||
$page->setDirsDtoFactory($dirsDtoFactory);
|
$page->setDirsDtoFactory($dirsDtoFactory);
|
||||||
$itemStorage = $this->moduleFactory->getInfrastructureFactory()->getStorage();
|
$itemStorage = $this->moduleFactory->getInfrastructureFactory()->getStorage();
|
||||||
$page->setItemStorage($itemStorage);
|
$page->setItemStorage($itemStorage);
|
||||||
|
|
|
||||||
|
|
@ -118,6 +118,10 @@ class Item extends Page implements IItem
|
||||||
'href' => route('admin.jsonObjects.dir', ['dir-id' => $this->item->getDir()->getParent()->getId()], false),
|
'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[] = [
|
$bc[] = [
|
||||||
'title' => $this->item->getName(),
|
'title' => $this->item->getName(),
|
||||||
'href' => route('admin.jsonObjects.editItem', ['item-id' => $this->item->getId()], false),
|
'href' => route('admin.jsonObjects.editItem', ['item-id' => $this->item->getId()], false),
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,8 @@ use Src\Modules\JsonObjects\Interfaces\IModulesProvider as IJSONProvider;
|
||||||
use Src\Modules\JsonObjects\Interfaces\IFactory as IJSONFactory;
|
use Src\Modules\JsonObjects\Interfaces\IFactory as IJSONFactory;
|
||||||
use Src\Modules\JsonObjects\Factory as JSONFactory;
|
use Src\Modules\JsonObjects\Factory as JSONFactory;
|
||||||
|
|
||||||
use Src\Lib\CategoriesTree\Interfaces\IFactory as IDirTreeFactory;
|
// use Src\Lib\CategoriesTree\Interfaces\IFactory as IDirTreeFactory;
|
||||||
use Src\Lib\CategoriesTree\Factory as DirTreeFactory;
|
// use Src\Lib\CategoriesTree\Factory as DirTreeFactory;
|
||||||
|
|
||||||
use Src\Common\Interfaces\Dto\Object\IFactory as IObjFactory;
|
use Src\Common\Interfaces\Dto\Object\IFactory as IObjFactory;
|
||||||
|
|
||||||
|
|
@ -45,17 +45,17 @@ class ModulesProvider implements ICommonProvider, ISidebarProvider, IJSONProvide
|
||||||
'common' => [
|
'common' => [
|
||||||
'factory' => CommonFactory::class,
|
'factory' => CommonFactory::class,
|
||||||
],
|
],
|
||||||
'jsonObjectsDirs' => [
|
// 'jsonObjectsDirs' => [
|
||||||
'factory' => DirTreeFactory::class,
|
// 'factory' => DirTreeFactory::class,
|
||||||
'settings' => [
|
// 'settings' => [
|
||||||
IDirTreeFactory::DB_CHARSET => 'utf8',
|
// IDirTreeFactory::DB_CHARSET => 'utf8',
|
||||||
IDirTreeFactory::DB_HOST => env('DB_HOST'),
|
// IDirTreeFactory::DB_HOST => env('DB_HOST'),
|
||||||
IDirTreeFactory::DB_NAME => env('DB_DATABASE'),
|
// IDirTreeFactory::DB_NAME => env('DB_DATABASE'),
|
||||||
IDirTreeFactory::DB_PASS => env('DB_PASSWORD'),
|
// IDirTreeFactory::DB_PASS => env('DB_PASSWORD'),
|
||||||
IDirTreeFactory::DB_USER => env('DB_USERNAME'),
|
// IDirTreeFactory::DB_USER => env('DB_USERNAME'),
|
||||||
// IDirTreeFactory::TABLE_NAME => $dirsTable,
|
// // IDirTreeFactory::TABLE_NAME => $dirsTable,
|
||||||
],
|
// ],
|
||||||
],
|
// ],
|
||||||
'jsonObjects' => [
|
'jsonObjects' => [
|
||||||
'factory' => JSONFactory::class,
|
'factory' => JSONFactory::class,
|
||||||
'settings' => [
|
'settings' => [
|
||||||
|
|
@ -108,14 +108,14 @@ class ModulesProvider implements ICommonProvider, ISidebarProvider, IJSONProvide
|
||||||
return $this->commonFactory;
|
return $this->commonFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createDirTreeFactory(): DirTreeFactory
|
// protected function createDirTreeFactory(): DirTreeFactory
|
||||||
{
|
// {
|
||||||
$factory = $this->createInstance($this->conf['jsonObjectsDirs']['factory']);
|
// $factory = $this->createInstance($this->conf['jsonObjectsDirs']['factory']);
|
||||||
$factory->loadSettings($this->conf['jsonObjectsDirs']['settings']);
|
// $factory->loadSettings($this->conf['jsonObjectsDirs']['settings']);
|
||||||
$factory->init();
|
// $factory->init();
|
||||||
$factory->setCommonFactory($this->getCommonFactory());
|
// $factory->setCommonFactory($this->getCommonFactory());
|
||||||
return $factory;
|
// return $factory;
|
||||||
}
|
// }
|
||||||
|
|
||||||
public function getJsonObjectsFactory(): JSONFactory
|
public function getJsonObjectsFactory(): JSONFactory
|
||||||
{
|
{
|
||||||
|
|
@ -123,8 +123,8 @@ class ModulesProvider implements ICommonProvider, ISidebarProvider, IJSONProvide
|
||||||
$this->jsonFactory = $this->createInstance($this->conf['jsonObjects']['factory']);
|
$this->jsonFactory = $this->createInstance($this->conf['jsonObjects']['factory']);
|
||||||
$this->jsonFactory->init();
|
$this->jsonFactory->init();
|
||||||
$this->jsonFactory->loadSettings($this->conf['jsonObjects']['settings']);
|
$this->jsonFactory->loadSettings($this->conf['jsonObjects']['settings']);
|
||||||
$dirTreeFactory = $this->createDirTreeFactory();
|
// $dirTreeFactory = $this->createDirTreeFactory();
|
||||||
$this->jsonFactory->setDirsTreeFactory($dirTreeFactory);
|
// $this->jsonFactory->setDirsTreeFactory($dirTreeFactory);
|
||||||
$this->jsonFactory->injectModules($this);
|
$this->jsonFactory->injectModules($this);
|
||||||
}
|
}
|
||||||
return $this->jsonFactory;
|
return $this->jsonFactory;
|
||||||
|
|
|
||||||
|
|
@ -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 |
Loading…
Reference in New Issue