From 299c831e82652c949fd1f83884cceecdd4784a09 Mon Sep 17 00:00:00 2001 From: Nick Zeng Date: Mon, 10 Nov 2025 16:49:05 +0800 Subject: [PATCH] add dev packages, caps Log util, add tools config --- backend/README.md | 63 ++------------------------ backend/app/Command/AppCompanySync.php | 31 +++++++++++++ backend/app/Utils/Log.php | 52 +++++++++++++++++++++ backend/composer.json | 5 +- backend/config/autoload/tools.php | 21 +++++++++ 5 files changed, 110 insertions(+), 62 deletions(-) create mode 100644 backend/app/Command/AppCompanySync.php create mode 100644 backend/app/Utils/Log.php create mode 100644 backend/config/autoload/tools.php diff --git a/backend/README.md b/backend/README.md index 7d7a10d..d7c753c 100644 --- a/backend/README.md +++ b/backend/README.md @@ -1,63 +1,6 @@ -# Introduction +## 开发记录: -This is a skeleton application using the Hyperf framework. This application is meant to be used as a starting place for those looking to get their feet wet with Hyperf Framework. -# Requirements +创建模型: -Hyperf has some requirements for the system environment, it can only run under Linux and Mac environment, but due to the development of Docker virtualization technology, Docker for Windows can also be used as the running environment under Windows. - -The various versions of Dockerfile have been prepared for you in the [hyperf/hyperf-docker](https://github.com/hyperf/hyperf-docker) project, or directly based on the already built [hyperf/hyperf](https://hub.docker.com/r/hyperf/hyperf) Image to run. - -When you don't want to use Docker as the basis for your running environment, you need to make sure that your operating environment meets the following requirements: - - - PHP >= 8.1 - - Any of the following network engines - - Swoole PHP extension >= 5.0,with `swoole.use_shortname` set to `Off` in your `php.ini` - - Swow PHP extension >= 1.3 - - JSON PHP extension - - Pcntl PHP extension - - OpenSSL PHP extension (If you need to use the HTTPS) - - PDO PHP extension (If you need to use the MySQL Client) - - Redis PHP extension (If you need to use the Redis Client) - - Protobuf PHP extension (If you need to use the gRPC Server or Client) - -# Installation using Composer - -The easiest way to create a new Hyperf project is to use [Composer](https://getcomposer.org/). If you don't have it already installed, then please install as per [the documentation](https://getcomposer.org/download/). - -To create your new Hyperf project: - -```bash -composer create-project hyperf/hyperf-skeleton path/to/install -``` - -If your development environment is based on Docker you can use the official Composer image to create a new Hyperf project: - -```bash -docker run --rm -it -v $(pwd):/app composer create-project --ignore-platform-reqs hyperf/hyperf-skeleton path/to/install -``` - -# Getting started - -Once installed, you can run the server immediately using the command below. - -```bash -cd path/to/install -php bin/hyperf.php start -``` - -Or if in a Docker based environment you can use the `docker-compose.yml` provided by the template: - -```bash -cd path/to/install -docker-compose up -``` - -This will start the cli-server on port `9501`, and bind it to all network interfaces. You can then visit the site at `http://localhost:9501/` which will bring up Hyperf default home page. - -## Hints - -- A nice tip is to rename `hyperf-skeleton` of files like `composer.json` and `docker-compose.yml` to your actual project name. -- Take a look at `config/routes.php` and `app/Controller/IndexController.php` to see an example of a HTTP entrypoint. - -**Remember:** you can always replace the contents of this README.md file to something that fits your project description. +`php ./bin/hyperf.php gen:model -F --with-comments --with-ide --property-case 0 -R companies` \ No newline at end of file diff --git a/backend/app/Command/AppCompanySync.php b/backend/app/Command/AppCompanySync.php new file mode 100644 index 0000000..254adb5 --- /dev/null +++ b/backend/app/Command/AppCompanySync.php @@ -0,0 +1,31 @@ +setDescription('Sync companies from Tools Dashboard'); + } + + public function handle() + { + $companies = + + $this->line('Hello Hyperf!', 'info'); + } +} diff --git a/backend/app/Utils/Log.php b/backend/app/Utils/Log.php new file mode 100644 index 0000000..7a8aca5 --- /dev/null +++ b/backend/app/Utils/Log.php @@ -0,0 +1,52 @@ +get(LoggerFactory::class)->get($channel); + } + + /** + * 选择日志频道(链式调用) + * + * @param string $channel 日志频道名称 + * @return LoggerInterface + * + * @example Log::channel('custom')->error('Error message') + * @example Log::channel('api')->info('API request', ['url' => '/api/users']) + * @example Log::channel('database')->debug('Query executed', ['sql' => 'SELECT * FROM users']) + */ + public static function channel(string $channel): LoggerInterface + { + return self::get($channel); + } + + /** + * 魔术方法:静态调用日志方法(使用默认频道 'app') + * 支持的日志级别:emergency, alert, critical, error, warning, notice, info, debug + * + * @param string $method 方法名(日志级别) + * @param array $args 参数数组 + * @return void + * + * @example Log::error('Error message', ['context' => 'data']) + * @example Log::info('Info message') + */ + public static function __callStatic(string $method, array $args): void + { + self::get()->$method(...$args); + } +} \ No newline at end of file diff --git a/backend/composer.json b/backend/composer.json index a89816f..7b4a416 100644 --- a/backend/composer.json +++ b/backend/composer.json @@ -24,7 +24,7 @@ "hyperf/db-connection": "~3.1.0", "hyperf/engine": "^2.10", "hyperf/framework": "~3.1.0", - "hyperf/guzzle": "~3.1.0", + "hyperf/guzzle": "^3.1", "hyperf/http-server": "~3.1.0", "hyperf/logger": "~3.1.0", "hyperf/memory": "~3.1.0", @@ -36,7 +36,8 @@ "hyperf/testing": "~3.1.0", "mockery/mockery": "^1.0", "phpstan/phpstan": "^1.0", - "swoole/ide-helper": "^5.0" + "swoole/ide-helper": "^5.0", + "symfony/var-dumper": "~v7.3" }, "suggest": { "ext-openssl": "Required to use HTTPS.", diff --git a/backend/config/autoload/tools.php b/backend/config/autoload/tools.php new file mode 100644 index 0000000..6912a72 --- /dev/null +++ b/backend/config/autoload/tools.php @@ -0,0 +1,21 @@ + false, + 'host' => env('TOOLS_HOST', 'http://127.0.0.1'), + 'host_test' => env('TOOLS_HOST', 'http://127.0.0.1'), + 'token' => env('TOOLS_TOKEN', ''), + 'token_test' => env('TOOLS_TOKEN', '') +];