99 lines
2.1 KiB
PHP
99 lines
2.1 KiB
PHP
<?php
|
|
/**
|
|
* Immutable sync package value object.
|
|
*
|
|
* @package WPContentSync
|
|
*/
|
|
|
|
namespace WPContentSync\Package;
|
|
|
|
final class ContentPackage {
|
|
public const SCHEMA_VERSION = '1.0';
|
|
|
|
/** @var array<string, mixed> */
|
|
private array $data;
|
|
|
|
/**
|
|
* @param array<string, mixed> $data Package data.
|
|
*/
|
|
private function __construct( array $data ) {
|
|
$this->data = $data;
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $data Package data.
|
|
*/
|
|
public static function fromArray( array $data ): self {
|
|
return new self(
|
|
array(
|
|
'schema_version' => (string) ( $data['schema_version'] ?? self::SCHEMA_VERSION ),
|
|
'generated_at' => (string) ( $data['generated_at'] ?? '' ),
|
|
'source' => self::arrayValue( $data['source'] ?? array() ),
|
|
'destination' => self::arrayValue( $data['destination'] ?? array() ),
|
|
'manifest' => self::arrayValue( $data['manifest'] ?? array() ),
|
|
'records' => self::arrayValue( $data['records'] ?? array() ),
|
|
'checksums' => self::arrayValue( $data['checksums'] ?? array() ),
|
|
)
|
|
);
|
|
}
|
|
|
|
public function schemaVersion(): string {
|
|
return $this->data['schema_version'];
|
|
}
|
|
|
|
public function generatedAt(): string {
|
|
return $this->data['generated_at'];
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function source(): array {
|
|
return $this->data['source'];
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function destination(): array {
|
|
return $this->data['destination'];
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function manifest(): array {
|
|
return $this->data['manifest'];
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function records(): array {
|
|
return $this->data['records'];
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function checksums(): array {
|
|
return $this->data['checksums'];
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(): array {
|
|
return $this->data;
|
|
}
|
|
|
|
/**
|
|
* @param mixed $value Value to normalize.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
private static function arrayValue( $value ): array {
|
|
return is_array( $value ) ? $value : array();
|
|
}
|
|
}
|