-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,10 @@ | |
|
||
namespace MacFJA\PharBuilder\Commands; | ||
|
||
use MacFJA\PharBuilder\PharBuilder; | ||
use League\Event\Event; | ||
use MacFJA\PharBuilder\Application; | ||
use MacFJA\PharBuilder\Event\ComposerAwareEvent; | ||
use MacFJA\PharBuilder\Event\PharAwareEvent; | ||
use Symfony\Component\Console\Exception\InvalidArgumentException; | ||
use Symfony\Component\Console\Exception\RuntimeException; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
|
@@ -33,6 +36,7 @@ class Package extends Base | |
*/ | ||
protected function configure() | ||
{ | ||
$resourcePath = __DIR__.DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'resource'; | ||
$this->setName('package') | ||
->addArgument( | ||
'composer', | ||
|
@@ -66,21 +70,9 @@ protected function configure() | |
'List of directories to add in Phar' | ||
) | ||
->setHelp( | ||
file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'package-help.txt') . | ||
file_get_contents($resourcePath . DIRECTORY_SEPARATOR .'package-help.txt') . | ||
$this->codeHelpParagraph( | ||
<<< CODE | ||
<info>... The content of your composer.json file</info> | ||
"extra": { | ||
"phar-builder": { | ||
"compression": "GZip", | ||
"name": "application.phar", | ||
"output-dir": "../", | ||
"entry-point": "./index.php", | ||
"include": ["bin","js","css"], | ||
"include-dev": false | ||
} | ||
} | ||
CODE | ||
file_get_contents($resourcePath . DIRECTORY_SEPARATOR .'package-extra-example.txt') | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
MacFJA
Author
Owner
|
||
) | ||
) | ||
->setDescription('Create a Phar file from a composer.json'); | ||
|
@@ -137,7 +129,26 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
$outputDir = $this->readParamComposerAsk($extraData, $input, $output, $baseDir, 'output-dir'); | ||
$includes = $this->readParamComposerAsk($extraData, $input, $output, $baseDir, 'include'); | ||
|
||
new PharBuilder($this->ioStyle, $composerFile, $outputDir, $name, $stubFile, $compression, $includes, $keepDev); | ||
/** | ||
* The application | ||
* | ||
* @var Application $app | ||
*/ | ||
$app = $this->getApplication(); | ||
$builder = $app->getBuilder(); | ||
$builder->setComposer($composerFile); | ||
$builder->setOutputDir($outputDir); | ||
$builder->setPharName($name); | ||
$builder->setStubFile($stubFile); | ||
$builder->setCompression($compression); | ||
$builder->setIncludes($includes); | ||
$builder->setKeepDev($keepDev); | ||
|
||
$app->emit(new PharAwareEvent('build.before', $builder)); | ||
|
||
$builder->buildPhar(); | ||
|
||
$app->emit(new ComposerAwareEvent('build.after', $builder->getComposerReader())); | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace MacFJA\PharBuilder\Event; | ||
|
||
use League\Event\AbstractListener; | ||
use League\Event\EventInterface; | ||
use Symfony\Component\Process\Process; | ||
|
||
/** | ||
* Class ApplicationListener. | ||
* | ||
* @package Event | ||
* @author MacFJA | ||
* @license MIT | ||
*/ | ||
class ApplicationListener extends AbstractListener | ||
{ | ||
|
||
/** | ||
* Handle an event. | ||
* | ||
* @param EventInterface $event The event to handle | ||
* | ||
* @return void | ||
*/ | ||
public function handle(EventInterface $event) | ||
{ | ||
if (!($event instanceof ComposerAwareEvent)) { | ||
return; | ||
} | ||
$data = $event->getComposerReader()->getComposerConfig(); | ||
|
||
if (!array_key_exists('events', $data) || !array_key_exists($event->getName(), $data['events'])) { | ||
return; | ||
} | ||
|
||
$actions = $data['events'][$event->getName()]; | ||
This comment has been minimized.
Sorry, something went wrong.
kelunik
Contributor
|
||
if (!is_array($actions)) { | ||
$actions = array($actions); | ||
} | ||
|
||
foreach ($actions as $action) { | ||
$process = new Process($action, dirname($event->getComposerReader()->getComposerJsonPath())); | ||
$process->run(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace MacFJA\PharBuilder\Event; | ||
|
||
use League\Event\Event; | ||
use MacFJA\PharBuilder\Utils\Composer; | ||
|
||
/** | ||
* Class ComposerAwareEvent. | ||
* | ||
* @package MacFJA\PharBuilder\Event | ||
* @author MacFJA | ||
* @license MIT | ||
*/ | ||
class ComposerAwareEvent extends Event | ||
{ | ||
/** | ||
* The phar builder | ||
* | ||
* @var Composer | ||
*/ | ||
protected $composerReader; | ||
/** | ||
* Create a new event instance. | ||
* | ||
* @param string $name The new event name | ||
* @param Composer $composer The PharBuilder | ||
*/ | ||
public function __construct($name, $composer) | ||
{ | ||
$this->composerReader = $composer; | ||
parent::__construct($name); | ||
} | ||
|
||
/** | ||
* Get the composer reader object | ||
* | ||
* @return Composer | ||
*/ | ||
public function getComposerReader() | ||
{ | ||
return $this->composerReader; | ||
} | ||
|
||
/** | ||
* Create a new event instance. | ||
* | ||
* @param string $name The new event name | ||
* @param Composer $composer The PharBuilder | ||
* | ||
* @return static | ||
*/ | ||
public static function named($name, $composer) | ||
{ | ||
return new static($name, $composer); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace MacFJA\PharBuilder\Event; | ||
|
||
use MacFJA\PharBuilder\PharBuilder; | ||
|
||
/** | ||
* Class PharAwareEvent. | ||
* | ||
* @package MacFJA\PharBuilder\Event | ||
* @author MacFJA | ||
* @license MIT | ||
*/ | ||
class PharAwareEvent extends ComposerAwareEvent | ||
{ | ||
/** | ||
* The phar builder | ||
* | ||
* @var PharBuilder | ||
*/ | ||
protected $pharContext; | ||
/** | ||
* Create a new event instance. | ||
* | ||
* @param string $name The new event name | ||
* @param PharBuilder $builder The PharBuilder | ||
*/ | ||
public function __construct($name, $builder) | ||
{ | ||
$this->pharContext = $builder; | ||
parent::__construct($name, $builder->getComposerReader()); | ||
} | ||
|
||
/** | ||
* Get the PHAR builder | ||
* | ||
* @return PharBuilder | ||
*/ | ||
public function getPhar() | ||
{ | ||
return $this->pharContext; | ||
} | ||
|
||
/** | ||
* Create a new event instance. | ||
* | ||
* @param string $name The new event name | ||
* @param PharBuilder $builder The PharBuilder | ||
* | ||
* @return static | ||
*/ | ||
public static function named($name, $builder) | ||
{ | ||
return new static($name, $builder); | ||
} | ||
} |
Do you know that you can just use
/
and PHP will automatically normalize it?