Skip to content
This repository has been archived by the owner on Dec 3, 2023. It is now read-only.

Commit

Permalink
Prototype to convert comments
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed Nov 25, 2022
1 parent 5520d5c commit f4206ea
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/config-transformer/src/ConfigLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ final class ConfigLoader
*/
private const UNQUOTED_PARAMETER_REGEX = '#(\w+:\s+)(\%(.*?)%)(.*?)?$#m';

/**
* @see https://regex101.com/r/I2wiC9/2
* @var string
*/
private const COMMENT_REGEX = '#^(\s+)?\# (.*)#m';

public function __construct(
private IdAwareXmlFileLoaderFactory $idAwareXmlFileLoaderFactory,
private SmartFileSystem $smartFileSystem,
Expand All @@ -64,6 +70,13 @@ public function createAndLoadContainerBuilderFromFileInfo(
static fn (array $match): string => $match[1] . '"' . $match[2] . ($match[4] ?? '') . '"'
);

// fake comment to keep them
$content = Strings::replace(
$content,
self::COMMENT_REGEX,
static fn ($match): string => $match[1] . '"%comment(' . $match[2] . ')%": null'
);

if (in_array($smartFileInfo->getSuffix(), [Format::YML, Format::YAML], true)) {
$content = Strings::replace(
$content,
Expand Down

0 comments on commit f4206ea

Please sign in to comment.