function build_pheanstalk_phar()
{
    printf("- Building %s from %s\n", PHAR_FILENAME, BASE_DIR);
    $phar = new Phar(PHAR_FULLPATH);
    $phar->buildFromDirectory(BASE_DIR);
    $phar->setStub($phar->createDefaultStub("vendor/autoload.php"));
}
示例#2
0
 /**
  * Execute the task
  *
  * @throws Exception
  * @return void
  */
 public function execute()
 {
     $target = $this->getOption('target');
     $sourceDirectory = $this->getOption('sourceDirectory');
     $stubFile = $this->getOption('stubFile');
     if (!extension_loaded('phar')) {
         throw new \Exception('Phar extension not loaded');
     }
     if (!is_dir($sourceDirectory)) {
         throw new \Exception('Source directory not found: ' . $sourceDirectory);
     }
     // check to see if we can create phar files
     $readOnly = ini_get('phar.readonly');
     if ($readOnly != 1) {
         $phar = new \Phar($target, 0, basename($target));
         $phar->startBuffering();
         $phar->buildFromDirectory($sourceDirectory);
         $stub = $phar->createDefaultStub();
         $phar->setStub($stub);
         $phar->stopBuffering();
         //$phar->compress(Phar::GZ);
     } else {
         throw new \Exception('Cannot create phar! (read-only enabled)');
     }
 }
示例#3
0
    public function testItExtractsIconFromPhar()
    {
        $key = uniqid();
        $iconContent = $key;
        $rootPackage = dirname(dirname(__FILE__));
        $iconRelativePath = 'Resources/notification/icon-' . $key . '.png';
        $testDir = sys_get_temp_dir() . '/test-jolinotif';
        $pharPath = $testDir . '/notification-extract-icon-' . $key . '.phar';
        $extractedIconPath = sys_get_temp_dir() . '/jolinotif/' . $iconRelativePath;
        if (!is_dir($testDir)) {
            mkdir($testDir);
        }
        $bootstrap = <<<'PHAR_BOOTSTRAP'
<?php

require __DIR__.'/vendor/autoload.php';

$iconPath = THE_ICON;
$notification = new \Joli\JoliNotif\Notification();
$notification->setBody('My notification');
$notification->setIcon(__DIR__.$iconPath);
PHAR_BOOTSTRAP;
        $phar = new \Phar($pharPath);
        $phar->buildFromDirectory($rootPackage, '#(src|tests/fixtures|vendor/composer)#');
        $phar->addFromString('bootstrap.php', str_replace('THE_ICON', '\'/' . $iconRelativePath . '\'', $bootstrap));
        $phar->addFromString($iconRelativePath, $iconContent);
        $phar->addFile('vendor/autoload.php');
        $phar->setStub($phar->createDefaultStub('bootstrap.php'));
        $this->assertTrue(is_file($pharPath));
        exec('php ' . $pharPath);
        $this->assertTrue(is_file($extractedIconPath));
        $this->assertSame($iconContent, file_get_contents($extractedIconPath));
    }
示例#4
0
function build_phar()
{
    $phar = new Phar('build/bugsnag.phar');
    $phar->buildFromDirectory(dirname(__FILE__) . '/src', '/\\.php$/');
    $phar->compressFiles(Phar::GZ);
    $phar->stopBuffering();
    $phar->setStub($phar->createDefaultStub('Bugsnag/Autoload.php'));
}
示例#5
0
 static function create($phar_file, $php_dir, $default_stub)
 {
     $phar = new \Phar($phar_file);
     $phar->buildFromDirectory($php_dir, '/\\.php$/');
     $phar->compressFiles(\Phar::GZ);
     $phar->stopBuffering();
     $phar->setStub($phar->createDefaultStub($default_stub));
 }
示例#6
0
function createPharFile($pharFilePath, $originalFile)
{
    $originalFile = realpath($originalFile);
    try {
        $phar = new Phar($pharFilePath);
        $phar->addFile($originalFile);
        $phar->compressFiles(Phar::GZ);
        $phar->stopBuffering();
        $phar->setStub($phar->createDefaultStub($pharFilePath));
        $phar->setStub("<?php Phar::mapPhar();\ninclude 'phar://{$pharFilePath}/{$originalFile}'; __HALT_COMPILER(); ?>");
    } catch (Exception $e) {
        var_dump($e->getMessage());
    }
}
示例#7
0
 /**
  * @param string $cli
  * @param string $web
  * @param array  $ignored
  * @param bool   $ignoreScm
  *
  * @return $this
  */
 public function build($cli = null, $web = null, array $ignored = null, $ignoreScm = true)
 {
     // debug
     $this->debug("Creating phar-file ...");
     // create phar
     $pharAlias = basename($this->filename);
     $this->phar = new \Phar($this->targetName, 0, $pharAlias);
     $this->phar->setSignatureAlgorithm(\Phar::SHA1);
     // start buffering
     $this->phar->startBuffering();
     // normalize ignored-array if present
     if (null !== $ignored) {
         foreach ($ignored as &$path) {
             $path = \str_replace($this->sourceDir, '', $path);
             if (\DIRECTORY_SEPARATOR !== \substr($path, 0, 1)) {
                 $path = \DIRECTORY_SEPARATOR . $path;
             }
         }
     }
     // indexing source
     $this->indexSourceDir($this->sourceDir, $ignored, $ignoreScm);
     // debug
     $this->debug(\str_repeat('-', 76));
     $this->debug("--> Indexing done.");
     // normalize entry files
     if ($cli) {
         $cli = \str_replace($this->sourceDir, '', $cli);
         $this->debug(\sprintf("--> Setting entry-point for CLI-execution to '%s'", $cli));
     }
     if ($web) {
         $web = \str_replace($this->sourceDir, '', $web);
         $this->debug(\sprintf("--> Setting entry-point for WEB-execution to '%s'", $web));
     }
     // set entry-point
     $this->phar->setStub($this->phar->createDefaultStub($cli, $web));
     // stop the buffering
     $this->phar->stopBuffering();
     // return fluid interface
     return $this;
 }
示例#8
0
$binaryFilename = "bin/{$binary}";
if (file_exists($pharFilename)) {
    Phar::unlinkArchive($pharFilename);
}
if (file_exists($binaryFilename)) {
    Phar::unlinkArchive($binaryFilename);
}
$phar = new Phar($pharFilename, FilesystemIterator::KEY_AS_PATHNAME | FilesystemIterator::CURRENT_AS_FILEINFO, $binary);
$phar->startBuffering();
$directories = array('src', 'vendor', 'scripts');
foreach ($directories as $dirname) {
    $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dirname));
    while ($iterator->valid()) {
        if ($iterator->isFile()) {
            $path = $iterator->getPathName();
            if ('php' == strtolower($iterator->getExtension())) {
                $contents = php_strip_whitespace($path);
                $phar->addFromString($path, $contents);
            } else {
                $phar->addFile($path);
            }
        }
        $iterator->next();
    }
}
$stub = "#!/usr/bin/env php\n" . $phar->createDefaultStub($scriptFilename);
$phar->setStub($stub);
$phar->compressFiles(Phar::GZ);
$phar->stopBuffering();
rename($pharFilename, $binaryFilename);
chmod($binaryFilename, 0775);
示例#9
0
    $dir = $dirName . "\\" . $src;
    $rp = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir));
    foreach ($rp as $file) {
        if ($file->isFile() && $file->getFilename() != ".." && $file->getFilename() != ".") {
            $pathBefore = substr($file->getPath(), 0, strlen($dir));
            $pathAfter = substr($file->getPath(), strlen($dir) + 1);
            $pathTo = "\\" . $suffix . ($pathAfter !== false ? $pathAfter . "\\" : "") . $file->getFilename();
            $phar->addFromString($pathTo, file_get_contents($file->getPath() . "/" . $file->getFilename()));
        }
    }
}
if (isset($composer["require"])) {
    while (list($library, $ver) = each($composer["require"])) {
        if (file_exists($dirName . "\\vendor\\" . $library)) {
            $dir = $dirName . "\\vendor\\" . $library . "\\src";
            $rp = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir));
        }
        foreach ($rp as $file) {
            if ($file->isFile() && $file->getFilename() != ".." && $file->getFilename() != ".") {
                $pathBefore = substr($file->getPath(), 0, strlen($dir));
                $pathAfter = substr($file->getPath(), strlen($dir) + 1);
                $pathTo = "\\" . $suffix . ($pathAfter !== false ? $pathAfter . "\\" : "") . $file->getFilename();
                $phar->addFromString($pathTo, file_get_contents($file->getPath() . "/" . $file->getFilename()));
            }
        }
    }
}
$stubSource = "<?php\r\n" . "class TMLoader {\r\n" . "    public static function get() {\r\n" . "        spl_autoload_register(function (\$class) {\r\n" . "            \$fileName = \"phar://{$pharName}/\" . \$class . \".php\";\r\n" . "            if (file_exists(\$fileName)) {\r\n" . "                include_once (\$fileName);\r\n" . "            }\r\n" . "        })\r\n;" . "    }\r\n" . "}";
$phar->addFromString("TMLoader.php", $stubSource);
$phar->setStub($phar->createDefaultStub('TMLoader.php'));
 /**
  * Exports a PHAR file for the entire extension
  *
  * @param string $phar_name
  * @param string $output_dir
  * @param bool   $create_sub_directories
  *
  * @throws \Exception
  */
 public function exportPHAR($phar_name, $output_dir = '.', $create_sub_directories = true)
 {
     ini_set('phar.readonly', 0);
     $temp_dir = '/tmp' . DIRECTORY_SEPARATOR . 'PHPExport_' . rand(1, 9999);
     if (!file_exists($temp_dir) && !@mkdir($temp_dir)) {
         throw new \Exception("Could not create temp directory: {$temp_dir}");
     }
     $this->exportFiles($temp_dir, $create_sub_directories);
     $phar = new \Phar($output_dir . DIRECTORY_SEPARATOR . $phar_name, 0, $phar_name);
     $phar->buildFromDirectory($temp_dir, '#\\.php$#');
     $result = $phar->setStub($phar->createDefaultStub('cli/index.php', 'www/index.php'));
     if (!$result) {
         throw new \Exception('Could not set stub for phar: ' . $phar_name);
     }
 }
示例#11
0
<?php

$phar = new Phar('jellytest.phar');
//指定压缩包的名称
$phar->startBuffering();
$phar->buildFromDirectory(__DIR__, '$(src|vendor)/.*\\.php$');
//第1个参数 指定压缩的目录, 第2个参数 通过正则来制定压缩文件的扩展名
//$phar->compressFiles(Phar::GZ); 指定压缩格式,Phar::GZ表示使用gzip来压缩此文件。也支持bz2压缩。参数修改为 PHAR::BZ2即可
$phar->setStub($phar->createDefaultStub('./vendor/autoload.php'));
#设置启动加载的文件。默认会自动加载并执行./vendor/autoload.php
$phar->stopBuffering();
/**
使用phar压缩包
include 'jellytest.phar';
include 'jellytest.phar/code/page.php';
*/
<?php

$dir = dirname(__FILE__) . '/broken.dirname';
mkdir($dir, 0777);
$fname = $dir . '/dotted_path.phar';
$stub = Phar::createDefaultStub();
$file = $stub;
$files = array();
$files['a'] = 'this is a';
$files['b'] = 'this is b';
include 'files/phar_test.inc';
$phar = new Phar($fname);
foreach ($phar as $entry) {
    echo file_get_contents($entry) . "\n";
}
?>
===DONE===
示例#13
0
<?php

$destFile = __DIR__ . '/bin/mtags.phar';
if (file_exists($destFile)) {
    unlink($destFile);
}
$phar = new Phar($destFile);
$phar->addFile(__DIR__ . '/mtags.php', 'mtags.php');
$phar->setStub($phar->createDefaultStub('mtags.php'));
// for completeness
$phar->addFile(__FILE__, basename(__FILE__));
$phar->addFile(__DIR__ . '/composer.json', 'composer.json');
foreach (glob(__DIR__ . '/src/*.php') as $file) {
    $phar->addFile($file, 'src/' . basename($file));
}
$phar->addFile(__DIR__ . '/vendor/autoload.php', 'vendor/autoload.php');
foreach (glob(__DIR__ . '/vendor/composer/*.php') as $file) {
    $phar->addFile($file, 'vendor/composer/' . basename($file));
}
$phar->addFile(__DIR__ . '/vendor/pwfisher/command-line-php/CommandLine.php', 'vendor/pwfisher/command-line-php/CommandLine.php');
$getid3dir = 'vendor/james-heinrich/getid3/getid3';
$getid3modules = ['getid3', 'module.audio.', 'module.misc.iso', 'module.misc.cue', 'module.tag.', 'module.audio-video.riff', 'module.audio-video.quicktime'];
foreach (glob(__DIR__ . '/' . $getid3dir . '/*.php') as $file) {
    $basename = basename($file);
    foreach ($getid3modules as $module) {
        if (strpos($basename, $module) === 0) {
            $phar->addFile($file, $getid3dir . '/' . $basename);
            break;
        }
    }
}
示例#14
0
<?php

define('SRC_ROOT', dirname(__FILE__) . '/src');
define('BUILD_ROOT', dirname(__FILE__) . '/build');
try {
    $phar = new Phar(BUILD_ROOT . '/PeriscopeDownloader.phar', FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME, 'PeriscopeDownloader.phar');
    $phar->buildFromDirectory(SRC_ROOT, '/.php$/');
    $phar->setMetadata(array('version' => '1.0', 'author' => 'jColfej', 'description' => 'Easy download periscope replay !'));
    $phar->setStub('#!/usr/bin/env php' . PHP_EOL . $phar->createDefaultStub('index.php'));
    echo 'File created : build/PeriscopeDownloader.phar' . PHP_EOL;
} catch (Exception $e) {
    echo '/!\\ Erreur on PHAR creation ...' . PHP_EOL;
    echo PHP_EOL;
    echo 'Error : ' . $e->getMessage() . PHP_EOL;
    echo 'File : ' . $e->getFile() . PHP_EOL;
    echo PHP_EOL;
    echo $e->getTraceAsString() . PHP_EOL;
}
示例#15
0
ini_set("display_errors", "on");
require_once "../src/configuration/config.php";
$EOL_PRINT = "<br/>\n";
echo "***********************************" . $EOL_PRINT;
echo "* <strong>Creating a phar file</strong>" . $EOL_PRINT;
echo "*                                  " . $EOL_PRINT;
echo "* This script builds the .phar file" . $EOL_PRINT;
echo "* for using the framework in a     " . $EOL_PRINT;
echo "* archive.                         " . $EOL_PRINT;
echo "***********************************" . $EOL_PRINT;
echo "* <strong>BUILD_SCRIPT_VERSION</strong> " . $BUILD_SCRIPT_VERSION . $EOL_PRINT;
echo "* <strong>FRAMEWORK_VERSION</strong> " . $FRAMEWORK_VERSION . $EOL_PRINT;
echo "***********************************" . $EOL_PRINT . $EOL_PRINT;
$filename = "epages-rest-php-" . $FRAMEWORK_VERSION . ".phar";
$latestFilename = "epages-rest-php.phar";
if (file_exists($filename)) {
    echo "<strong>Version already exists. Delete this version of increase the version.</strong>";
} else {
    echo "<ul>";
    echo "<li><strong>Creating the .phar</strong></li>";
    $phar = new Phar($filename);
    echo "<li><strong>Adding all files</strong></li>";
    $phar->buildFromDirectory('../src');
    echo "<li><strong>Create and set default stub</strong></li>";
    $phar->setStub($phar->createDefaultStub('Shop.class.php'));
    echo "<li><strong>Delete the latest file</strong></li>";
    unlink($latestFilename);
    echo "<li><strong>Copy to latest</strong></li>";
    copy($filename, $latestFilename);
    echo "</ul>";
}
<?php

$app = new Phar("bin/docblock.phar", 0, "docblock.phar");
$app->addFile('src/docblock.php');
$app->addFile('src/DocBlockGenerator.class.php');
$defaultStub = $app->createDefaultStub("src/docblock.php");
$stub = "#!/usr/bin/env php \n" . $defaultStub;
$app->setStub($stub);
$app->stopBuffering();
?>

示例#17
0
 /**
  * Executes the current command.
  *
  * @param InputInterface  $input  An InputInterface instance
  * @param OutputInterface $output An OutputInterface instance
  *
  * @return null|int     null or 0 if everything went fine, or an error code
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('');
     $output->writeln('<comment>Creating package</comment>');
     $this->validate($input, $output);
     try {
         //get all params
         $rutaPhar = $input->getOption('output');
         $alias = $input->getOption('alias') . '.phar';
         $rutaPhar = rtrim($rutaPhar, '/') . '/' . $alias;
         $src = $input->getOption('src');
         $stub = $input->getOption('stub');
         $stubweb = $input->getOption('stubweb');
         $replace = $input->getOption('replace');
         $exclude = $input->getOption('exclude');
         if (true === $replace && is_file($rutaPhar)) {
             \Phar::unlinkArchive($rutaPhar);
         }
         //create and setup Stup object
         $oStub = new Stub();
         if (null !== $stub) {
             $oStub->setStubCli($stub);
         }
         if (null !== $stubweb) {
             $oStub->setStubWeb($stubweb);
         }
         $oStub->setDirTmp($src);
         $oStub->createDefaultStub();
         //create Finder object
         $finder = new Finder();
         $finder->files()->in($src);
         foreach ($exclude as $dirToExclude) {
             $finder->exclude($dirToExclude);
         }
         //inicialize progressbar
         $progress = new ProgressBar($output, count($finder));
         //create phar object
         $phar = new \Phar($rutaPhar, 0, $alias);
         $phar->startBuffering();
         //create default stubs
         $phar->setStub($phar->createDefaultStub($oStub->getStubCli(), $oStub->getStubWeb()));
         $progress->setBarCharacter('<comment>=</comment>');
         $progress->setProgressCharacter('<comment>></comment>');
         //add all files in the phar object
         $progress->start();
         foreach ($finder as $file) {
             $alias = ltrim(str_replace($src, '', $file->getPathname()), '/');
             $phar->addFile($file, $alias);
             $progress->advance();
         }
         $progress->finish();
         $phar->stopBuffering();
         $oStub->deleteTmpStubs();
         $output->writeln('');
         $output->writeln('');
         $output->writeln("<info>Phar created in: </info>" . $rutaPhar);
     } catch (\Exception $e) {
         $output->writeln('<error>' . $e->getMessage() . "</error>");
         exit(1);
     }
 }
示例#18
0
 *
 *   * Redistributions of source code must retain the above copyright notice,
 *     this list of conditions and the following disclaimer.
 *
 *   * Redistributions in binary form must reproduce the above copyright notice,
 *     this list of conditions and the following disclaimer in the documentation
 *     and/or other materials provided with the distribution.
 *
 *   * Neither the name of Sebastian Heuer nor the names of contributors
 *     may be used to endorse or promote products derived from this software
 *     without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER ORCONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 */
$srcDir = __DIR__ . '/src';
$buildDir = __DIR__ . '/build';
$phar = new Phar($buildDir . '/mokka.phar', NULL, 'mokka.phar');
$phar->buildFromDirectory($srcDir);
$phar->setStub($phar->createDefaultStub('/framework/autoload.php'));
<?php

$srcRoot = __DIR__;
$buildRoot = __DIR__ . '/build';
$phar = new Phar($buildRoot . "/myapp.phar", FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME, "myapp.phar");
$phar["public/index.php"] = file_get_contents($srcRoot . "/public/index.php");
$phar["public/test.php"] = file_get_contents($srcRoot . "/public/test.php");
$phar[".atoum.php"] = file_get_contents($srcRoot . "/.atoum.php");
$phar->setStub($phar->createDefaultStub("public/index.php"));
示例#20
0
<?php

$defaults = array('cli' => 'src/cli.php', 'web' => 'src/web.php', 'bin' => 'application.phar');
$temp_file = 'application.phar';
$options = getopt('', array('cli::', 'web::', 'bin::'));
$options = array_merge($defaults, $options);
@unlink($options['bin']);
@unlink($temp_file);
$phar = new Phar($temp_file);
$phar->buildFromDirectory(__DIR__, '/^((?!\\.git).)*$/');
$defaultStub = $phar->createDefaultStub($options['cli'], $options['web']);
$defaultStub = "#!/usr/bin/env php\n" . $defaultStub;
$phar->setStub($defaultStub);
unset($phar);
chmod($temp_file, 0755);
rename($temp_file, $options['bin']);
#!/usr/bin/env php5
<?php 
$source = realpath(__DIR__ . '/../src');
$bin = realpath(__DIR__ . '/../bin');
// Create the PHAR archive
$phar = new Phar($bin . '/music-playlist-generator.phar', Phar::CURRENT_AS_FILEINFO | Phar::KEY_AS_FILENAME, 'music-playlist-generator.phar');
// Start buffering
$phar->startBuffering();
// Add files of the source
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source));
while ($iterator->valid()) {
    if (!$iterator->isDot()) {
        $filePath = $iterator->key();
        $localePath = substr($filePath, strlen($source) + 1);
        echo "Add {$localePath} \n";
        $phar->addFile($filePath, $localePath);
    }
    $iterator->next();
}
// Set the default stub
$defaultStub = $phar->createDefaultStub('index.php');
// The default stub is executable
$phar->setStub("#!/usr/bin/php \n" . $defaultStub);
// Stop buffering
$phar->stopBuffering();
示例#22
0
<?php

$mindbody = new Phar("mboapi.phar");
$mindbody->startBuffering();
$files = new AppendIterator();
$files->append(new DirectoryIterator("services"));
$files->append(new DirectoryIterator("structures"));
$mindbody->buildFromIterator($files, dirname(__FILE__));
$mindbody->addFile("LICENSE");
$mindbody->addFile("README.markdown");
$mindbody->addFromString("loadServices.php", "<?php\n\tinclude_once(\"services/Appointment_Service.php\");\n\tinclude_once(\"services/Class_Service.php\");\n\tinclude_once(\"services/Client_Service.php\");\n\tinclude_once(\"services/Sale_Service.php\");\n\tinclude_once(\"services/Site_Service.php\");\n\tinclude_once(\"services/Staff_Service.php\");\n\tinclude_once(\"services/Data_Service.php\");\n\tinclude_once(\"services/Finder_Service.php\");\n?>");
$mindbody->setStub($mindbody->createDefaultStub("loadServices.php"));
$mindbody->stopBuffering();
foreach (new RecursiveIteratorIterator($mindbody) as $file) {
    echo $file->getFileName() . "\n";
}
示例#23
0
<?php

/**
 * Make a lots of Pharn!
 * 
 * @author Jan-David Siegl <*****@*****.**>
 * @since 09.08.2015
 */
$srcRoot = "src/";
$buildRoot = "build/";
$phar = new Phar($buildRoot . "/pharTest.phar", FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME, "pharTest.phar");
$phar['index.php'] = file_get_contents($srcRoot . "index.php");
$phar['AppManager.php'] = file_get_contents($srcRoot . "AppManager.php");
$phar->setStub($phar->createDefaultStub('index.php'));
copy($srcRoot . "config.ini", $buildRoot . "config.ini");
示例#24
0
$jobphar = "{$builddir}/{$jobname}.phar";
$jobsh = "{$builddir}/{$jobname}.sh";
if (isset($opts['t'])) {
    $tz = $opts['t'];
} else {
    $tz = date_default_timezone_get();
}
try {
    new DateTimeZone($tz);
} catch (Exception $e) {
    echo sprintf("Invalid timezone '%s'.\n\n", $tz);
    exit(1);
}
$phar = new Phar($jobphar, RecursiveDirectoryIterator::CURRENT_AS_FILEINFO | RecursiveDirectoryIterator::KEY_AS_FILENAME, 'my.phar');
$phar->startBuffering();
$stub = $phar->createDefaultStub('Hadoophp/_run.php', false);
// inject timezone and add shebang (substr cuts off the leading "<?php" bit)
$stub = "#!/usr/bin/env php\n<?php\ndate_default_timezone_set('{$tz}');\ndefine('HADOOPHP_DEBUG', " . var_export(isset($opts['debug']), true) . ");\n" . substr($stub, 5);
$phar->setStub($stub);
// for envs without phar, this will work and not create a checksum error, but invocation needs to be "php archive.phar then":
// $phar->setStub($phar->createDefaultStub('Hadoophp/_run.php', 'Hadoophp/_run.php'));
$buildDirectories = array(realpath(__DIR__ . '/../lib/'), realpath($jobdir));
if (isset($opts['i'])) {
    $buildDirectories = array_merge($buildDirectories, (array) $opts['i']);
}
$filterRegex = '#^((/|^)(?!\\.)[^/]*)+$#';
foreach ($buildDirectories as $path) {
    $phar->buildFromDirectory(realpath($path), $filterRegex);
}
$phar->stopBuffering();
if (file_exists("{$jobdir}/ARGUMENTS")) {
示例#25
0
<?php

// $srcRoot = __DIR__."/../";
// $buildRoot = __DIR__."/../../bin";
// $vendorRoot = __DIR__."/../../vendor";
//
// $phar = new Phar($buildRoot . "/juborm.phar", 0, "juborm.phar");
// $phar->buildFromDirectory("$srcRoot",'/.php$/');
// $files = $phar->buildFromDirectory("$vendorRoot/nategood/commando/src",'/.php$/');
// $files = $phar->buildFromDirectory("$vendorRoot/kevinlebrun/colors.php/lib",'/.php$/');
//
// $phar->setStub($phar->createDefaultStub('Assistant/bootloader.php'));
$srcRoot = __DIR__ . "/../..";
$buildRoot = __DIR__ . "/../../bin";
$phar = new Phar($buildRoot . "/juborm.phar", 0, "juborm.phar");
$files = $phar->buildFromDirectory("{$srcRoot}", '/.php$/');
$phar->setStub($phar->createDefaultStub('/src/Assistant/bootloader.php'));
示例#26
0
    $chn->in($target);
}
for ($i = 0; $i < $workers; ++$i) {
    $chn->in(null);
}
for ($i = 0; $i < $workers; ++$i) {
    $chn_done->out();
}
$chn->close();
$chn_done->close();
echo 'Building PHARs...';
$phars = ['fmt', 'refactor'];
foreach ($phars as $target) {
    file_put_contents($target . '.stub.php', '<?php namespace {$inPhar = true;} ' . preg_replace('/' . preg_quote('<?php') . '/', '', file_get_contents($target . '.stub.php'), 1));
    $phar = new Phar($target . '.phar', FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME, $target . '.phar');
    $phar[$target . '.stub.php'] = file_get_contents($target . '.stub.php');
    $phar->setStub('#!/usr/bin/env php' . "\n" . $phar->createDefaultStub($target . '.stub.php'));
    file_put_contents($target . '.phar.sha1', sha1_file($target . '.phar'));
    unlink($target . '.stub.php');
}
echo 'done', PHP_EOL;
$variants = ['.php' => 0755, '.phar' => 0755, '.phar.sha1' => 0444];
foreach ($targets as $target) {
    foreach ($variants as $variant => $permission) {
        if (file_exists($target . $variant)) {
            echo 'moving ', $target . $variant, ' to ..' . DIRECTORY_SEPARATOR . $target . $variant, PHP_EOL;
            rename($target . $variant, '..' . DIRECTORY_SEPARATOR . $target . $variant);
            chmod('..' . DIRECTORY_SEPARATOR . $target . $variant, $permission);
        }
    }
}
示例#27
0
#!/usr/bin/env php
<?php 
const PHAR_FILE = __DIR__ . '/../blackhole-bot.phar';
const EXEC_FILE = __DIR__ . '/../blackhole-bot';
$phar = new Phar(PHAR_FILE, 0, 'blackhole-bot.phar');
/**
 * Add files to phar
 */
$append = new AppendIterator();
$append->append(new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__ . '/../src/', FilesystemIterator::SKIP_DOTS)));
$append->append(new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__ . '/../vendor/', FilesystemIterator::SKIP_DOTS)));
$append->append(new ArrayIterator(['src/Config/Services/services.yml' => realpath(__DIR__ . '/../src/Config/Services/services.yml')]));
$phar->addFromString('bin/blackhole', str_replace('#!/usr/bin/env php', '', file_get_contents(__DIR__ . '/../bin/blackhole')));
/**
 * Build the phar
 */
$phar->buildFromIterator($append, __DIR__ . '/..');
// start buffering. Mandatory to modify stub.
$phar->startBuffering();
// Get the default stub. You can create your own if you have specific needs
$defaultStub = $phar->createDefaultStub('bin/blackhole');
// Adding files
$phar->buildFromDirectory(__DIR__, '/\\.php$/');
// Create a custom stub to add the shebang
$stub = "#!/usr/bin/env php \n" . $defaultStub;
// Add the stub
$phar->setStub($stub);
$phar->stopBuffering();
chmod(PHAR_FILE, 0755);
rename(PHAR_FILE, EXEC_FILE);
示例#28
0
<?php

$archive = new Phar('regression.phar');
$base = dirname(__FILE__);
$archive->buildFromIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($base . '/src')), $base);
$archive->buildFromIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($base . '/vendor')), $base);
$archive->setStub(Phar::createDefaultStub('vendor/autoload.php'));
示例#29
0
<?php

// Create a new htrouter phar file
@unlink('htrouter.phar');
$phar = new Phar('htrouter.phar', 0, 'htrouter.phar');
$basePath = realpath(dirname(__FILE__) . "/../htrouter");
$phar->buildFromDirectory($basePath, '/\\.php$/');
$phar->addFile(dirname(__FILE__) . '/stub.php', '/stub.php');
// Add stub
$phar->setStub($phar->createDefaultStub('stub.php', 'stub.php'));
示例#30
0
<?php

$phar = new Phar("compiler.phar", FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME, "compiler.phar");
$phar["index.php"] = file_get_contents("compiler.php");
$phar->setStub($phar->createDefaultStub("index.php"));