Skip to content

Commit 6aa200a

Browse files
committed
Add bin
1 parent adc2e9c commit 6aa200a

3 files changed

Lines changed: 43 additions & 9 deletions

File tree

β€Žbin/Commands/JVM/RunCommand.phpβ€Ž

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<?php
22
namespace PHPJava\Console\Commands\JVM;
33

4+
use PHPJava\Core\JavaArchive;
5+
use PHPJava\Core\JavaClass;
6+
use PHPJava\Core\JVM\Parameters\GlobalOptions;
7+
use PHPJava\Core\Stream\Reader\FileReader;
48
use Symfony\Component\Console\Command\Command;
59
use Symfony\Component\Console\Input\InputArgument;
610
use Symfony\Component\Console\Input\InputDefinition;
@@ -36,24 +40,50 @@ protected function configure()
3640
'm',
3741
InputOption::VALUE_OPTIONAL,
3842
'Set run mode [jar|class]. Default is class.'
39-
)
40-
->addOption(
41-
'entrypoint',
42-
'e',
43-
InputOption::VALUE_OPTIONAL,
44-
'Overwrite entrypoint'
4543
);
4644
}
4745

4846
protected function execute(InputInterface $input, OutputInterface $output)
4947
{
5048
$settings = $input->getOption('settings') ?? [];
51-
$mode = $input->getOption('mode') ?? 'class';
52-
$entrypoint = $input->getOption('entrypoint') ?? null;
49+
$mode = strtolower($input->getOption('mode') ?? 'class');
5350
$file = $input->getArgument('file');
5451
$parameters = $input->getArgument('parameters');
5552

53+
// Set global options
54+
GlobalOptions::set($settings);
55+
56+
if ($mode === 'jar') {
57+
return $this->runJar($file, $parameters);
58+
} elseif ($mode === 'class') {
59+
return $this->runClass($file, $parameters);
60+
}
61+
62+
$output->writeln(
63+
'<error>Unable to run `' . $mode . '` mode.</error>'
64+
);
65+
}
5666

57-
var_dump($file);
67+
private function runJar(string $file, array $parameters)
68+
{
69+
$jar = new JavaArchive($file);
70+
$jar->execute(
71+
$parameters
72+
);
73+
}
74+
75+
private function runClass(string $file, array $parameters)
76+
{
77+
$class = new JavaClass(
78+
new FileReader($file)
79+
);
80+
$class
81+
->getInvoker()
82+
->getStatic()
83+
->getMethods()
84+
->call(
85+
'main',
86+
$parameters
87+
);
5888
}
5989
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/php
12
<?php
23
namespace PHPJava\Console;
34

β€Žcomposer.jsonβ€Ž

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
"name": "memory"
1010
}
1111
],
12+
"bin": [
13+
"bin/PHPJava"
14+
],
1215
"require": {
1316
"php": ">=7.2",
1417
"ext-zip": "*",

0 commit comments

Comments
Β (0)