/**
  * Given FileXml from a QPM package definition, this will return a valid QFileInManifest object for that XML element
  * @param SimpleXMLElement $objFileXml
  * @param QDirectoryToken[] $objDirectoryTokenArray
  * @return QFileInManifest
  */
 public static function LoadFromQpmXml(SimpleXMLElement $objFileXml, $objDirectoryTokenArray)
 {
     $objFile = new QFileInManifest();
     $objFile->DirectoryToken = (string) $objFileXml['directoryToken'];
     $objFile->Path = (string) $objFileXml['path'];
     $objFile->Md5 = (string) $objFileXml['md5'];
     if (array_key_exists($objFile->DirectoryToken, $objDirectoryTokenArray)) {
         $objFile->DirectoryTokenObject = $objDirectoryTokenArray[$objFile->DirectoryToken];
     } else {
         return null;
     }
     if (is_file($objFile->GetFullPath())) {
         $objFile->RealPath = realpath($objFile->GetFullPath());
     }
     $objFile->Base64Data = (string) $objFileXml;
     return $objFile;
 }
 protected function SetupFileArray()
 {
     $this->objFileArrayByRealPath = array();
     foreach ($this->objManifestXml->files->file as $objFileXml) {
         $objFileInManifest = new QFileInManifest();
         $objFileInManifest->DirectoryToken = (string) $objFileXml['directoryToken'];
         $objFileInManifest->Path = (string) $objFileXml['path'];
         $objFileInManifest->Md5 = (string) $objFileXml['md5'];
         $objFileInManifest->DirectoryTokenObject = $this->objDirectoryArray[$objFileInManifest->DirectoryToken];
         // Make sure this is valid and in-use DirectoryToken and that this file exists
         if (constant($objFileInManifest->DirectoryTokenObject->Token) && file_exists($objFileInManifest->GetFullPath())) {
             $objFileInManifest->RealPath = realpath($objFileInManifest->GetFullPath());
             if ($objFileInManifest->RealPath) {
                 $this->objFileArrayByRealPath[$objFileInManifest->RealPath] = $objFileInManifest;
             }
         }
     }
 }
 /**
  * Analyzes a FileXml from a QPM Manifest we are downloading to see what "category" it belongs to
  * (e.g. is it a new file to be installed, or is it going to auto-overwrite an existing file in the filesystem,
  * or is it going to have to modify and already-modified file in the filesystem)
  * @param SimpleXMLElement $objFileXml
  * @return string error message (if any) or null if none
  */
 protected function AnalyzeFile(SimpleXMLElement $objFileXml)
 {
     $objFile = QFileInManifest::LoadFromQpmXml($objFileXml, $this->objDirectoryArray);
     // Is the DirectoryToken valid?
     if (!$objFile) {
         return 'directory token not defined in configuration.inc.php: ' . (string) $objFileXml['directoryToken'];
     }
     // Does this file currently exist in the filesystem?
     // Yep
     if ($objFile->RealPath) {
         // Does this file match the version with that in the QPM -- if so, add it to the "overwrite" array
         if ($objFile->IsMd5MatchWithFilesystem()) {
             $this->objOverwriteFileArray[] = $objFile;
             // Or does the file match the version with that in the Manifest (if applicable) -- if so, add it to the "overwrite" array
         } else {
             if (array_key_exists($objFile->RealPath, $this->objFileArrayByRealPath) && $this->objFileArrayByRealPath[$objFile->RealPath]->IsMd5MatchWithFilesystem()) {
                 $this->objOverwriteFileArray[] = $objFile;
                 // Otherwise, it doesn't match anything -- therefore, we will be modifying the local copy
             } else {
                 $this->objModifiedFileArray[] = $objFile;
             }
         }
         // Nope -- it's a new file
     } else {
         $this->objNewFileArray[] = $objFile;
     }
 }