PHP Classes

File: bin/build

Recommend this page to a friend!
  Classes of Gabriel Couto   PHP Gameboy Emulator   bin/build   Download  
File: bin/build
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: PHP Gameboy Emulator
Emulate Gameboy console in a terminal in pure PHP
Author: By
Last change:
Date: 8 years ago
Size: 1,737 bytes
 

Contents

Class file image Download
#!/usr/bin/env php
<?php

use Symfony\Component\Finder\Finder;
use
Symfony\Component\Finder\SplFileInfo;

require_once(
__DIR__ . '/../vendor/autoload.php');

$rootDir = __DIR__ . '/..';

$filename = 'php-gameboy.phar';
$filePath = $rootDir . '/bin/' . $filename;
$stub = <<<STUB
#!/usr/bin/env php
<?php

Phar::mapPhar("php-gameboy.phar");

require_once("phar://php-gameboy.phar/php-terminal-gameboy-emulator/boot.php");

__HALT_COMPILER();

STUB;

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

$finderSort = function ($a, $b) {
    return
strcmp(strtr($a->getRealPath(), '\\', '/'), strtr($b->getRealPath(), '\\', '/'));
};

function
addFile($phar, $file)
{
   
$path = strtr(str_replace(dirname(dirname(__DIR__)).DIRECTORY_SEPARATOR, '', $file->getRealPath()), '\\', '/');

   
$content = file_get_contents($file);

   
$phar->addFromString($path, $content);
}

$phar = new Phar(
   
$filePath,
   
FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME,
   
$filename
);
$phar->setSignatureAlgorithm(\Phar::SHA1);
$phar->startBuffering();

addFile($phar, new SplFileInfo('boot.php', $rootDir . '/boot.php', 'boot.php'));
addFile($phar, new SplFileInfo('composer.json', $rootDir . '/composer.json', 'composer.json'));
addFile($phar, new SplFileInfo('vendor/autoload.php', $rootDir . '/vendor/autoload.php', 'vendor/autoload.php'));

$finder = new Finder();
$finder->files()
    ->
ignoreVCS(true)
    ->
name('*.php')
    ->
in([
       
$rootDir . '/src/',
       
$rootDir . '/vendor/composer',
       
$rootDir . '/vendor/whatthejeff',
    ])
    ->
sort($finderSort)
;

foreach (
$finder as $file) {
   
addFile($phar, $file);
}

$phar->setStub($stub);

$phar->stopBuffering();

chmod($filePath, 0775);