Skip to content

Commit

Permalink
Merge branch 'master' of github.com:xp-framework/compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Jun 16, 2018
2 parents 7c3f1cc + ecf7f01 commit 031893d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
20 changes: 20 additions & 0 deletions src/main/php/xp/compiler/CompileOnly.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php namespace xp\compiler;

use io\streams\OutputStream;

class CompileOnly extends Output {

/**
* Returns the target for a given input
*
* @param string $name
* @return io.streams.OutputStream
*/
public function target($name) {
return newinstance(OutputStream::class, [], [
'write' => function($bytes) { },
'flush' => function() { },
'close' => function() { }
]);
}
}
13 changes: 10 additions & 3 deletions src/main/php/xp/compiler/CompileRunner.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@
* ```
* - Compile `src/main/php` and `src/test/php` to the `dist` folder.
* ```sh
* $ xp compile -o dist src/main/php/ src/test/php
* $ xp compile -o dist src/main/php/ src/test/php/
* ```
* - Compile `src/main/php`, do not write output
* ```sh
* $ xp compile -n src/main/php/
* ```
* - Target PHP 5.6 (default target is current PHP version)
* ```sh
* $ xp compile -t PHP.5.6 HelloWorld.php HelloWorld.class.php
* ```
*
* By using the *-o* option, you can pass multiple input sources
* following it.
* The *-o* and *-n* options accept multiple input sources following them.
*
* @see https://github.com/xp-framework/rfc/issues/299
*/
Expand All @@ -54,6 +57,10 @@ public static function main(array $args) {
$out= $args[++$i];
$in= array_slice($args, $i + 1);
break;
} else if ('-n' === $args[$i]) {
$out= null;
$in= array_slice($args, $i + 1);
break;
} else {
$in= $args[$i];
$out= isset($args[$i + 1]) ? $args[$i + 1] : '-';
Expand Down
4 changes: 3 additions & 1 deletion src/main/php/xp/compiler/Output.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ abstract class Output {
* @return self
*/
public static function newInstance($arg) {
if ('-' === $arg) {
if (null === $arg) {
return new CompileOnly();
} else if ('-' === $arg) {
return new ToStream(Console::$out->getStream());
} else if (strstr($arg, '.php')) {
return new ToFile($arg);
Expand Down

0 comments on commit 031893d

Please sign in to comment.