66 lines
1.3 KiB
PHP
66 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace MakePhar;
|
|
|
|
class Application
|
|
{
|
|
|
|
protected $config;
|
|
|
|
private function parseCommandLine()
|
|
{
|
|
$opts = "h";
|
|
$long = [ 'help' ];
|
|
|
|
$parsed = getopt($opts, $long);
|
|
$config = [
|
|
'help' => false,
|
|
'manifest' => getcwd()."/makephar.sdl",
|
|
'output' => null,
|
|
'compress' => false,
|
|
];
|
|
|
|
foreach ($parsed as $k=>$v) switch ($k) {
|
|
case 'h':
|
|
case 'help':
|
|
$config['help'] = true;
|
|
break;
|
|
}
|
|
|
|
$this->config = (object)$config;
|
|
}
|
|
|
|
private function printHelp()
|
|
{
|
|
printf("Usage: makephar [opts]\n");
|
|
printf("Options: -h,--help Show this help\n");
|
|
}
|
|
|
|
public function run()
|
|
{
|
|
$this->parseCommandLine();
|
|
|
|
if ($this->config->help) {
|
|
$this->printHelp();
|
|
return;
|
|
}
|
|
|
|
$this->buildManifest();
|
|
}
|
|
|
|
protected function buildManifest()
|
|
{
|
|
$manifests = Manifest::createFromFile($this->config->manifest);
|
|
|
|
foreach ($manifests as $manifest) {
|
|
log_info("Building %s", $manifest->getOutput());
|
|
$builder = new PharBuilder($manifest);
|
|
$builder->prepare();
|
|
$builder->build();
|
|
$builder->finalize();
|
|
}
|
|
|
|
}
|
|
|
|
}
|