#!/usr/bin/env php set('db', function () use ($databaseConfig) { $adapter = 'Phalcon\Db\Adapter\Pdo\\' . $databaseConfig['adapter']; return new $adapter([ 'host' => $databaseConfig['host'], 'username' => $databaseConfig['username'], 'password' => $databaseConfig['password'], 'dbname' => $databaseConfig['dbname'], ]); }); $diContainer->setShared('config', function () { return include __DIR__ . '/../config/config.php'; }); $arguments = []; foreach ($argv as $k => $arg) { if ($k === 1) { $arguments['task'] = $arg; } elseif ($k === 2) { $arguments['action'] = $arg; } elseif ($k >= 3) { $arguments['params'][] = $arg; } } $tasks = include __DIR__ . '/../config/tasks.php'; if (!isset($arguments['task'])) { fwrite(STDERR, 'Available tasks:' . PHP_EOL); foreach ($tasks as $name => $config) { fwrite(STDERR, $name . ' - ' . $config['desc'] . PHP_EOL); } exit(0); } if (!isset($tasks[$arguments['task']])) { fwrite(STDERR, 'Task doesn\'t exist' . PHP_EOL); exit(1); } $task = $tasks[$arguments['task']]; $diContainer->set('dispatcher', function () use ($task) { $dispatcher = new Dispatcher(); $dispatcher->setDefaultNamespace($task['namespace']); return $dispatcher; }); $console = new Console($diContainer); try { $console->handle(['task' => $task['slug'], 'action' => $task['action'], 'params' => $arguments['params'] ?? null]); } catch (\Phalcon\Exception $e) { fwrite(STDERR, $e->getMessage() . PHP_EOL); exit(1); } catch (\Throwable $throwable) { fwrite(STDERR, $throwable->getMessage() . PHP_EOL); exit(1); }