bakaphp /
phalcon-api
| 1 | <?php |
||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Gewaer\Bootstrap; |
||
| 6 | |||
| 7 | use function Gewaer\Core\appPath; |
||
| 8 | use Phalcon\Cli\Console; |
||
| 9 | use Phalcon\Di\FactoryDefault\Cli as PhCli; |
||
| 10 | |||
| 11 | /** |
||
| 12 | * Class Cli |
||
| 13 | * |
||
| 14 | * @package Gewaer\Bootstrap |
||
| 15 | * |
||
| 16 | * @property Console $application |
||
| 17 | */ |
||
| 18 | class Cli extends AbstractBootstrap |
||
| 19 | {
|
||
| 20 | private $argv; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Run the application |
||
| 24 | * |
||
| 25 | * @return mixed |
||
| 26 | */ |
||
| 27 | public function run() |
||
| 28 | {
|
||
| 29 | return $this->application->handle($this->options); |
||
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @return mixed |
||
| 34 | */ |
||
| 35 | public function setup() |
||
| 36 | {
|
||
| 37 | $this->container = new PhCli(); |
||
| 38 | $this->providers = require appPath('cli/config/providers.php');
|
||
| 39 | |||
| 40 | $this->processArguments(); |
||
| 41 | |||
| 42 | parent::setup(); |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Setup the application object in the container |
||
| 47 | * |
||
| 48 | * @return void |
||
| 49 | */ |
||
| 50 | protected function setupApplication() |
||
| 51 | {
|
||
| 52 | $this->application = new Console($this->container); |
||
| 53 | $this->container->setShared('application', $this->application);
|
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Pass php argv |
||
| 58 | * |
||
| 59 | * @param array $argv |
||
| 60 | * @return void |
||
| 61 | */ |
||
| 62 | public function setArgv(array $argv): void |
||
| 63 | {
|
||
| 64 | $this->argv = $argv; |
||
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Parses arguments from the command line |
||
| 69 | */ |
||
| 70 | private function processArguments() |
||
| 71 | {
|
||
| 72 | $arguments = []; |
||
| 73 | foreach ($this->argv as $k => $arg) {
|
||
| 74 | if ($k == 1) {
|
||
| 75 | $arguments['task'] = $arg; |
||
| 76 | } elseif ($k == 2) {
|
||
| 77 | $arguments['action'] = $arg; |
||
| 78 | } elseif ($k >= 3) {
|
||
| 79 | $arguments['params'][] = $arg; |
||
| 80 | } |
||
| 81 | } |
||
| 82 | |||
| 83 | $this->options = $arguments; |
||
| 84 | } |
||
| 85 | } |
||
| 86 |