Add file to phar package.

@param \Phar $phar
Phar object.
@param string $file
File path.
@param boolean $strip
Strip whitespace.
767884
protected function addFile($phar, $file, $strip = true)
    {
        $path = strtr(str_replace($this->projectPath, '', $file->getRealPath()), '\\', '/');
        $content = file_get_contents($file);

        $this->logger->log('<comment>Adding file</comment> ' . $path);

        switch (true) {
            case ('LICENSE' === basename($file)):
                $content = "\n" . $content . "\n";
                break;

            case preg_match('#/In2pire/Cli/Configuration/PhpConfiguration.php$#', $path):
                if ($this->flag & STATIC::FLAG_CACHE) {
                    $configuration = $this->getAllConfiguration();
                    $content = str_replace('// [CONFIGURATION]', '$this->configuration = ' . var_export($configuration, 1) . ';', $content);
                    $content = str_replace(['@version', '@build'], [$this->buildVersion, $this->buildDate], $content);
                }
                break;

            case (pathinfo($file, PATHINFO_EXTENSION) == 'yml'):
                $content = str_replace(['@version', '@build'], [$this->buildVersion, $this->buildDate], $content);
                break;

            case $strip:
                $content = $this->stripWhitespace($content);
                break;
        }

        $phar->addFromString($path, $content);
        $this->increaseFileCounter();
    }
56030
public function add($file, $entry_name = null)
    {
        // Make sure to adapt the entry name as the original filename.
        if (isset($entry_name)) {
            $this->phar->addFile($file, $entry_name);
        }
        else {
            $this->phar->addFile($file);
        }

        return $this;
    }
910043
public function compile()
    {
        $pharFilePath = dirname(__FILE__).'/../../build/packagist-security-checker.phar';

        if (file_exists($pharFilePath)) {
            unlink($pharFilePath);
        }

        $phar = new Phar($pharFilePath, 0, 'packagist-security-checker.phar');
        $phar->setSignatureAlgorithm(\Phar::SHA1);

        $phar->startBuffering();

        $this
            ->addPHPFiles($phar)
            ->addVendorFiles($phar)
            ->addComposerVendorFiles($phar)
            ->addBin($phar)
            ->addStub($phar)
            ->addLicense($phar);

        $phar->stopBuffering();

        unset($phar);
    }
1310459
protected function makePhar()
    {
        $phar = new Phar($this->filePhar, 0, $this->alias);
        $phar->setSignatureAlgorithm(\Phar::SHA1);
        $phar->startBuffering();

        // Adicionar arquivos
        $this->addFiles($phar);

        // Adicionar arquivo bin
        $this->addBinFile($phar);

        // Adicionar Stup
        $this->addStub($phar);

        // Adicionar licenca
        $this->addLicence($phar);

        // Adicionar arquivo de update
        //$this->addUpdateFile($phar);

        // Finalizar phar.
        $phar->stopBuffering();
        unset($phar);
    }
234891
protected function addStub(Phar $phar)
    {
        $this->fireEvent('STUB');

        // Add warning once the phar is older than 30 days
        $defineTime = '';
        if (array_key_exists('package_version', $this->params)) {
            $warningTime = time() + 30 * 86400;
            $defineTime = "define('PHAR_DEV_WARNING_TIME', $warningTime);\n";
        }

        $content = $this->files->get(__DIR__ . '/../stubs/compile.stub');
        $content = str_replace('DubbyAlias', $this->alias, $content);
        $content = str_replace('DubbyDefineDateTime', $defineTime, $content);

        $phar->setStub($content);
    }
1266142
private function addComposerBin(\Phar $phar)
    {
        $this->info('add file BIN');

        $content = file_get_contents(base_path('artisan'));
        $content = preg_replace('{^#!/usr/bin/env php\s*}', '', $content);
        $phar->addFromString('artisan', $content);
    }
1061306
protected function addDbup(\Phar $phar)
    {
        $content = file_get_contents(__DIR__ . '/../../../dbup');
        $content = preg_replace('{^#!/usr/bin/env php\s*}', '', $content);

        $phar->addFromString('dbup', $content);
    }
1100985
public function addFile($file)
    {
        $this->box->addFile($file, $this->pharComposer->getPathLocalToBase($file));
    }
532545
public function addCss($file, $path='/css', $attr = [])
    {
        $attr = array_merge(['rel' => 'stylesheet'], $attr);
        $output = [];
        foreach ($attr as $name => $value) {
            $output[] = "{$name}=\"{$value}\"";
        }
        $attr = implode(' ', $output);
        $file = str_replace('//', '', "{$path}/{$file}");
        return sprintf('<link href="%s" %s>', $file, $attr);
    }
89774
public function addFile($file, $coverage)
    {
        $file = $this->realpath($file);
        if (!$this->collectable($file)) {
            return;
        }
        $nbLines = count(file($file));

        foreach ($coverage as $line => $value) {
            if ($line === 0 || $line >= $nbLines) {
                continue; // Because Xdebug bugs...
            }
            if (!isset($this->_coverage[$file][$line])) {
                $this->_coverage[$file][$line] = $value;
            } else {
                $this->_coverage[$file][$line] += $value;
            }
        }
    }
421992
public function setPatchFile(PhingFile $file)
    {
        if (!$file->exists()) {
            throw new BuildException('patchfile ' . $file . " doesn't exist", $this->getLocation());
        }
        $this->cmd->createArgument()->setValue('-i');
        $this->cmd->createArgument()->setFile($file);
        $this->havePatchFile = true;
    }
479237
public function add( $file, $version = "", $attr = array() ) {

		if ( count( $attr ) <= 0 && is_array( $version ) ) {
			$attr    = $version;
			$version = "";
		}

		if ( empty( $version ) ) {
			$version = '?ver=' . Kecik::$version;
		} else {
			$version = '?ver=' . $version;
		}

		if ( ! in_array( $file, $this->assets[ $this->type ] ) ) {
			$this->assets[ $this->type ][]   = $file;
			$this->attr[ $this->type ][]     = $attr;
			$this->versions[ $this->type ][] = $version;
		}

	}
106477
public static function write(string $file = '', string $data = '', bool $doAppend = false): bool
    {
        $result = false;
        $file = static::normalizePath($file);
        if (static::verifyPath($file) && Directory::create(\dirname($file))) {
            $flags = $doAppend ? FILE_APPEND : 0;
            $flags |= static::$writeLocks ? LOCK_EX : 0;

            $result = @\file_put_contents($file, $data, $flags) !== false;
            @\chmod($file, static::$newFileMode);
        }
        return $result;
    }
756728
final public function include_file( string $file, bool $return = false ) {
		$file = $this->path . $file;
		if ( ! file_exists( $file ) || 0 !== validate_file( $file ) ) {
			return '';
		}

		if ( $return ) {
			ob_start();
			require $file;
			return ob_get_clean();
		}

		require $file;
	}
617207
private function addComposerVendorFiles(Phar $phar)
    {
        $vendorPath = __DIR__.'/../../vendor/';

        $this
            ->addFile($phar, new \SplFileInfo($vendorPath.'autoload.php'))
            ->addFile($phar, new \SplFileInfo($vendorPath.'composer/autoload_namespaces.php'))
            ->addFile($phar, new \SplFileInfo($vendorPath.'composer/autoload_psr4.php'))
            ->addFile($phar, new \SplFileInfo($vendorPath.'composer/autoload_classmap.php'))
            ->addFile($phar, new \SplFileInfo($vendorPath.'composer/autoload_real.php'))
            ->addFile($phar, new \SplFileInfo($vendorPath.'composer/autoload_static.php'))
            ->addFile($phar, new \SplFileInfo($vendorPath.'composer/ClassLoader.php'));

        return $this;
    }
483831
protected function _createFromFile($file) {
        if (!file_exists($file)) {
            Garp_Cli::errorOut("File not found: {$file}. Adding no snippets.");
            return false;
        }
        $config = new Garp_Config_Ini($file, APPLICATION_ENV);
        if (!isset($config->snippets)) {
            Garp_Cli::lineOut('Could not find any snippets. I\'m stopping now... This is awkward.');
            return true;
        }

        $snippetNoun = 'snippets';
        $snippetCount = count($config->snippets);
        if ($snippetCount === 1) {
            $snippetNoun = 'snippet';
        }
        Garp_Cli::lineOut("About to add {$snippetCount} {$snippetNoun} from {$file}");
        Garp_Cli::lineOut('');
        $this->_createSnippets($config->snippets);
        Garp_Cli::lineOut('Done.');
        Garp_Cli::lineOut('');
        return true;
    }
1355355
private function addFile(Phar $phar, SplFileInfo $file, $strip = false)
    {
        // Forçar tirar espaços de PHP.
        $strip = ($file->getExtension() == 'php') ? true : $strip;

        $this->fireEvent($file->getRealPath());

        $path = str_replace($this->pathBase, '', $file->getRealPath());
        $content = $this->files->get($file);

        // Tratar espacos?
        if ($strip) {
            $content = $this->stripWhitespace($content);
        }

        // Eh arquivo de licenca?
        if ('LICENSE' === basename($file)) {
            $content = "\n" . $content . "\n";
        }

        // Tratar parametros
        foreach ($this->params as $pk => $pv) {
            $pk = sprintf('@%s@', $pk);
            $content = str_replace($pk, $pv, $content);
        }
        $phar->addFromString($path, $content);
    }