コード例 #1
0
 /**
  * Data preparer.
  *
  * Returns pairs of TokenReflection\Broker where one parses a directory of given type
  * and the second one parses a PHAR archive that was created from the same directory.
  *
  * @param integer $format Archive format
  * @param integer $compression Archive compression
  * @param boolean $wholeArchive Use compression for the whole archive
  * @return array
  */
 private function prepareData($format = Phar::PHAR, $compression = Phar::NONE, $wholeArchive = true)
 {
     $dirName = $this->prepareTemporaryStorage();
     $directory = realpath(__DIR__ . '/../data/');
     $iterator = new \DirectoryIterator($directory);
     static $skip = array('broker' => true, 'parseerror' => true, 'duplicities' => true);
     $data = array();
     foreach ($iterator as $item) {
         if (isset($skip[$item->getFileName()])) {
             continue;
         }
         if ($item->isDir() && !$item->isDot()) {
             $ext = '.phar';
             $fileName = $dirName . DIRECTORY_SEPARATOR . uniqid($format . $compression);
             $phar = new Phar($fileName . $ext);
             $phar->buildFromDirectory($item->getPathName());
             if ($format !== Phar::PHAR) {
                 if ($format === Phar::TAR) {
                     $ext .= '.tar';
                 } elseif ($format === Phar::ZIP) {
                     $ext .= '.zip';
                 }
                 $phar->convertToExecutable($format, $wholeArchive ? $compression : Phar::NONE, $ext);
             }
             if ($compression !== Phar::NONE && !$wholeArchive) {
                 $phar->compressFiles($compression);
             }
             unset($phar);
             $dataItem = array(array('format' => $format, 'compression' => $compression, 'wholeArchive' => $wholeArchive));
             $broker = new Broker(new Broker\Backend\Memory(), 0);
             $broker->processDirectory($item->getPathName());
             $dataItem[] = $broker;
             $broker2 = new Broker(new Broker\Backend\Memory(), 0);
             $broker2->process($fileName . $ext);
             $dataItem[] = $broker2;
             $data[] = $dataItem;
         }
     }
     $this->cleanUpTemporaryStorage($dirName);
     return $data;
 }