This commit is contained in:
2026-06-12 23:57:19 +08:00
parent 0ff2cd7a06
commit 7827b8d5b1
6 changed files with 147 additions and 116 deletions
+68 -6
View File
@@ -6,34 +6,75 @@ 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) {
@@ -55,39 +96,60 @@ class ChangeSet
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 $this->changedFiles !== [] || $this->removedFiles !== [] || $this->changedClasses !== [] || $this->removedClasses !== [];
}
/**
* @return array
*/
public function toArray(): array
{
return [
'changed_files' => $this->getChangedFiles(),
'removed_files' => $this->getRemovedFiles(),
'changed_files' => $this->getChangedFiles(),
'removed_files' => $this->getRemovedFiles(),
'changed_classes' => $this->getChangedClasses(),
'removed_classes' => $this->getRemovedClasses(),
];