Skip to content

Commit

Permalink
Доработки.
Browse files Browse the repository at this point in the history
  • Loading branch information
ProklUng committed Jul 15, 2021
1 parent f73e835 commit 0574ca3
Showing 1 changed file with 51 additions and 4 deletions.
55 changes: 51 additions & 4 deletions src/CompilerContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace ProklUng\ContainerBoilerplate;

use InvalidArgumentException;
use Proklung\ContainerBoilerplate\Resource\FileBitrixSettingsResource;
use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper;
use Symfony\Component\Config\ConfigCache;
use Symfony\Component\DependencyInjection\Container;
Expand All @@ -27,6 +26,11 @@ class CompilerContainer
*/
private $projectRoot;

/**
* @var string $moduleId ID модуля.
*/
private $moduleId = '';

/**
* CompilerContainer constructor.
*
Expand Down Expand Up @@ -55,7 +59,7 @@ public function isConfigFresh(string $configFile = '/bitrix/.settings.php') : bo

$content = file_get_contents($this->projectRoot . $meta);

/** @var FileBitrixSettingsResource $checker */
/** @var \ProklUng\ContainerBoilerplate\Resource\FileBitrixSettingsResource $checker */
$checker = unserialize($content);
// Кривизна в мета-файле = конфиг потенциально не свежий.
if ($checker === false) {
Expand All @@ -76,7 +80,7 @@ public function isConfigFresh(string $configFile = '/bitrix/.settings.php') : bo
*/
public function createConfigMeta(string $configFile = '/bitrix/.settings.php') : void
{
$checker = new FileBitrixSettingsResource($this->projectRoot . $configFile);
$checker = new \ProklUng\ContainerBoilerplate\Resource\FileBitrixSettingsResource($this->projectRoot . $configFile);

@file_put_contents($this->projectRoot . $configFile . '.meta', serialize($checker));
}
Expand Down Expand Up @@ -122,7 +126,12 @@ public function cacheContainer(

$hasContainerFresh = $containerConfigCache->isFresh();

$configsBag = ['/bitrix/.settings.php', '/bitrix/.settings_extra.php'];
$configsBag = [
'/bitrix/.settings.php',
'/bitrix/.settings_extra.php',
$this->locateModuleDir($this->moduleId).'/.settings.php', // Конфиг модуля
];

foreach ($configsBag as $configFile) {
// Если конфиг-файл изменился - пересобрать дамп контейнера.
if (file_exists($this->projectRoot . $configFile) && !$this->isConfigFresh($configFile)) {
Expand Down Expand Up @@ -305,4 +314,42 @@ private function rrmdir(string $dir) : void
rmdir($dir);
}
}

/**
* Задать ID модуля.
*
* @param string $moduleId
*
* @return CompilerContainer
*/
public function setModuleId(string $moduleId): CompilerContainer
{
$this->moduleId = $moduleId;

return $this;
}

/**
* Определить, где лежит модуль - в local или bitrix.
*
* @param string $moduleId ID модуля.
* @param string $baseFolder Базовая папка.
*
* @return string
*/
private function locateModuleDir(string $moduleId, $baseFolder = '/bitrix/modules') : string
{
$hasLocalDir = is_dir($this->projectRoot . '/local/modules/' . $moduleId);

if ($hasLocalDir && @file_exists($this->projectRoot . '/local/modules/' . $moduleId)) {
return '/local/modules/' . $this->projectRoot;
}
elseif (@file_exists($this->projectRoot. $baseFolder . '/' . $moduleId))
{
return $baseFolder . '/' . $moduleId;
}

return '';
}

}

0 comments on commit 0574ca3

Please sign in to comment.