public function testGetBinaryFindersSet() { touch('bad.jpg'); touch('test.jpg'); touch('test.png'); touch('test.php'); $this->setConfig(array('blacklist' => array('bad.jpg'), 'finder-bin' => array(array('name' => '*.png', 'in' => '.'), array('name' => '*.jpg', 'in' => '.')))); /** @var $results \SplFileInfo[] */ $results = array(); $finders = $this->config->getBinaryFinders(); foreach ($finders as $finder) { foreach ($finder as $result) { $results[] = $result; } } $this->assertEquals('test.png', $results[0]->getBasename()); $this->assertEquals('test.jpg', $results[1]->getBasename()); }
/** * @override */ protected function execute(InputInterface $input, OutputInterface $output) { $this->config = $this->getConfig($input); $path = $this->config->getOutputPath(); // load bootstrap file if (null !== ($bootstrap = $this->config->getBootstrapFile())) { $this->config->loadBootstrap(); $this->putln('?', "Loading bootstrap file: {$bootstrap}"); unset($bootstrap); } // remove any previous work if (file_exists($path)) { $this->putln('?', 'Removing previously built Phar...'); unlink($path); } // set up Box if ($this->isVerbose()) { $this->putln('*', 'Building...'); } else { $output->writeln('Building...'); } $this->putln('?', "Output path: {$path}"); $this->box = Box::create($path); // set replacement values, if any if (array() !== ($values = $this->config->getProcessedReplacements())) { $this->putln('?', 'Setting replacement values...'); if ($this->isVerbose()) { foreach ($values as $key => $value) { $this->putln('+', "{$key}: {$value}"); } } $this->box->setValues($values); unset($values, $key, $value); } // register configured compactors if (array() !== ($compactors = $this->config->getCompactors())) { $this->putln('?', 'Registering compactors...'); foreach ($compactors as $compactor) { $this->putln('+', get_class($compactor)); $this->box->addCompactor($compactor); } } // alert about mapped paths if (array() !== ($map = $this->config->getMap())) { $this->putln('?', 'Mapping paths:'); foreach ($map as $item) { foreach ($item as $match => $replace) { if (empty($match)) { $match = "(all)"; } $this->putln('-', "{$match} <info>></info> {$replace}"); } } } // start adding files if (array() !== ($iterators = $this->config->getFinders())) { $this->putln('?', 'Adding Finder files...'); foreach ($iterators as $iterator) { $this->add($iterator, null); } } if (array() !== ($iterators = $this->config->getBinaryFinders())) { $this->putln('?', 'Adding binary Finder files...'); foreach ($iterators as $iterator) { $this->add($iterator, null, true); } } $this->add($this->config->getDirectoriesIterator(), 'Adding directories...'); $this->add($this->config->getBinaryDirectoriesIterator(), 'Adding binary directories...', true); $this->add($this->config->getFilesIterator(), 'Adding files...'); $this->add($this->config->getBinaryFilesIterator(), 'Adding binary files...', true); if (null !== ($main = $this->config->getMainScriptPath())) { $this->putln('?', 'Adding main file: ' . $this->config->getBasePath() . DIRECTORY_SEPARATOR . $main); $mapper = $this->config->getMapper(); $pharPath = $mapper($main); if (null !== $pharPath) { $this->putln('>', $pharPath); $main = $pharPath; } $this->box->addFromString($main, $this->config->getMainScriptContents()); } // set the appropriate stub if (true === $this->config->isStubGenerated()) { $this->putln('?', 'Generating new stub...'); $stub = StubGenerator::create()->alias($this->config->getAlias())->extract($this->config->isExtractable())->index($main)->intercept($this->config->isInterceptFileFuncs())->mimetypes($this->config->getMimetypeMapping())->mung($this->config->getMungVariables())->notFound($this->config->getNotFoundScriptPath())->web($this->config->isWebPhar()); if (null !== ($shebang = $this->config->getShebang())) { $this->putln('-', 'Using custom shebang line: ' . $shebang); $stub->shebang($shebang); } if (null !== ($banner = $this->config->getStubBanner())) { $this->putln('-', 'Using custom banner.'); $stub->banner($banner); } elseif (null !== ($banner = $this->config->getStubBannerFromFile())) { $this->putln('-', 'Using custom banner from file: ' . $this->config->getBasePath() . DIRECTORY_SEPARATOR . $this->config->getStubBannerPath()); $stub->banner($banner); } $this->box->getPhar()->setStub($stub->generate()); } elseif (null !== ($stub = $this->config->getStubPath())) { $stub = $this->config->getBasePath() . DIRECTORY_SEPARATOR . $stub; $this->putln('?', "Using stub file: {$stub}"); $this->box->setStubUsingFile($stub); } else { $this->putln('?', 'Using default stub.'); } // set metadata, if any if (null !== ($metadata = $this->config->getMetadata())) { $this->putln('?', 'Setting metadata...'); $this->box->getPhar()->setMetadata($metadata); } // compress, if algorithm set if (null !== ($algorithm = $this->config->getCompressionAlgorithm())) { $this->putln('?', 'Compressing...'); $this->box->getPhar()->compressFiles($algorithm); } $this->box->getPhar()->stopBuffering(); // sign using private key, if applicable if (file_exists($path . '.pubkey')) { unlink($path . '.pubkey'); } if (null !== ($key = $this->config->getPrivateKeyPath())) { $this->putln('?', 'Signing using a private key...'); $passphrase = $this->config->getPrivateKeyPassphrase(); if ($this->config->isPrivateKeyPrompt()) { /** @var $dialog DialogHelper */ $dialog = $this->getHelper('dialog'); $passphrase = $dialog->askHiddenResponse($output, 'Private key passphrase:'); } $this->box->signUsingFile($key, $passphrase); // set the signature algorithm if no key is used } elseif (null !== ($algorithm = $this->config->getSigningAlgorithm())) { $this->box->getPhar()->setSignatureAlgorithm($algorithm); } unset($this->box); // chmod, if configured if (null !== ($chmod = $this->config->getFileMode())) { $this->putln('?', 'Setting file permissions...'); chmod($path, $chmod); } $this->putln('*', 'Done.'); }