Repository navigation
Internals Installer Package PackageMover
Framework Internals · Subsystem overview · Developer guide
Source: awt_src/classes/installer/package/PackageMover.php · Snapshot 8411f4287706.
Installation validates archives and manifests, moves files, persists metadata, copies data into storage, invokes an optional hook and emits an event. These operations do not form one atomic transaction.
use installer\interfaces\package\IPackageMover;
use RuntimeException;class PackageMover implements IPackageMoverDeclarations below preserve visibility, type, default and modifiers exactly. A typed property without an initializer remains uninitialized until its constructor or another method assigns it. Mutable fields belong to this instance unless marked static; readonly fields can be initialized once. Constructor-promoted properties are also listed below.
| Member | Declaration | Purpose or source contract |
|---|---|---|
| $source | private string $source; |
Used by __construct(), move(), getSource(), setSource(), scanDirectory(). |
| $destination | private string $destination; |
Used by __construct(), move(), getDestination(), setDestination(). |
| $scanned | private array $scanned; |
Used by __construct(), move(), scanDirectory(). |
| Constructor-promoted | public function __construct(string $source |
Initialized from the constructor argument; default expression is evaluated when the argument is omitted. |
| Method | Signature |
|---|---|
| __construct | public function __construct(string $source, string $destination) |
| move | public function move(): void |
| getSource | public function getSource(): string |
| getDestination | public function getDestination(): string |
| setSource | public function setSource(string $source): void |
| setDestination | public function setDestination(string $destination): void |
| scanDirectory | private function scanDirectory(string $dir): void |
public function __construct(string $source, string $destination)| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$source |
string $source |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
$destination |
string $destination |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
State writes: $this->source, $this->destination, $this->scanned.
Implementation, validation guards and interaction order
public function __construct(string $source, string $destination)
{
$this->source = $source;
$this->destination = $destination;
$this->scanned = [
"directories" => [],
"files" => []
];
}public function move(): voidState writes: $this->scanned.
Explicit exceptions: RuntimeException. The guards in the implementation below show when each is raised; exceptions from collaborators also propagate unless caught.
External effects include mkdir, rename, rmdir.
Implementation, validation guards and interaction order
/**
* @inheritDoc
*/
public function move(): void
{
if (!is_dir($this->source)) {
throw new RuntimeException("Source directory does not exist: {$this->source}");
}
if (!is_dir($this->destination)) {
throw new RuntimeException("Destination directory does not exist: {$this->destination}");
}
$this->scanned = ['directories' => [], 'files' => []];
$this->scanDirectory($this->source);
foreach ($this->scanned["directories"] as $dir) {
$destDir = $this->destination . DIRECTORY_SEPARATOR . $dir;
if (!is_dir($destDir) && !mkdir($destDir, 0755, true) && !is_dir($destDir)) {
throw new RuntimeException("Failed to create directory: {$destDir}");
}
}
foreach ($this->scanned["files"] as $file) {
$srcFile = $this->source . DIRECTORY_SEPARATOR . $file;
$destFile = $this->destination . DIRECTORY_SEPARATOR . $file;
if (!rename($srcFile, $destFile)) {
throw new RuntimeException("Failed to move file from {$srcFile} to {$destFile}");
}
}
foreach (array_reverse($this->scanned["directories"]) as $dir) {
rmdir($this->source . DIRECTORY_SEPARATOR . $dir);
}
rmdir($this->source);
}public function getSource(): stringReturn expressions (including local callbacks): $this->source.
Implementation, validation guards and interaction order
/**
* @inheritDoc
*/
public function getSource(): string
{
return $this->source;
}public function getDestination(): stringReturn expressions (including local callbacks): $this->destination.
Implementation, validation guards and interaction order
/**
* @inheritDoc
*/
public function getDestination(): string
{
return $this->destination;
}public function setSource(string $source): void| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$source |
string $source |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
State writes: $this->source.
Implementation, validation guards and interaction order
/**
* @inheritDoc
*/
public function setSource(string $source): void
{
$this->source = $source;
}public function setDestination(string $destination): void| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$destination |
string $destination |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
State writes: $this->destination.
Implementation, validation guards and interaction order
/**
* @inheritDoc
*/
public function setDestination(string $destination): void
{
$this->destination = $destination;
}private function scanDirectory(string $dir): void| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$dir |
string $dir |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
State writes: $this->scanned["directories"][], $this->scanned["files"][].
Implementation, validation guards and interaction order
//Helper
private function scanDirectory(string $dir): void
{
$scan = scandir($dir);
unset($scan[0], $scan[1]);
foreach($scan as $entry) {
$fullPath = $dir . DIRECTORY_SEPARATOR . $entry;
$relativePath = substr($fullPath, strlen($this->source) + 1);
if(is_dir($fullPath)) {
$this->scanned["directories"][] = $relativePath;
$this->scanDirectory($fullPath);
} else {
$this->scanned["files"][] = $relativePath;
}
}
}AWT Framework Wiki · Home · Installation Guide · Developer Guide · Framework Internals
Philosophy · Architecture · Known discrepancies · Verification
Installation Guide
Developer Guide
- Learning sequence
- First package
- Package structure
- Lifecycle
- Runtimes
- Events and objects
- Routing and controllers
- Views and resources
- Database and models
- Storage and caching
- Configuration and CLI
- Responses and errors
- Extension points
Framework Internals
- Architecture
- Bootstrap
- Packages
- Runtime
- Events and context
- Objects
- HTTP routing and controllers
- Rendering
- Blade integration
- Database
- Models
- Storage and caching
- Settings
- CLI
- Identity and sessions
- Responses
- Errors
- Complete source inventory
Documentation notes