コード例 #1
0
ファイル: Validator.php プロジェクト: soneritics/realworks
 /**
  * Validate the object.
  * @return boolean
  */
 public function isValid()
 {
     # File exists
     if (!file_exists($this->zippedContent->getFilename())) {
         return false;
     }
     # Can open zip file
     $zip = new \ZipArchive();
     if ($zip->open($this->zippedContent->getFilename()) !== true) {
         return false;
     }
     # Check if an XML and XSD file are present
     $xmlFile = false;
     $xsdFile = false;
     for ($i = 0; $i < $zip->numFiles; $i++) {
         $filename = $zip->getNameIndex($i);
         $file = new File($filename);
         $extension = strtolower($file->getExtension());
         if ($extension === 'xml') {
             $xmlFile = true;
         } elseif ($extension === 'xsd') {
             $xsdFile = true;
         }
     }
     $zip->close();
     return $xmlFile && $xsdFile;
 }
コード例 #2
0
ファイル: Unpacker.php プロジェクト: soneritics/realworks
 /**
  * Unpack the zip file.
  * @return array of Realworks\File\File objects
  * @throws CanNotOpenZipFile
  */
 public function unpack()
 {
     $result = [];
     $zip = new \ZipArchive();
     if ($zip->open($this->zippedContent->getFilename()) !== true) {
         throw new CanNotOpenZipFile("Can not open zip file: {$this->zippedContent->getFilename()}");
     }
     $zip->extractTo($this->directory);
     $zip->close();
     foreach (scandir($this->directory) as $extractedFileName) {
         $fullFilename = $this->directory . $extractedFileName;
         if (!is_dir($fullFilename)) {
             $file = new File($fullFilename);
             $extension = strtolower($file->getExtension());
             switch ($extension) {
                 case 'xml':
                     $result[] = new XMLFile($fullFilename);
                     break;
                 case 'xsd':
                     $result[] = new XSDFile($fullFilename);
                     break;
                 default:
                     $result[] = $file;
             }
         }
     }
     return $result;
 }