Skip to content

Commit 94f222f

Browse files
Исправление ошибки
Учтена несовместимость с модулем sprint.migration; Добавлена возможность исключать произвольные namespace;
1 parent f791aec commit 94f222f

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

README.md

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

99
`composer require webarchitect609/bitrix-neverinclude`
1010

11-
2 В init.php после подключения `vendor/autoload.php` добавьте вызов:
11+
2 Если необходимо, то в init.php укажите список namespace, для которых не следует применять автоматическое подключение модуля:
12+
13+
`\WebArch\BitrixNeverInclude\BitrixNeverInclude::addExcluded(['Foo\\Bar',]);`
14+
15+
Сейчас известна несовместимость с модулем 'sprint.migration', поэтому его namespace исключается автоматически.
16+
17+
3 В init.php после подключения `vendor/autoload.php` добавьте вызов:
1218

1319
`\WebArch\BitrixNeverInclude\BitrixNeverInclude::registerModuleAutoload();`
1420

src/main/BitrixNeverInclude.php

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,28 @@ class BitrixNeverInclude
1313
*/
1414
const CACHE_TAG = 'BitrixNeverInclude';
1515

16+
/**
17+
* @var string[]
18+
*/
19+
protected static $excludedNamespaces = [
20+
//С этим модулем пакет заведомо несовместим
21+
'Sprint\Migration',
22+
];
23+
24+
/**
25+
* Установить список игнорируемых namespace
26+
*
27+
* @param array $namespaces
28+
*/
29+
public static function addExcluded(array $namespaces)
30+
{
31+
foreach ($namespaces as $namespace) {
32+
if (trim($namespace) != '') {
33+
self::$excludedNamespaces[] = trim($namespace);
34+
}
35+
}
36+
}
37+
1638
/**
1739
* Зарегистрировать автолоадер модулей Битрикс
1840
* и **НАВСЕГДА ЗАБЫТЬ** про CModule::IncludeModule и Loader::includeModule
@@ -54,6 +76,10 @@ public static function getClassMapping()
5476
*/
5577
protected function autoloadModule($class)
5678
{
79+
if ($this->isExcluded($class)) {
80+
return;
81+
}
82+
5783
$moduleName = $this->recognizeOldModule($class);
5884

5985
if (!$moduleName) {
@@ -64,9 +90,9 @@ protected function autoloadModule($class)
6490
return;
6591
}
6692

67-
Loader::includeModule($moduleName);
68-
Loader::autoLoad($class);
69-
93+
if (Loader::includeModule($moduleName)){
94+
Loader::autoLoad($class);
95+
}
7096
}
7197

7298
/**
@@ -130,4 +156,22 @@ protected function recognizeNewModule($class)
130156

131157
return '';
132158
}
159+
160+
/**
161+
* Производит проверку, что класс относится к списку исключённых из автолоадинга
162+
*
163+
* @param $class
164+
*
165+
* @return bool
166+
*/
167+
private function isExcluded($class)
168+
{
169+
foreach (self::$excludedNamespaces as $namespace) {
170+
if (strpos($class, $namespace) === 0) {
171+
return true;
172+
}
173+
}
174+
175+
return false;
176+
}
133177
}

0 commit comments

Comments
 (0)