Files
kiri-container/ChangeSet.php
T

158 lines
2.4 KiB
PHP
Raw Normal View History

2026-04-17 16:30:52 +08:00
<?php
declare(strict_types=1);
namespace Kiri\Di;
class ChangeSet
{
2026-06-12 23:57:19 +08:00
/**
* @var array
*/
2026-04-17 16:30:52 +08:00
private array $changedFiles = [];
2026-06-12 23:57:19 +08:00
/**
* @var array
*/
2026-04-17 16:30:52 +08:00
private array $removedFiles = [];
2026-06-12 23:57:19 +08:00
/**
* @var array
*/
2026-04-17 16:30:52 +08:00
private array $changedClasses = [];
2026-06-12 23:57:19 +08:00
/**
* @var array
*/
2026-04-17 16:30:52 +08:00
private array $removedClasses = [];
2026-06-12 23:57:19 +08:00
/**
* @param string $file
* @return void
*/
2026-04-17 16:30:52 +08:00
public function addChangedFile(string $file): void
{
$this->changedFiles[$file] = true;
}
2026-06-12 23:57:19 +08:00
/**
* @param string $file
* @return void
*/
2026-04-17 16:30:52 +08:00
public function addRemovedFile(string $file): void
{
$this->removedFiles[$file] = true;
}
2026-06-12 23:57:19 +08:00
/**
* @param string $class
* @return void
*/
2026-04-17 16:30:52 +08:00
public function addChangedClass(string $class): void
{
$this->changedClasses[$class] = true;
}
2026-06-12 23:57:19 +08:00
/**
* @param string $class
* @return void
*/
2026-04-17 16:30:52 +08:00
public function addRemovedClass(string $class): void
{
$this->removedClasses[$class] = true;
}
2026-06-12 23:57:19 +08:00
/**
* @param ChangeSet $changeSet
* @return $this
*/
2026-04-17 16:30:52 +08:00
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;
}
2026-06-12 23:57:19 +08:00
/**
* @return array
*/
2026-04-17 16:30:52 +08:00
public function getChangedFiles(): array
{
return array_keys($this->changedFiles);
}
2026-06-12 23:57:19 +08:00
/**
* @return array
*/
2026-04-17 16:30:52 +08:00
public function getRemovedFiles(): array
{
return array_keys($this->removedFiles);
}
2026-06-12 23:57:19 +08:00
/**
* @return array
*/
2026-04-17 16:30:52 +08:00
public function getChangedClasses(): array
{
return array_keys($this->changedClasses);
}
2026-06-12 23:57:19 +08:00
/**
* @return array
*/
2026-04-17 16:30:52 +08:00
public function getRemovedClasses(): array
{
return array_keys($this->removedClasses);
}
2026-06-12 23:57:19 +08:00
/**
* @return bool
*/
2026-04-17 16:30:52 +08:00
public function hasChanges(): bool
{
2026-06-12 23:57:19 +08:00
return $this->changedFiles !== [] || $this->removedFiles !== [] || $this->changedClasses !== [] || $this->removedClasses !== [];
2026-04-17 16:30:52 +08:00
}
2026-06-12 23:57:19 +08:00
/**
* @return array
*/
2026-04-17 16:30:52 +08:00
public function toArray(): array
{
return [
2026-06-12 23:57:19 +08:00
'changed_files' => $this->getChangedFiles(),
'removed_files' => $this->getRemovedFiles(),
2026-04-17 16:30:52 +08:00
'changed_classes' => $this->getChangedClasses(),
'removed_classes' => $this->getRemovedClasses(),
];
}
}