Files
2026-06-12 23:57:19 +08:00

158 lines
2.4 KiB
PHP

<?php
declare(strict_types=1);
namespace Kiri\Di;
class ChangeSet
{
/**
* @var array
*/
private array $changedFiles = [];
/**
* @var array
*/
private array $removedFiles = [];
/**
* @var array
*/
private array $changedClasses = [];
/**
* @var array
*/
private array $removedClasses = [];
/**
* @param string $file
* @return void
*/
public function addChangedFile(string $file): void
{
$this->changedFiles[$file] = true;
}
/**
* @param string $file
* @return void
*/
public function addRemovedFile(string $file): void
{
$this->removedFiles[$file] = true;
}
/**
* @param string $class
* @return void
*/
public function addChangedClass(string $class): void
{
$this->changedClasses[$class] = true;
}
/**
* @param string $class
* @return void
*/
public function addRemovedClass(string $class): void
{
$this->removedClasses[$class] = true;
}
/**
* @param ChangeSet $changeSet
* @return $this
*/
public function merge(ChangeSet $changeSet): self
{
foreach ($changeSet->getChangedFiles() as $file) {
$this->addChangedFile($file);
}
foreach ($changeSet->getRemovedFiles() as $file) {
$this->addRemovedFile($file);
}
foreach ($changeSet->getChangedClasses() as $class) {
$this->addChangedClass($class);
}
foreach ($changeSet->getRemovedClasses() as $class) {
$this->addRemovedClass($class);
}
return $this;
}
/**
* @return array
*/
public function getChangedFiles(): array
{
return array_keys($this->changedFiles);
}
/**
* @return array
*/
public function getRemovedFiles(): array
{
return array_keys($this->removedFiles);
}
/**
* @return array
*/
public function getChangedClasses(): array
{
return array_keys($this->changedClasses);
}
/**
* @return array
*/
public function getRemovedClasses(): array
{
return array_keys($this->removedClasses);
}
/**
* @return bool
*/
public function hasChanges(): bool
{
return $this->changedFiles !== [] || $this->removedFiles !== [] || $this->changedClasses !== [] || $this->removedClasses !== [];
}
/**
* @return array
*/
public function toArray(): array
{
return [
'changed_files' => $this->getChangedFiles(),
'removed_files' => $this->getRemovedFiles(),
'changed_classes' => $this->getChangedClasses(),
'removed_classes' => $this->getRemovedClasses(),
];
}
}