39 Star 200 Fork 65

funadmin/webmanadmin

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
think 2.84 KB
一键复制 编辑 原始数据 按行查看 历史
funadmin 提交于 2025-09-09 22:26 +08:00 . chore: 更新项目配置文件和忽略项
#!/usr/bin/env php
<?php
/**
* FunAdmin ThinkPHP风格命令行工具
* ============================================================================
* 提供类似ThinkPHP的命令行接口,底层使用Webman命令系统
* ============================================================================
* Usage: php think [command] [options]
* Examples:
* php think make:controller User
* php think make:model User
* php think curd --table=users
* php think addon --name=demo
*/
use Webman\Config;
use fun\console\ThinkCommand;
use Webman\Console\Util;
use support\Container;
use Dotenv\Dotenv;
if (!Phar::running()) {
chdir(__DIR__);
}
require_once __DIR__ . '/vendor/autoload.php';
if (!$appConfigFile = config_path('app.php')) {
throw new RuntimeException('Config file not found: app.php');
}
if (class_exists(Dotenv::class) && file_exists(run_path('.env'))) {
if (method_exists(Dotenv::class, 'createUnsafeImmutable')) {
Dotenv::createUnsafeImmutable(run_path())->load();
} else {
Dotenv::createMutable(run_path())->load();
}
}
$appConfig = require $appConfigFile;
if ($timezone = $appConfig['default_timezone'] ?? '') {
date_default_timezone_set($timezone);
}
if ($errorReporting = $appConfig['error_reporting'] ?? '') {
error_reporting($errorReporting);
}
// 不需要处理 webman 服务命令(start, stop, restart等),这些保留给webman脚本
require_once __DIR__ . '/support/bootstrap.php';
// 创建 ThinkPHP 风格的命令行工具
$cli = new ThinkCommand();
$cli->setName('think cli');
$cli->installThinkCommands();
// 加载自定义命令
if (is_dir($command_path = Util::guessPath(app_path(), '/command', true))) {
$cli->installCommands($command_path);
}
// 加载自定义命令配置
$customCommands = config('command', []);
foreach ($customCommands as $commandClass) {
if (class_exists($commandClass)) {
try {
$cli->add(new $commandClass());
} catch (\Exception $e) {
// 忽略命令初始化错误,继续加载其他命令
error_log("Failed to load command {$commandClass}: " . $e->getMessage());
}
}
}
// 加载插件命令
foreach (config('plugin', []) as $firm => $projects) {
if (isset($projects['app'])) {
foreach (['', '/app'] as $app) {
if ($command_str = Util::guessPath(base_path() . "/plugin/$firm{$app}", 'command')) {
$command_path = base_path() . "/plugin/$firm{$app}/$command_str";
$cli->installCommands($command_path, "plugin\\$firm" . str_replace('/', '\\', $app) . "\\$command_str");
}
}
}
foreach ($projects as $name => $project) {
if (!is_array($project)) {
continue;
}
$project['command'] ??= [];
array_walk($project['command'], [$cli, 'createCommandInstance']);
}
}
$cli->run();
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/funadmin/webmanadmin.git
git@gitee.com:funadmin/webmanadmin.git
funadmin
webmanadmin
webmanadmin
main

搜索帮助