Skip to content

Commit

Permalink
Merge pull request #1093 from spiral/hotfix/tokenizer-scopes-config
Browse files Browse the repository at this point in the history
  • Loading branch information
spiralbot committed May 15, 2024
1 parent 911b695 commit 607e4ef
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions src/Bootloader/TokenizerBootloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Spiral\Boot\EnvironmentInterface;
use Spiral\Config\ConfiguratorInterface;
use Spiral\Config\Patch\Append;
use Spiral\Config\Patch\Set;
use Spiral\Core\Attribute\Singleton;
use Spiral\Core\BinderInterface;
use Spiral\Tokenizer\ClassesInterface;
Expand Down Expand Up @@ -93,19 +94,48 @@ public function addDirectory(string $directory): void

/**
* Add directory for indexation into specific scope.
* @param non-empty-string $scope
* @param non-empty-string $directory
*/
public function addScopedDirectory(string $scope, string $directory): void
{
if (!isset($this->config->getConfig(TokenizerConfig::CONFIG)['scopes'][$scope])) {
$this->ensureScopeExists($scope, 'directories');

$this->config->modify(
TokenizerConfig::CONFIG,
new Append('scopes.' . $scope . '.directories', null, $directory),
);
}

/**
* Exclude directory from indexation in specific scope.
* @param non-empty-string $scope
* @param non-empty-string $directory
*/
public function excludeScopedDirectory(string $scope, string $directory): void
{
$this->ensureScopeExists($scope, 'exclude');

$this->config->modify(
TokenizerConfig::CONFIG,
new Append('scopes.' . $scope . '.exclude', null, $directory),
);
}

private function ensureScopeExists(string $scope, string $section): void
{
if (!isset($this->config->getConfig(TokenizerConfig::CONFIG)['scopes'])) {
$this->config->modify(
TokenizerConfig::CONFIG,
new Append('scopes', $scope, []),
new Set('scopes', []),
);
}

$this->config->modify(
TokenizerConfig::CONFIG,
new Append('scopes.' . $scope, null, $directory),
);
if (!isset($this->config->getConfig(TokenizerConfig::CONFIG)['scopes'][$scope])) {
$this->config->modify(
TokenizerConfig::CONFIG,
new Append('scopes', $scope, [$section => []]),
);
}
}
}

0 comments on commit 607e4ef

Please sign in to comment.