Skip to content
This repository was archived by the owner on Sep 6, 2023. It is now read-only.

Commit 47bdb4b

Browse files
committed
Add autoload paths in include.php
1 parent 018a47e commit 47bdb4b

File tree

8 files changed

+337
-298
lines changed

8 files changed

+337
-298
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
```php
1010
<?php
11-
use Fred\FishGenerator\ElementFishGenerator;
11+
use GGrach\FishGenerator\ElementFishGenerator;
1212

1313
/**
1414
* В конструктор передаем IBLOCK ID в который нужно сгенерировать тестовый элемент
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?
2+
3+
namespace GGrach\FishGenerator;
4+
5+
/**
6+
* @todo Add https://dummyimage.com/
7+
* @todo https://loremflickr.com/
8+
* @todo https://loremipsum.io/ru/21-of-the-best-placeholder-image-generators/
9+
*/
10+
11+
/**
12+
* Все, что связано с логированием и дебагом
13+
*/
14+
class Debug {
15+
16+
/**
17+
* @var bool При Debug режиме записываются все сгенерированные данные в переменную, при отключенном режиме считается только количество ошибок и успешных выполнений
18+
*/
19+
protected $isDebug = false;
20+
21+
/**
22+
* @var bool При строгом режиме выбрасываются исключения при какой-либо ошибке
23+
*/
24+
protected $isStrictMode = false;
25+
26+
/**
27+
* @var array Результирующие данные
28+
*/
29+
protected $resultData = [
30+
// Количество ошибок
31+
'ERRORS_COUNT' => 0,
32+
// Описание ошибок
33+
'ERRORS' => [],
34+
// Сгенерированные элементы
35+
'GENERATED_DATA' => [],
36+
// Успешно сгенерированных элементов
37+
'SUCCESS_GENERATED' => 0
38+
];
39+
40+
public function addError($dataError) {
41+
$this->resultData['ERRORS_COUNT']++;
42+
43+
if ($this->isDebug)
44+
$this->resultData['ERRORS'][] = $dataError;
45+
}
46+
47+
public function addSuccess($dataSuccess) {
48+
$this->resultData['SUCCESS_GENERATED']++;
49+
50+
if ($this->isDebug)
51+
$this->resultData['GENERATED_DATA'][] = $dataSuccess;
52+
}
53+
54+
public function clearResultData($dataSuccess) {
55+
$this->resultData = [
56+
'ERRORS_COUNT' => 0,
57+
'ERRORS' => [],
58+
'GENERATED_DATA' => [],
59+
'SUCCESS_GENERATED' => 0
60+
];
61+
}
62+
63+
public function getResultData(): array {
64+
if ($this->isDebug)
65+
return $this->resultData;
66+
else {
67+
return [
68+
'ERRORS_COUNT' => $this->resultData['ERRORS_COUNT'],
69+
'SUCCESS_GENERATED' => $this->resultData['SUCCESS_GENERATED']
70+
];
71+
}
72+
}
73+
74+
public function setDebug(bool $valueDebug) {
75+
$this->isDebug = $valueDebug;
76+
return $this;
77+
}
78+
79+
public function setStrictMode(bool $strictMode) {
80+
$this->isStrictMode = $strictMode;
81+
return $this;
82+
}
83+
84+
}

ggrachdev.fish_generator/classes/general/FishGenerator/ElementFishGenerator.php

Lines changed: 0 additions & 258 deletions
This file was deleted.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?
2+
3+
namespace GGrach\FishGenerator\Generators;
4+
5+
use GGrach\FishGenerator\Exceptions\SearchIblockException;
6+
7+
/**
8+
* @version 0.2
9+
* @todo Добавить исключения
10+
*/
11+
class ElementFishGenerator extends ElementGenerator {
12+
13+
/**
14+
* @var array Кеш
15+
*/
16+
public $arCache = [];
17+
18+
/*
19+
* @var int ID Инфоблока в который будет осуществлена генерация
20+
*/
21+
protected $iblockId = null;
22+
23+
/**
24+
*
25+
* @param int $iblockId
26+
* @param string $localization Локализация
27+
* @throws BitrixRedactionException
28+
*/
29+
public function __construct(int $iblockId, string $localization = 'ru_RU') {
30+
31+
if (\CModule::IncludeModule("iblock")) {
32+
$dbRes = \CIBlock::GetByID($iblockId);
33+
if (!$dbRes->GetNext()) {
34+
throw new SearchIblockException('Указаный инфоблок не найден');
35+
}
36+
$this->$dataGenerator = \Faker\Factory::create($localization);
37+
$this->iblockId = $iblockId;
38+
} else {
39+
throw new BitrixRedactionException('Не найдены необходимые для работы библиотеки модули');
40+
}
41+
}
42+
43+
}

0 commit comments

Comments
 (0)