*/ private readonly array $manifest; private readonly UserCopySourceCatalog $source; public function __construct(array $manifest) { $this->manifest = UserCopyManifest::validate($manifest); $this->source = new UserCopySourceCatalog($this->manifest); } /** @param array $databaseEntries */ public function assertReady(array $databaseEntries): void { $sourceEntries = $this->source->entries(); if (array_keys($databaseEntries) !== array_keys($sourceEntries)) { throw new UserCopyAdminException( 'Manifest 尚未同步,不能发布。', 409 ); } $manifestByKey = []; foreach ($this->manifest['entries'] as $entry) { $manifestByKey[$entry['key']] = $entry; } foreach ($sourceEntries as $copyKey => $sourceEntry) { $databaseEntry = $databaseEntries[$copyKey]; $placeholderHash = hash( 'sha256', UserCopySourceCatalog::canonicalJson( $manifestByKey[$copyKey]['parameters'] ) ); if (!hash_equals( (string) $databaseEntry->source_hash_zh, hash('sha256', $sourceEntry['source']) ) || !hash_equals( (string) $databaseEntry->placeholder_hash, $placeholderHash ) || (int) $databaseEntry->manifest_revision !== (int) $this->manifest['version']) { throw new UserCopyAdminException( 'Manifest 词条合同尚未同步:' . $copyKey, 409 ); } } } }