/** * Validate the zip package * * @param string $source Zip package location to validate * @return bool * @throws PortableElementException * @throws PortableElementParserException * @throws PortableElementInconsistencyModelException */ public function validate($source) { try { $this->assertSourceAsFile($source); if (!QtiPackage::isValidZip($source)) { throw new PortableElementParserException('Source package is not a valid zip.'); } } catch (common_Exception $e) { throw new PortableElementParserException('A problem has occured during package parsing.', 0, $e); } $zip = new ZipArchive(); $zip->open($source, ZIPARCHIVE::CHECKCONS); $definitionFiles = $this->getModel()->getDefinitionFiles(); foreach ($definitionFiles as $file) { if ($zip->locateName($file) === false) { throw new PortableElementParserException('A portable element package must contains a "' . $file . '" file at the root of the archive.'); } } $zip->close(); $this->getModel()->createDataObject($this->getManifestContent($source)); return true; }
/** * Validate the zip package * * @access public * @param string schema * @return boolean */ public function validate($schema = '') { $this->valid = false; try { if (QtiPackage::isValidZip($this->source)) { $zip = new ZipArchive(); $zip->open($this->source, ZIPARCHIVE::CHECKCONS); if ($zip->locateName("pciCreator.json") === false) { throw new common_Exception("A PCI creator package must contains a pciCreator.json file at the root of the archive"); } else { if ($zip->locateName("pciCreator.js") === false) { throw new common_Exception("A PCI creator package must contains a pciCreator.js file at the root of the archive"); } else { //check manifest format : $manifest = $this->getManifest(); $this->valid = $this->validateManifest($manifest); } } $zip->close(); } } catch (common_Exception $e) { $this->addError($e); } }