Exemplo n.º 1
0
 /**
  * returns a bundle
  *
  * @return  Bundle
  */
 public function bundle()
 {
     $bundle = new Bundle();
     $iterator = Finder::create()->files()->ignoreVCS(true)->filter($this->package->getBlacklistFilter())->exclude($this->package->getPathVendor())->in($this->package->getDirectory());
     $this->logger->log('    Adding whole project directory "' . $this->package->getDirectory() . '"');
     return $bundle->addDir($iterator);
 }
Exemplo n.º 2
0
 /**
  * @test
  */
 public function addPackageAddsResourcesFromCalculatedBundle()
 {
     $bundle = new Bundle();
     $bundle->addFile('path/to/package/file.php');
     $this->mockPharComposer->expects($this->once())->method('getPathLocalToBase')->with($this->equalTo('path/to/package/file.php'))->will($this->returnValue('file.php'));
     $this->mockBox->expects($this->once())->method('addFile')->with($this->equalTo('path/to/package/file.php'), $this->equalTo('file.php'));
     $mockFinder = $this->createMock('Symfony\\Component\\Finder\\Finder');
     $bundle->addDir($mockFinder);
     $this->mockPharComposer->expects($this->once())->method('getBase')->will($this->returnValue('path/to/package'));
     $this->mockBox->expects($this->once())->method('buildFromIterator')->with($this->equalTo($mockFinder), $this->equalTo('path/to/package'));
     $this->targetPhar->addBundle($bundle);
 }
Exemplo n.º 3
0
 public function build()
 {
     $this->log('[' . $this->step . '/' . $this->step . '] Creating phar <info>' . $this->getTarget() . '</info>');
     $time = microtime(true);
     $pathVendor = $this->getPathVendor();
     if (!is_dir($pathVendor)) {
         throw new RuntimeException('Directory "' . $pathVendor . '" not properly installed, did you run "composer install"?');
     }
     $target = $this->getTarget();
     if (file_exists($target)) {
         $this->log('  - Remove existing file <info>' . $target . '</info> (' . $this->getSize($target) . ')');
         if (unlink($target) === false) {
             throw new UnexpectedValueException('Unable to remove existing phar archive "' . $target . '"');
         }
     }
     $targetPhar = TargetPhar::create($target, $this);
     $this->log('  - Adding main package');
     $targetPhar->addBundle(Bundle::from($this->getPackageRoot(), $this->logger));
     $this->log('  - Adding composer base files');
     // explicitly add composer autoloader
     $targetPhar->addFile($pathVendor . 'autoload.php');
     // TODO: check for vendor/bin !
     // only add composer base directory (no sub-directories!)
     $targetPhar->buildFromIterator(new \GlobIterator($pathVendor . 'composer/*.*', \FilesystemIterator::KEY_AS_FILENAME));
     foreach ($this->getPackagesDependencies() as $package) {
         $this->log('  - Adding dependency "' . $package->getName() . '" from "' . $this->getPathLocalToBase($package->getDirectory()) . '"');
         $targetPhar->addBundle(Bundle::from($package, $this->logger));
     }
     $this->log('  - Setting main/stub');
     $chmod = 0755;
     $main = $this->getMain();
     if ($main === null) {
         $this->log('    WARNING: No main bin file defined! Resulting phar will NOT be executable');
     } else {
         $generator = StubGenerator::create()->index($this->getPathLocalToBase($main))->extract(true)->banner("Bundled by phar-composer with the help of php-box.\n\n@link https://github.com/clue/phar-composer");
         $lines = file($main, FILE_IGNORE_NEW_LINES);
         if (substr($lines[0], 0, 2) === '#!') {
             $this->log('    Using referenced shebang "' . $lines[0] . '"');
             $generator->shebang($lines[0]);
             // remove shebang from main file and add (overwrite)
             unset($lines[0]);
             $targetPhar->addFromString($this->getPathLocalToBase($main), implode("\n", $lines));
         }
         $targetPhar->setStub($generator->generate());
         $chmod = octdec(substr(decoct(fileperms($main)), -4));
         $this->log('    Using referenced chmod ' . sprintf('%04o', $chmod));
     }
     $targetPhar->finalize();
     if ($chmod !== null) {
         $this->log('    Applying chmod ' . sprintf('%04o', $chmod));
         if (chmod($target, $chmod) === false) {
             throw new UnexpectedValueException('Unable to chmod target file "' . $target . '"');
         }
     }
     $time = max(microtime(true) - $time, 0);
     $this->log('');
     $this->log('    <info>OK</info> - Creating <info>' . $this->getTarget() . '</info> (' . $this->getSize($this->getTarget()) . ') completed after ' . round($time, 1) . 's');
 }
Exemplo n.º 4
0
 private function addDir(Bundle $bundle, $dir)
 {
     $dir = $this->package->getAbsolutePath(rtrim($dir, '/') . '/');
     $this->logger->log('    adding "' . $dir . '"');
     $bundle->addDir(Finder::create()->files()->ignoreVCS(true)->in($dir));
 }