Beispiel #1
0
 /**
  * Load vendor database from a file
  *
  * @param string $fileName
  */
 public static function loadVendorDatabaseFromFile($fileName)
 {
     $input = new \Library\FileObject($fileName, 'r');
     $input->setFlags(\SplFileObject::DROP_NEW_LINE);
     self::loadVendorDatabase($input);
 }
Beispiel #2
0
 /**
  * Write Package content
  *
  * @param array $data Package data
  * @param string $file Source file
  * @param bool $deleteSource Delete source file
  * @return integer Number of fragments
  */
 public function writeContent($data, $file, $deleteSource)
 {
     $id = $data['Id'];
     $baseName = $this->getPath($id) . "/{$id}-";
     $fileSize = @$data['Size'];
     $maxFragmentSize = @$data['MaxFragmentSize'] * 1024;
     // Kilobytes => Bytes
     if (!$data['FileLocation']) {
         // No file
         $numFragments = 0;
     } elseif ($fileSize == 0 or $maxFragmentSize == 0 or $fileSize <= $maxFragmentSize) {
         // Don't split, just copy/move/rename the file
         if ($deleteSource) {
             \Library\FileObject::rename($file, $baseName . '1');
         } else {
             \Library\FileObject::copy($file, $baseName . '1');
         }
         $numFragments = 1;
     } else {
         // Split file into fragments of nearly identical size no bigger than $maxFragmentSize.
         $fragmentSize = ceil($fileSize / ceil($fileSize / $maxFragmentSize));
         // Determine number of fragments by files actually written
         $numFragments = 0;
         $input = new \Library\FileObject($file, 'rb');
         while ($fragment = $input->fread($fragmentSize)) {
             $numFragments++;
             \Library\FileObject::filePutContents($baseName . $numFragments, $fragment);
         }
         unset($input);
         // Close file before eventually trying to delete it
         if ($deleteSource) {
             \Library\FileObject::unlink($file);
         }
     }
     return $numFragments;
 }
Beispiel #3
0
 /** {@inheritdoc} */
 public function load($locale, $filename)
 {
     $file = new \Library\FileObject($filename);
     $file->setFlags(\SplFileObject::DROP_NEW_LINE | \SplFileObject::READ_AHEAD | \SplFileObject::SKIP_EMPTY);
     $textDomain = new \Zend\I18n\Translator\TextDomain();
     $state = 0;
     // Parser state; 0 := everything else; 1 := msgid; 2 := msgstr
     $msgid = '';
     // current msgid
     $msgstr = '';
     // current msgstr
     $fuzzy = false;
     // TRUE if current message is marked as fuzzy
     $escapeSequences = array('\\\\' => '\\', '\\"' => '"', '\\n' => "\n");
     foreach ($file as $line) {
         if ($state == 0 or $state == 2) {
             if (preg_match('/^msgid\\s(.*)/', $line, $matches)) {
                 // Begin new message. Add last message to result list except
                 // for empty msgid and untranslated messages.
                 if ($msgid != '' and $msgstr != '') {
                     $textDomain[$msgid] = $msgstr;
                 }
                 $line = $matches[1];
                 $state = 1;
                 $msgid = '';
                 $msgstr = '';
             } elseif (preg_match('/^#,.*fuzzy/', $line)) {
                 $fuzzy = true;
             }
         }
         if ($state == 0) {
             continue;
         }
         if ($state == 1) {
             if (preg_match('/^msgstr\\s(.*)/', $line, $matches)) {
                 // msgid complete, begin reading msgstr
                 $line = $matches[1];
                 $state = 2;
                 if ($fuzzy) {
                     // Message is marked as fuzzy, Ignore it.
                     $msgid = '';
                     $fuzzy = false;
                 }
             }
         }
         if (preg_match('/^"(.*)"$/', $line, $matches)) {
             $line = strtr($matches[1], $escapeSequences);
             // Append string to msgid or msgstr, depending on parser state.
             // This supports strings that spans multiple lines.
             if ($state == 1) {
                 $msgid .= $line;
             } else {
                 $msgstr .= $line;
             }
         } else {
             $state = 0;
         }
     }
     // The last entry is not added inside the loop.
     if ($msgid != '' and $msgstr != '') {
         $textDomain[$msgid] = $msgstr;
     }
     return $textDomain;
 }