/**
  * Builds a package
  *
  * @param	integer		$source			id or instance of a source
  * @param	PackageReader	$package		required and optional packages
  * @param	string		$directory		source directory
  * @param	string		$filename		the filename
  * @param	mixed		$excludeFiles		files to exclude while packing archive
  * @param	boolean		$ignoreDotFiles		should files beginning with a dot be ignored
  * @param	boolean		$removeAfter		should temporary files be removed afterwards
  */
 public function __construct($source, PackageReader $package, $directory, $filename, $excludeFiles = array(), $ignoreDotFiles = true, $removeAfter = false, $allowedDotFiles = array())
 {
     // read source
     $this->source = $source instanceof Source ? $source : new Source($source);
     // read package
     $this->package = $package->getPackageData();
     if (!isset($this->package['name'])) {
         throw new SystemException('Missing package name in "' . $directory . '", package.xml is not valid');
     }
     $this->ignoreDotFiles = $ignoreDotFiles;
     // add additional files whitch should be allowed
     if (!empty($allowedDotFiles)) {
         if (!is_array($allowedDotFiles)) {
             $allowedDotFiles = array($allowedDotFiles);
         }
         $this->allowedDotFiles = array_merge($this->allowedDotFiles, $allowedDotFiles);
     }
     // add additional files whitch should be excluded
     if (!empty($excludeFiles)) {
         if (!is_array($excludeFiles)) {
             $excludeFiles = array($excludeFiles);
         }
         $this->excludeFiles = array_merge($this->excludeFiles, $excludeFiles);
     }
     // get data for filename
     $data = array('pn' => $this->package['name'], 'pv' => $this->package['version'], 'pr' => 'r' . $this->source->revision, 't' => DateUtil::formatTime('%Y-%m-%d %H:%M:%S', TIME_NOW, false));
     // set archive name
     $this->filename = PackageHelper::getArchiveName($filename, $data);
     // mark package as built
     $buildDirectory = FileUtil::addTrailingSlash($this->source->buildDirectory);
     $location = $buildDirectory . $this->filename;
     PackageHelper::addPackageData($this->package['name'], $location);
     // check requirements
     $this->verifyPackages('requiredpackage', $directory);
     $this->verifyPackages('optionalpackage', $directory);
     // intialize archive
     $location = $this->createArchive($directory, $this->filename, $removeAfter);
     // do not move files created on-the-fly
     if (PackageHelper::isTemporaryFile($location)) {
         $this->location = $location;
         return;
     }
     // register file
     require_once PB_DIR . 'lib/data/source/file/SourceFileEditor.class.php';
     $sourceFile = SourceFileEditor::create($this->source->sourceID, $location, 'package');
     $this->location = $sourceFile->getPath();
 }
 /**
  * Builds any combination of archive names
  *
  * @param	string	$pattern
  */
 protected function generateArchiveName($pattern)
 {
     // recursively call method if pattern is an array
     if (is_array($pattern)) {
         foreach ($pattern as $filename) {
             if (!$filename) {
                 continue;
             }
             $this->generateArchiveName($filename);
         }
         return;
     }
     // dummy values
     if ($this->currentDirectory === null || !isset($this->packages[$this->currentDirectory])) {
         $data = array('pn' => 'packageName', 'pv' => 'packageVersion', 'pr' => 'r' . $this->source->revision, 't' => DateUtil::formatTime('%Y-%m-%d %H:%M:%S', TIME_NOW, false));
     } else {
         $data = array('pn' => $this->packages[$this->currentDirectory]['packageName'], 'pv' => $this->packages[$this->currentDirectory]['version'], 'pr' => 'r' . $this->source->revision, 't' => DateUtil::formatTime('%Y-%m-%d %H:%M:%S', TIME_NOW, false));
     }
     // get filename
     $this->filenames[$pattern] = PackageHelper::getArchiveName($pattern, $data);
 }