Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
localzet committed May 31, 2024
1 parent 9ed2e7f commit 51c4a6c
Showing 1 changed file with 34 additions and 9 deletions.
43 changes: 34 additions & 9 deletions master
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,57 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

use support\Container;
use Triangle\Console;
use Triangle\Console\Util;
use Triangle\Engine\Config;

require_once __DIR__ . '/vendor/autoload.php';

if (!in_array($argv[1] ?? '', ['start', 'restart', 'stop', 'status', 'reload', 'connections'])) {
require_once __DIR__ . '/support/bootstrap.php';
} else {
Config::load(config_path(), ['route', 'container']);
if (class_exists('Support\App')) {
Support\App::loadAllConfig(['route']);
} else {
Config::load(config_path(), ['route', 'container']);
}
}

$cli = new Console();
if (is_dir($command_path = app_path('command'))) {
$cli->setName('Triangle CLI');
$cli->installInternalCommands();
if (is_dir($command_path = Util::guessPath(app_path(), '/command', true))) {
$cli->installCommands($command_path);
}

foreach (config('plugin', []) as $firm => $projects) {
if (config("plugin.$firm.app", false)) continue;
if (isset($projects['app'])) {
if ($command_str = Util::guessPath(base_path() . "/plugin/$firm", 'command')) {
$command_path = base_path() . "/plugin/$firm/$command_str";
$cli->installCommands($command_path, "plugin\\$firm\\$command_str");
}
}
foreach ($projects as $name => $project) {
foreach ($project['command'] ?? [] as $command) {
$cli->add(new $command);
if (!is_array($project)) {
continue;
}
foreach ($project['command'] ?? [] as $class_name) {
$reflection = new ReflectionClass($class_name);
if ($reflection->isAbstract()) {
continue;
}
$properties = $reflection->getStaticProperties();
$name = $properties['defaultName'];
if (!$name) {
throw new RuntimeException("Command {$class_name} has no defaultName");
}
$description = $properties['defaultDescription'] ?? '';
$command = Container::get($class_name);
$command->setName($name)->setDescription($description);
$cli->add($command);
}
}
}

try {
$cli->run();
} catch (Exception $e) {
}
$cli->run();

0 comments on commit 51c4a6c

Please sign in to comment.