open($tempPath) !== true) { throw new RuntimeException(sprintf('Failed to open playlist archive: %s', $filePath)); } $isOpen = true; $dataBytes = $zip->getFromName('data'); if ($dataBytes === false) { throw new RuntimeException(sprintf('Missing data entry in playlist archive: %s', $filePath)); } $document = new PlaylistDocument(); $document->mergeFromString($dataBytes); $embeddedFiles = []; for ($i = 0; $i < $zip->numFiles; $i++) { $name = $zip->getNameIndex($i); if ($name === false || $name === 'data') { continue; } $contents = $zip->getFromIndex($i); if ($contents === false) { throw new RuntimeException(sprintf('Unable to read ZIP entry %s: %s', $name, $filePath)); } $embeddedFiles[$name] = $contents; } return new PlaylistArchive($document, $embeddedFiles); } finally { if ($isOpen) { $zip->close(); } @unlink($tempPath); } } }