Skip to content

Commit

Permalink
Command to generate phar file
Browse files Browse the repository at this point in the history
  • Loading branch information
renatocassino committed Jan 20, 2019
1 parent 0832a9c commit 2d6bf4c
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
dephpugger.phar.gz
composer.phar
phpunit.phar
/vendor/
Expand Down
22 changes: 11 additions & 11 deletions bin/dephpugger
Expand Up @@ -2,20 +2,20 @@
<?php

function findInnerPart($search, $parts=[]) {
do {
$part = array_pop($parts);
} while(($part != $search) && (count($parts) > 1));
return implode(DIRECTORY_SEPARATOR, $parts);
do {
$part = array_pop($parts);
} while(($part != $search) && (count($parts) > 1));
return implode(DIRECTORY_SEPARATOR, $parts);
}

function autoload_path($dir) {
$pathParts = explode(DIRECTORY_SEPARATOR, $dir);
if(in_array('vendor', $pathParts, true)) {
return findInnerPart('vendor', $pathParts);
} else if(in_array('bin', $pathParts, true)) {
return findInnerPart('bin', $pathParts);
}
throw new Exception("Can't find any base-paths. Please keep file within repository");
$pathParts = explode(DIRECTORY_SEPARATOR, $dir);
if(in_array('vendor', $pathParts, true)) {
return findInnerPart('vendor', $pathParts);
} else if(in_array('bin', $pathParts, true)) {
return findInnerPart('bin', $pathParts);
}
throw new Exception("Can't find any base-paths. Please keep file within repository");
}

$basePath = autoload_path(__DIR__);
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -18,7 +18,7 @@
"autoload": {
"psr-4" : {
"Dephpug\\": "src/Dephpug",
"Dephpug\\Console\\": "console/"
"Dephpug\\Console\\": "src/Dephpug/Console/"
},
"files": [
"src/Dephpug/SplashScreen.php",
Expand Down
22 changes: 22 additions & 0 deletions create-phar.php
@@ -0,0 +1,22 @@
<?php

$pharFile = 'dephpugger.phar';

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

if (file_exists($pharFile . '.gz')) {
unlink ($pharFile . '.gz');
}

$phar = new Phar($pharFile, 0, $pharFile);
$phar->setSignatureAlgorithm(Phar::SHA1);
$phar->buildFromDirectory('.', "/(bin|src|vendor).*(?:\.php|dephpugger)$/i");
$phar->setDefaultStub('./bin/dephpugger');
$phar->compress(Phar::GZ);

$phar->setStub("#!/usr/bin/env php\n<?php Phar::mapPhar('dephpugger.phar'); require 'phar://dephpugger.phar/bin/dephpugger'; __HALT_COMPILER();");

echo "File $pharFile created!";

Binary file added dephpugger.phar
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 2d6bf4c

Please sign in to comment.