Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 1 addition & 36 deletions context.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,44 +26,9 @@ documents:
- '*Interface.php'
showTreeView: true

- description: Project Templates
outputPath: core/templates.md
sources:
- type: file
sourcePaths:
- src/Template
- vendor/spiral/files/src/FilesInterface.php
showTreeView: true

- description: Research Templates
outputPath: core/drafling.md
sources:
- type: file
sourcePaths:
- src/Research/Config
- src/Research/Domain
- src/Research/Repository
- src/Research/Service
- src/Research/Storage/StorageDriverInterface.php

- description: Research FileStorage
outputPath: drafling/file-storage.md
sources:
- type: file
sourcePaths:
- src/Research/Storage

- description: Research MCP
outputPath: drafling/mcp.md
sources:
- type: file
sourcePaths:
- src/Research/MCP
- src/McpServer/McpServerBootloader.php


- description: "Changes in the Project"
outputPath: "changes.md"
sources:
- type: git_diff
commit: unstaged

6 changes: 3 additions & 3 deletions src/Config/Import/ImportResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
use Butschster\ContextGenerator\Config\Import\Merger\ConfigMergerProviderInterface;
use Butschster\ContextGenerator\Config\Import\PathPrefixer\DocumentOutputPathPrefixer;
use Butschster\ContextGenerator\Config\Import\PathPrefixer\SourcePathPrefixer;
use Butschster\ContextGenerator\Config\Import\Source\Config\SourceConfigInterface;
use Butschster\ContextGenerator\Config\Import\Source\Config\SourceConfigFactory;
use Butschster\ContextGenerator\Config\Import\Source\Config\SourceConfigInterface;
use Butschster\ContextGenerator\Config\Import\Source\Exception\ImportSourceException;
use Butschster\ContextGenerator\Config\Import\Source\ImportedConfig;
use Butschster\ContextGenerator\Config\Import\Source\ImportSourceProvider;
Expand All @@ -31,8 +31,8 @@ public function __construct(
private ImportSourceProvider $sourceProvider,
private WildcardPathFinder $pathFinder,
private ConfigMergerProviderInterface $configMergerProvider,
private DocumentOutputPathPrefixer $documentPrefixer = new DocumentOutputPathPrefixer(),
private SourcePathPrefixer $sourcePrefixer = new SourcePathPrefixer(),
private DocumentOutputPathPrefixer $documentPrefixer,
private SourcePathPrefixer $sourcePrefixer,
private SourceConfigFactory $sourceConfigFactory = new SourceConfigFactory(),
private CircularImportDetectorInterface $detector = new CircularImportDetector(),
#[LoggerPrefix(prefix: 'import-resolver')]
Expand Down
7 changes: 7 additions & 0 deletions src/Config/Import/PathPrefixer/PathPrefixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@

namespace Butschster\ContextGenerator\Config\Import\PathPrefixer;

use Butschster\ContextGenerator\Lib\Variable\VariableResolver;

/**
* Abstract base class for path prefix operations
*/
abstract readonly class PathPrefixer
{
public function __construct(
protected VariableResolver $variables,
) {}

/**
* Apply a path prefix to the appropriate paths in a configuration
*/
Expand All @@ -20,6 +26,7 @@ abstract public function applyPrefix(array $config, string $pathPrefix): array;
protected function combinePaths(string $prefix, string $path): string
{
$combined = \rtrim($prefix, '/') . '/' . \ltrim($path, '/');

return $this->normalizePath($combined);
}

Expand Down
3 changes: 3 additions & 0 deletions src/Config/Import/PathPrefixer/SourcePathPrefixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,13 @@ private function applyPathPrefixToSource(array $source, string $prefix): array
private function applyPrefixToPaths(mixed $paths, string $prefix): mixed
{
if (\is_string($paths)) {
$paths = $this->variables->resolve($paths);

// Skip absolute paths
if ($this->isAbsolutePath($paths)) {
return $paths;
}

return $this->combinePaths($prefix, $paths);
}

Expand Down
11 changes: 11 additions & 0 deletions src/Lib/Variable/Provider/PredefinedVariableProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@

namespace Butschster\ContextGenerator\Lib\Variable\Provider;

use Butschster\ContextGenerator\DirectoriesInterface;

/**
* Provider with predefined system variables
*/
final readonly class PredefinedVariableProvider implements VariableProviderInterface
{
public function __construct(
private DirectoriesInterface $dirs,
) {}

public function has(string $name): bool
{
return \array_key_exists($name, $this->getPredefinedVariables());
Expand Down Expand Up @@ -37,6 +43,11 @@ private function getPredefinedVariables(): array
'OS' => PHP_OS,
'HOSTNAME' => \gethostname() ?: 'unknown',
'PWD' => \getcwd() ?: '.',

'ROOT_PATH' => (string) $this->dirs->getRootPath(),
'CONFIG_PATH' => (string) $this->dirs->getConfigPath(),
'ENV_PATH' => (string) $this->dirs->getEnvFilePath(),
'BINARY_PATH' => (string) $this->dirs->getBinaryPath(),
];
}
}
2 changes: 1 addition & 1 deletion src/Lib/Variable/VariableBootloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function defineSingletons(): array
),

// Predefined system variables have lowest priority
new PredefinedVariableProvider(),
new PredefinedVariableProvider(dirs: $dirs),
);
},

Expand Down
5 changes: 3 additions & 2 deletions src/Lib/Variable/VariableReplacementProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
namespace Butschster\ContextGenerator\Lib\Variable;

use Butschster\ContextGenerator\Application\Logger\LoggerPrefix;
use Butschster\ContextGenerator\Lib\Variable\Provider\PredefinedVariableProvider;
use Butschster\ContextGenerator\Lib\Variable\Provider\VariableProviderInterface;
use Psr\Log\LoggerInterface;
use Spiral\Core\Attribute\Proxy;

/**
* Processor that replaces variable references in text
*/
final readonly class VariableReplacementProcessor implements VariableReplacementProcessorInterface
{
public function __construct(
private VariableProviderInterface $provider = new PredefinedVariableProvider(),
#[Proxy]
private VariableProviderInterface $provider,
#[LoggerPrefix(prefix: 'variable-replacement')]
private ?LoggerInterface $logger = null,
) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Tests\Feature\Console\GenerateCommand;

use PHPUnit\Framework\TestCase;
use Tests\TestCase;

/**
* Wrapper for generate command result assertions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Tests\Feature\Console\GenerateCommand;

use PHPUnit\Framework\TestCase;
use Tests\TestCase;

/**
* Trait providing tool assertion methods for CompilingResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Butschster\ContextGenerator\Research\Storage\FileStorage\DirectoryScanner;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Tests\TestCase;
use Spiral\Exceptions\ExceptionReporterInterface;
use Spiral\Files\Files;

Expand Down Expand Up @@ -245,6 +245,7 @@ public function report(\Throwable $exception): void
$this->scanner = new DirectoryScanner($files, $reporter);
}

#[\Override]
protected function tearDown(): void
{
// Clean up temp directory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Butschster\ContextGenerator\Research\Storage\FileStorage\FrontmatterParser;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Tests\TestCase;

final class FrontmatterParserTest extends TestCase
{
Expand Down
6 changes: 6 additions & 0 deletions tests/src/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Tests;

use Butschster\ContextGenerator\Directories;
use Butschster\ContextGenerator\DirectoriesInterface;
use PHPUnit\Framework\TestCase as BaseTestCase;

/**
Expand All @@ -26,6 +27,11 @@ abstract class TestCase extends BaseTestCase
*/
private array $tempDirs = [];

public function getDirs(): DirectoriesInterface
{
return $this->createDirectories();
}

/**
* Clean up temporary files and directories
*/
Expand Down
3 changes: 2 additions & 1 deletion tests/src/Unit/Application/FSPathLinuxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Tests\TestCase;

#[CoversClass(FSPath::class)]
final class FSPathLinuxTest extends TestCase
Expand Down Expand Up @@ -265,6 +265,7 @@ protected function setUp(): void
}
}

#[\Override]
protected function tearDown(): void
{
// Reset directory separator if it was overridden
Expand Down
3 changes: 2 additions & 1 deletion tests/src/Unit/Application/FSPathMixedSlashTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Tests\TestCase;

#[CoversClass(FSPath::class)]
final class FSPathMixedSlashTest extends TestCase
Expand Down Expand Up @@ -220,6 +220,7 @@ public function it_should_normalize_path_with_many_mixed_slashes(): void
$this->assertSame('C:/Users/test/documents/file.txt', $path->toString());
}

#[\Override]
protected function tearDown(): void
{
// Always reset directory separator at the end of each test
Expand Down
3 changes: 2 additions & 1 deletion tests/src/Unit/Application/FSPathWindowsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Tests\TestCase;

#[CoversClass(FSPath::class)]
final class FSPathWindowsTest extends TestCase
Expand Down Expand Up @@ -218,6 +218,7 @@ protected function setUp(): void
}
}

#[\Override]
protected function tearDown(): void
{
// Reset directory separator if it was overridden
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Unit/Fetcher/FileSourceFetcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Butschster\ContextGenerator\Source\File\FileSourceFetcher;
use Butschster\ContextGenerator\Source\SourceInterface;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Tests\TestCase;

class FileSourceFetcherTest extends TestCase
{
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Unit/Fetcher/FileTreeBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Butschster\ContextGenerator\Lib\TreeBuilder\FileTreeBuilder;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Tests\TestCase;

class FileTreeBuilderTest extends TestCase
{
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Unit/Fetcher/TextSourceFetcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Butschster\ContextGenerator\Source\Text\TextSource;
use Butschster\ContextGenerator\Source\Text\TextSourceFetcher;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Tests\TestCase;

class TextSourceFetcherTest extends TestCase
{
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Unit/Lib/Html/HtmlCleanerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Butschster\ContextGenerator\Lib\Html\HtmlCleaner;
use League\HTMLToMarkdown\HtmlConverter;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Tests\TestCase;

class HtmlCleanerTest extends TestCase
{
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Unit/Lib/TreeBuilder/DirectorySorterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Butschster\ContextGenerator\Lib\TreeBuilder\DirectorySorter;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Tests\TestCase;

#[CoversClass(DirectorySorter::class)]
final class DirectorySorterTest extends TestCase
Expand Down
3 changes: 2 additions & 1 deletion tests/src/Unit/Lib/TreeBuilder/FileTreeBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Butschster\ContextGenerator\Lib\TreeBuilder\TreeRendererInterface;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Tests\TestCase;

#[CoversClass(FileTreeBuilder::class)]
final class FileTreeBuilderTest extends TestCase
Expand Down Expand Up @@ -261,6 +261,7 @@ protected function setUp(): void
\file_put_contents($this->tempDir . '/dir2/subdir/file4.txt', 'content');
}

#[\Override]
protected function tearDown(): void
{
$this->removeDirectory($this->tempDir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Butschster\ContextGenerator\Lib\Variable\Provider\VariableProviderInterface;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Tests\TestCase;

#[CoversClass(CompositeVariableProvider::class)]
class CompositeVariableProviderTest extends TestCase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Dotenv\Repository\RepositoryInterface;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Tests\TestCase;

#[CoversClass(DotEnvVariableProvider::class)]
class DotEnvVariableProviderTest extends TestCase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Butschster\ContextGenerator\Lib\Variable\Provider\PredefinedVariableProvider;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Tests\TestCase;

#[CoversClass(PredefinedVariableProvider::class)]
class PredefinedVariableProviderTest extends TestCase
Expand Down Expand Up @@ -83,6 +83,6 @@ public function it_should_return_temp_directory(): void

protected function setUp(): void
{
$this->provider = new PredefinedVariableProvider();
$this->provider = new PredefinedVariableProvider(dirs: $this->getDirs());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Tests\TestCase;
use Psr\Log\LoggerInterface;

#[CoversClass(VariableReplacementProcessor::class)]
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Unit/Lib/Variable/VariableResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Butschster\ContextGenerator\Lib\Variable\VariableResolver;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Tests\TestCase;

#[CoversClass(VariableResolver::class)]
class VariableResolverTest extends TestCase
Expand Down
Loading
Loading