0 follower

Final Class Yiisoft\YiiDevTool\Infrastructure\Changelog

InheritanceYiisoft\YiiDevTool\Infrastructure\Changelog

Constants

Hide inherited constants

Constant Value Description Defined By
TYPES [ 'Chg', 'Bug', 'New', 'Enh', ] Yiisoft\YiiDevTool\Infrastructure\Changelog

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( string $path )
$path string

                public function __construct(private string $path)
{
}

            
addEntry() public method

public void addEntry ( string $text )
$text string

                public function addEntry(string $text): void
{
    $replaces = $this->replaceInFile(
        '/^(## \d+\.\d+\.\d+ under development\n)\n(?:- no changes in this release\.|- Initial release\.)$/m',
        <<<MARKDOWN
        $1
        - $text
        MARKDOWN,
        $this->path
    );
    if ($replaces === 0) {
        $this->replaceInFile(
            '/^(##\s\d+\.\d+\.\d+\sunder\sdevelopment\n)$/m',
            <<<MARKDOWN
        $1
        - $text
        MARKDOWN,
            $this->path
        );
    }
}

            
close() public method

public void close ( Yiisoft\YiiDevTool\Infrastructure\Version $version )
$version Yiisoft\YiiDevTool\Infrastructure\Version

                public function close(Version $version): void
{
    $this->replaceInFile(
        '/\d+\.\d+\.\d+ under development/',
        $version . ' ' . date('F d, Y'),
        $this->path
    );
}

            
getReleaseLog() public method

public string[] getReleaseLog ( Yiisoft\YiiDevTool\Infrastructure\Version|null $version null )
$version Yiisoft\YiiDevTool\Infrastructure\Version|null

                public function getReleaseLog(?Version $version = null): array
{
    return $this->splitChangelog($version?->asString());
}

            
getReleaseNotes() public method

public string[] getReleaseNotes ( Yiisoft\YiiDevTool\Infrastructure\Version $version )
$version Yiisoft\YiiDevTool\Infrastructure\Version

                public function getReleaseNotes(Version $version): array
{
    [, $changelog] = $this->splitChangelog($version->asString());
    return $changelog;
}

            
open() public method

public void open ( Yiisoft\YiiDevTool\Infrastructure\Version $version )
$version Yiisoft\YiiDevTool\Infrastructure\Version

                public function open(Version $version): void
{
    $headline = "## $version under development\n";
    $headline .= "\n- no changes in this release.\n";
    $lines = explode("\n", file_get_contents($this->path));
    $hl = [
        array_shift($lines),
        array_shift($lines),
    ];
    array_unshift($lines, $headline);
    file_put_contents($this->path, implode("\n", [...$hl, ...$lines]));
}

            
resort() public method

public void resort ( )

                public function resort(): void
{
    // split the file into relevant parts
    [$start, $rawChangelog, $end] = $this->splitChangelog();
    $changelog = [];
    foreach ($rawChangelog as $i => $line) {
        $line = rtrim($line);
        if ($line === '') {
            continue;
        }
        if (preg_match('/^- (New|Chg|Enh|Bug)( #\d+(, #\d+)*)?: .+/', $line, $m)) {
            $o = ['New' => 'C', 'Chg' => 'D', 'Enh' => 'E', 'Bug' => 'F'];
            $key = $o[$m[1]] . ' ' . (!empty($m[2]) ? $m[2] : 'AAAA') . $i;
        } else {
            $key = 'B' . $i;
        }
        $changelog[$key] = $line;
    }
    ksort($changelog);
    file_put_contents($this->path, implode("\n", array_merge($start, $changelog, $end)));
}