-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHelloWorld
executable file
·34 lines (27 loc) · 1.17 KB
/
HelloWorld
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env php
<?php
require __DIR__.'/vendor/autoload.php';
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
(new Application('Hello World', '1.0.0'))
->register('greet')
->addArgument('name', InputArgument::OPTIONAL, 'Name of the person')
->addOption('say', null, InputOption::VALUE_REQUIRED, 'Custom greeting')
->setCode(function (InputInterface $input, OutputInterface $output) {
$name = $input->getArgument('name');
$greeting = $input->getOption('say');
if (!empty($name) && !empty($greeting)) {
return $output->writeln("<info>$greeting $name!</info>");
} else if (!empty($name)) {
return $output->writeln("<info>Hello $name!</info>");
} else if (!empty($greeting)) {
return $output->writeln("<info>$greeting World!</info>");
} else {
return $output->writeln("<info>Hello World!</info>");
}
})
->getApplication()
->run();