Skip to main content
Glama

CTX: Context as Code (CaC) tool

by context-hub
MIT License
235
  • Apple
  • Linux
GithubSourceFactory.php2.77 kB
<?php declare(strict_types=1); namespace Butschster\ContextGenerator\Source\Github; use Butschster\ContextGenerator\Source\Registry\AbstractSourceFactory; use Butschster\ContextGenerator\Source\SourceInterface; /** * Factory for creating GithubSource instances */ final readonly class GithubSourceFactory extends AbstractSourceFactory { #[\Override] public function getType(): string { return 'github'; } #[\Override] public function create(array $config): SourceInterface { $this->logger?->debug('Creating GitHub source', [ 'path' => (string) $this->dirs->getRootPath(), 'config' => $config, ]); if (!isset($config['repository'])) { throw new \RuntimeException('GitHub source must have a "repository" property'); } // Determine source paths (required) if (!isset($config['sourcePaths'])) { throw new \RuntimeException('GitHub source must have a "sourcePaths" property'); } $sourcePaths = $config['sourcePaths']; if (!\is_string($sourcePaths) && !\is_array($sourcePaths)) { throw new \RuntimeException('"sourcePaths" must be a string or array in source'); } // Validate filePattern if present if (isset($config['filePattern'])) { if (!\is_string($config['filePattern']) && !\is_array($config['filePattern'])) { throw new \RuntimeException('filePattern must be a string or an array of strings'); } // If it's an array, make sure all elements are strings if (\is_array($config['filePattern'])) { foreach ($config['filePattern'] as $pattern) { if (!\is_string($pattern)) { throw new \RuntimeException('All elements in filePattern must be strings'); } } } } // Convert notPath to match Symfony Finder's naming convention $notPath = $config['excludePatterns'] ?? $config['notPath'] ?? []; return new GithubSource( repository: $config['repository'], sourcePaths: $sourcePaths, branch: $config['branch'] ?? 'main', description: $config['description'] ?? '', filePattern: $config['filePattern'] ?? '*.*', notPath: $notPath, path: $config['path'] ?? null, contains: $config['contains'] ?? null, notContains: $config['notContains'] ?? null, showTreeView: $config['showTreeView'] ?? true, githubToken: $config['githubToken'] ?? null, modifiers: $config['modifiers'] ?? [], tags: $config['tags'] ?? [], ); } }

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/context-hub/generator'

If you have feedback or need assistance with the MCP directory API, please join our Discord server