mirror of
http://124.126.16.154:8888/singularity/hdk-skeleton.git
synced 2026-01-15 03:35:06 +08:00
init: 初始化项目
This commit is contained in:
9
.gitignore
vendored
Normal file
9
.gitignore
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
# IDEs
|
||||
.idea/
|
||||
.vscode/
|
||||
|
||||
# Build Dists
|
||||
vendor/
|
||||
composer.phar
|
||||
.phpunit.result.cache
|
||||
runtime/
|
||||
22
.php-cs-fixer.dist.php
Normal file
22
.php-cs-fixer.dist.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
* .php-cs-fixer.dist.php@HDK-Core
|
||||
*
|
||||
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
|
||||
* Powered by PhpStorm
|
||||
* Created on 2023/1/9
|
||||
*/
|
||||
|
||||
$finder = PhpCsFixer\Finder::create()->in([
|
||||
__DIR__ . '/app',
|
||||
__DIR__ . '/test',
|
||||
]);
|
||||
|
||||
$config = new PhpCsFixer\Config();
|
||||
return $config->setRules([
|
||||
'@PSR12' => true,
|
||||
'strict_param' => true,
|
||||
'array_syntax' => ['syntax' => 'short'],
|
||||
])
|
||||
->setUsingCache(false)
|
||||
->setFinder($finder);
|
||||
68
.versionrc
Normal file
68
.versionrc
Normal file
@@ -0,0 +1,68 @@
|
||||
{
|
||||
"header": "# 版本更新日志",
|
||||
"preMajor": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "feat",
|
||||
"section": "✨ Features | 新功能"
|
||||
},
|
||||
{
|
||||
"type": "fix",
|
||||
"section": "🐛 Bug Fixes | Bug 修复"
|
||||
},
|
||||
{
|
||||
"type": "init",
|
||||
"section": "🎉 Init | 初始化"
|
||||
},
|
||||
{
|
||||
"type": "docs",
|
||||
"section": "✏️ Documentation | 文档"
|
||||
},
|
||||
{
|
||||
"type": "style",
|
||||
"section": "💄 Styles | 风格"
|
||||
},
|
||||
{
|
||||
"type": "refactor",
|
||||
"section": "♻️ Code Refactoring | 代码重构"
|
||||
},
|
||||
{
|
||||
"type": "perf",
|
||||
"section": "⚡ Performance Improvements | 性能优化"
|
||||
},
|
||||
{
|
||||
"type": "tests",
|
||||
"section": "✅ Tests | 测试"
|
||||
},
|
||||
{
|
||||
"type": "test",
|
||||
"section": "✅ Tests | 测试"
|
||||
},
|
||||
{
|
||||
"type": "revert",
|
||||
"section": "⏪ Revert | 回退"
|
||||
},
|
||||
{
|
||||
"type": "build",
|
||||
"section": "📦 Build System | 打包构建"
|
||||
},
|
||||
{
|
||||
"type": "chore",
|
||||
"section": "🚀 Chore | 构建/工程依赖/工具"
|
||||
},
|
||||
{
|
||||
"type": "ci",
|
||||
"section": "👷 Continuous Integration | CI 配置"
|
||||
}
|
||||
],
|
||||
"bumpFiles": [
|
||||
{
|
||||
"filename": "VERSION_TRACKER.txt",
|
||||
"type": "plain-text"
|
||||
},
|
||||
{
|
||||
"filename": "composer.json",
|
||||
"type": "json"
|
||||
}
|
||||
]
|
||||
}
|
||||
25
CHANGELOG.md
Normal file
25
CHANGELOG.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# 版本更新日志
|
||||
### [0.2.2](http://124.126.16.154:8888/singularity/composer-template/compare/v0.2.1...v0.2.2) (2023-03-15)
|
||||
|
||||
### [0.2.1](http://124.126.16.154:8888/singularity/composer-template/compare/v0.2.0...v0.2.1) (2023-03-15)
|
||||
|
||||
|
||||
### 📦 Build System | 打包构建
|
||||
|
||||
* **composer:** 更新依赖,修复ci ([e6a4ee6](http://124.126.16.154:8888/singularity/composer-template/commit/e6a4ee6fa7f081e1612249c96fe4c34878b7635e))
|
||||
|
||||
## 0.2.0 (2023-03-15)
|
||||
|
||||
|
||||
### 📦 Build System | 打包构建
|
||||
|
||||
* **composer:** 更新仓库名 ([1873e46](http://124.126.16.154:8888/singularity/composer-template/commit/1873e469b01cddabf652c477462097795451cf43))
|
||||
* **composer:** 更新包类型 ([f52386b](http://124.126.16.154:8888/singularity/composer-template/commit/f52386bdc63ab0123a306992f93ac45c0d686afd))
|
||||
* **composer:** 更新配置 ([48e5b85](http://124.126.16.154:8888/singularity/composer-template/commit/48e5b852b362c5591f4286aedfaec97cf56d87f6))
|
||||
* **git:** 更新忽略文件 ([ec43564](http://124.126.16.154:8888/singularity/composer-template/commit/ec435643c3116b767fee449a2f9678e8e83e9eaa))
|
||||
|
||||
|
||||
### ✨ Features | 新功能
|
||||
|
||||
* init scripts ([30de628](http://124.126.16.154:8888/singularity/composer-template/commit/30de62841b6eeedccb80aa648bc89ec9e54d07a0))
|
||||
* 适配 hdk ([8613e75](http://124.126.16.154:8888/singularity/composer-template/commit/8613e750aae4ff5fa69cdc8eaf97554e67494827))
|
||||
59
Dockerfile
Normal file
59
Dockerfile
Normal file
@@ -0,0 +1,59 @@
|
||||
# Default Dockerfile
|
||||
#
|
||||
# @link https://studio.luxcreo.cn/
|
||||
# @contact dongyun.li@luxcreo.cn
|
||||
|
||||
FROM harbor.luxcreo.cn/library/hyperf:8.1-swoole
|
||||
LABEL maintainer="李东云 <dongyun.li@luxcreo.ai>" version="1.0" license="MIT" app.name="LuxStudio"
|
||||
|
||||
##
|
||||
# ---------- env settings ----------
|
||||
##
|
||||
# --build-arg timezone=Asia/Shanghai
|
||||
ARG timezone
|
||||
ARG db
|
||||
ARG app_env
|
||||
ARG site
|
||||
ARG idp_id
|
||||
ARG idp_assertion_url
|
||||
ARG idp_logout_url
|
||||
ARG acs_url
|
||||
ARG landing_host
|
||||
ARG oss_upload_host
|
||||
ARG oss_callback_api
|
||||
ARG cookie_domain
|
||||
|
||||
ENV TIMEZONE=${timezone:-"Asia/Shanghai"} \
|
||||
APP_ENV=${app_env} \
|
||||
DB_HOST=${db} \
|
||||
SITE=${site} \
|
||||
IDP_ID=${idp_id} \
|
||||
IDP_ASSERTION_URL=${idp_assertion_url} \
|
||||
IDP_LOGOUT_URL=${idp_logout_url} \
|
||||
ACS_URL=${acs_url} \
|
||||
LANDING_HOST=${landing_host} \
|
||||
OSS_UPLOAD_HOST=${oss_upload_host} \
|
||||
OSS_CALLBACK_API=${oss_callback_api} \
|
||||
COOKIE_DOMAIN=${cookie_domain}
|
||||
|
||||
# 设置时区
|
||||
RUN set -ex \
|
||||
# ---------- some config ----------
|
||||
&& cd /etc/php81 \
|
||||
# - config PHP
|
||||
&& echo "date.timezone=${TIMEZONE}" >> conf.d/99_overrides.ini \
|
||||
# - config timezone
|
||||
&& ln -sf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime \
|
||||
&& echo "${TIMEZONE}" > /etc/timezone \
|
||||
# ---------- clear works ----------
|
||||
&& echo -e "\033[42;37m Build Completed :).\033[0m\n"
|
||||
|
||||
# Composer Cache
|
||||
#COPY auth.json /root/.composer/auth.json
|
||||
COPY composer.* ./
|
||||
RUN composer install --no-dev --no-scripts
|
||||
|
||||
COPY . ./
|
||||
RUN composer dump-autoload -o && php bin/hyperf.php
|
||||
|
||||
ENTRYPOINT ["php", "/srv/www/bin/hyperf.php", "start"]
|
||||
22
LICENCE.md
Normal file
22
LICENCE.md
Normal file
@@ -0,0 +1,22 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020 Elliot J. Reed
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
69
README.md
Normal file
69
README.md
Normal file
@@ -0,0 +1,69 @@
|
||||
# PHP Package Skeleton / Example Project
|
||||
|
||||
This repository shows a basic setup for a PHP package or application in PHP.
|
||||
|
||||
## PHP Versions
|
||||
|
||||
This version will work on PHP version 8.0 and above.
|
||||
|
||||
For a version which is compatible with PHP 7.4 and above select the 7.4 Git tag ([github.com/elliotjreed/php-package-boilerplate/tree/7.4](https://github.com/elliotjreed/php-package-boilerplate/tree/7.4)).
|
||||
|
||||
## Getting Started
|
||||
|
||||
PHP 8.0 or above and Composer is expected to be installed on our system.
|
||||
|
||||
### Installing Composer
|
||||
|
||||
For instructions on how to install Composer visit [getcomposer.org](https://getcomposer.org/download/).
|
||||
|
||||
### Installing
|
||||
|
||||
After cloning this repository, change into the newly created directory and run
|
||||
|
||||
```bash
|
||||
composer install
|
||||
```
|
||||
|
||||
or if you have installed Composer locally in your current directory
|
||||
|
||||
```bash
|
||||
php composer.phar install
|
||||
```
|
||||
|
||||
This will install all dependencies needed for the project.
|
||||
|
||||
## Running the Tests
|
||||
|
||||
All tests can be run by executing
|
||||
|
||||
```bash
|
||||
vendor/bin/phpunit
|
||||
```
|
||||
|
||||
`phpunit` will automatically find all tests inside the `test` directory and run them based on the configuration in the `phpunit.xml` file.
|
||||
|
||||
### Testing Approach
|
||||
|
||||
The test for the class `Greeting` verifies that the return value of the `sayHello` method returns the string "Hello {name}", where {name} is the value passed through to the constructor.
|
||||
|
||||
## Running the Application
|
||||
|
||||
PHP has an in-built server for local development. This can be started by executing
|
||||
|
||||
```
|
||||
php -S localhost:8000 -t public
|
||||
```
|
||||
|
||||
Then open your browser at `http://localhost:8000/example.php`
|
||||
|
||||
You should see the text "Hello Ada Lovelace" on your screen.
|
||||
|
||||
## Built With
|
||||
|
||||
- [PHP](https://secure.php.net/)
|
||||
- [Composer](https://getcomposer.org/)
|
||||
- [PHPUnit](https://phpunit.de/)
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the MIT License - see the [LICENCE.md](LICENCE.md) file for details.
|
||||
34
app/Controller/Api/IndexController.php
Normal file
34
app/Controller/Api/IndexController.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
*
|
||||
* @link https://www.hyperf.io
|
||||
* @document https://hyperf.wiki
|
||||
* @contact group@hyperf.io
|
||||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
namespace App\Controller\Api;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Singularity\HDK\Core\Controller\AbstractController;
|
||||
|
||||
class IndexController extends AbstractController
|
||||
{
|
||||
public function index(): ResponseInterface
|
||||
{
|
||||
$method = $this->request->getMethod();
|
||||
|
||||
return $this->response->json(
|
||||
[
|
||||
'code' => 200,
|
||||
'message' => "Hello LuxStudio.",
|
||||
'data' => [
|
||||
'method' => $method,
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
23
bin/hyperf.php
Normal file
23
bin/hyperf.php
Normal file
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
ini_set('display_errors', 'on');
|
||||
ini_set('display_startup_errors', 'on');
|
||||
ini_set('memory_limit', '1G');
|
||||
|
||||
error_reporting(E_ALL);
|
||||
|
||||
! defined('BASE_PATH') && define('BASE_PATH', dirname(__DIR__, 1));
|
||||
! defined('SWOOLE_HOOK_FLAGS') && define('SWOOLE_HOOK_FLAGS', SWOOLE_HOOK_ALL);
|
||||
|
||||
require BASE_PATH . '/vendor/autoload.php';
|
||||
|
||||
// Self-called anonymous function that creates its own scope and keep the global namespace clean.
|
||||
(function () {
|
||||
Hyperf\Di\ClassLoader::init();
|
||||
/** @var Psr\Container\ContainerInterface $container */
|
||||
$container = require BASE_PATH . '/config/container.php';
|
||||
|
||||
$application = $container->get(Hyperf\Contract\ApplicationInterface::class);
|
||||
$application->run();
|
||||
})();
|
||||
96
composer.json
Executable file
96
composer.json
Executable file
@@ -0,0 +1,96 @@
|
||||
{
|
||||
"name": "singularity/hdk-skeleton",
|
||||
"license": "MIT",
|
||||
"type": "project",
|
||||
"description": "HDK 骨架",
|
||||
"authors": [
|
||||
{
|
||||
"name": "李东云",
|
||||
"email": "dongyun.li@luxcreo.ai"
|
||||
}
|
||||
],
|
||||
"extra": {
|
||||
"hyperf": {
|
||||
"config": "Singularity\\HDK\\Skeleton\\ConfigProvider"
|
||||
},
|
||||
"hooks": {
|
||||
"config": {
|
||||
"stop-on-failure": [
|
||||
"pre-push"
|
||||
]
|
||||
},
|
||||
"pre-push": [
|
||||
"echo committing as $(git config user.name)",
|
||||
"docker run --rm -t -v \"$(pwd)\":/srv/www harbor.luxcreo.cn/library/hyperf:8.0-swoole composer ci"
|
||||
]
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"App\\": "app/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Test\\": "test/"
|
||||
}
|
||||
},
|
||||
"require": {
|
||||
"php": "^8.1",
|
||||
"composer/composer": ">=2.5.4",
|
||||
"hyperf/db-connection": "3.0.*",
|
||||
"hyperf/session": "3.0.*",
|
||||
"hyperf/validation": "3.0.*",
|
||||
"singularity/hdk-auth": "^0.2.2",
|
||||
"singularity/hdk-core": "^0.2.10",
|
||||
"singularity/hyperf-saml": "^0.2.3",
|
||||
"symfony/polyfill-php81": "^1.27"
|
||||
},
|
||||
"require-dev": {
|
||||
"brainmaestro/composer-git-hooks": "^2.8",
|
||||
"friendsofphp/php-cs-fixer": "^3.0",
|
||||
"hyperf/devtool": "3.0.*",
|
||||
"hyperf/testing": "3.0.*",
|
||||
"phpstan/phpstan": "^1.10.6",
|
||||
"swoole/ide-helper": "^4.8.12"
|
||||
},
|
||||
"suggest": {
|
||||
"singularity/hdk-auth": "用户、鉴权相关逻辑必需",
|
||||
"singularity/hyperf-saml": "接入单点登录必需"
|
||||
},
|
||||
"prefer-stable": true,
|
||||
"config": {
|
||||
"optimize-autoloader": true,
|
||||
"sort-packages": true,
|
||||
"secure-http": false
|
||||
},
|
||||
"scripts": {
|
||||
"post-root-package-install": [
|
||||
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
|
||||
],
|
||||
"test": [
|
||||
"rm -rf runtime",
|
||||
"Composer\\Config::disableProcessTimeout",
|
||||
"co-phpunit --prepend test/bootstrap.php -c phpunit.xml --colors=always"
|
||||
],
|
||||
"cs-fix": "vendor/bin/php-cs-fixer fix $1 --rules=@PSR12 --allow-risky=yes",
|
||||
"analyse": "vendor/bin/phpstan analyse -l 0 $1",
|
||||
"ci": [
|
||||
"@analyse app/ test/",
|
||||
"@cs-fix",
|
||||
"@test",
|
||||
"echo CI Success"
|
||||
]
|
||||
},
|
||||
"repositories": {
|
||||
"lux-map": {
|
||||
"type": "composer",
|
||||
"url": "https://satis.luxcreo.cn/"
|
||||
},
|
||||
"packagist": {
|
||||
"type": "composer",
|
||||
"url": "https://mirrors.cloud.tencent.com/composer/"
|
||||
}
|
||||
},
|
||||
"version": "0.2.2"
|
||||
}
|
||||
7073
composer.lock
generated
Executable file
7073
composer.lock
generated
Executable file
File diff suppressed because it is too large
Load Diff
21
config/autoload/annotations.php
Normal file
21
config/autoload/annotations.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
*
|
||||
* @link https://www.hyperf.io
|
||||
* @document https://hyperf.wiki
|
||||
* @contact group@hyperf.io
|
||||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
return [
|
||||
'scan' => [
|
||||
'paths' => [
|
||||
BASE_PATH . '/app',
|
||||
],
|
||||
'ignore_annotations' => [
|
||||
'mixin',
|
||||
],
|
||||
],
|
||||
];
|
||||
13
config/autoload/commands.php
Normal file
13
config/autoload/commands.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
*
|
||||
* @link https://www.hyperf.io
|
||||
* @document https://hyperf.wiki
|
||||
* @contact group@hyperf.io
|
||||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
return [
|
||||
];
|
||||
60
config/autoload/databases.php
Normal file
60
config/autoload/databases.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
*
|
||||
* @link https://www.hyperf.io
|
||||
* @document https://hyperf.wiki
|
||||
* @contact group@hyperf.io
|
||||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
use Hyperf\Database\Commands\Ast\ModelRewriteInheritanceVisitor;
|
||||
use Hyperf\Database\Commands\Ast\ModelRewriteKeyInfoVisitor;
|
||||
use Hyperf\Database\Commands\Ast\ModelRewriteSoftDeletesVisitor;
|
||||
use Hyperf\Database\Commands\Ast\ModelRewriteTimestampsVisitor;
|
||||
use Hyperf\Database\Commands\ModelOption;
|
||||
|
||||
return [
|
||||
'default' => [
|
||||
'driver' => env('DB_DRIVER', 'mysql'),
|
||||
'host' => env('DB_HOST', 'localhost'),
|
||||
'database' => env('DB_DATABASE', 'lux_studio'),
|
||||
'port' => env('DB_PORT', 3306),
|
||||
'username' => env('DB_USERNAME', 'root'),
|
||||
'password' => env('DB_PASSWORD', 'Qfsd2018'),
|
||||
'charset' => env('DB_CHARSET', 'utf8mb4'),
|
||||
'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci'),
|
||||
'prefix' => env('DB_PREFIX', ''),
|
||||
'pool' => [
|
||||
'min_connections' => 1,
|
||||
'max_connections' => 10,
|
||||
'connect_timeout' => 10.0,
|
||||
'wait_timeout' => 3.0,
|
||||
'heartbeat' => -1,
|
||||
'max_idle_time' => (float)env('DB_MAX_IDLE_TIME', 60),
|
||||
],
|
||||
'commands' => [
|
||||
'gen:model' => [
|
||||
'path' => 'app/Model',
|
||||
'force_casts' => true,
|
||||
'inheritance' => 'Model',
|
||||
'uses' => 'Hyperf\DbConnection\Model\Model',
|
||||
'refresh_fillable' => true,
|
||||
'table_mapping' => [],
|
||||
'ignore_tables' => [],
|
||||
'with_comments' => true,
|
||||
'property_case' => ModelOption::PROPERTY_CAMEL_CASE,
|
||||
'visitors' => [
|
||||
// ModelRewriteGetterSetterVisitor::class,
|
||||
ModelRewriteInheritanceVisitor::class,
|
||||
ModelRewriteKeyInfoVisitor::class,
|
||||
ModelRewriteSoftDeletesVisitor::class,
|
||||
ModelRewriteTimestampsVisitor::class,
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
44
config/autoload/devtool.php
Normal file
44
config/autoload/devtool.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
*
|
||||
* @link https://www.hyperf.io
|
||||
* @document https://hyperf.wiki
|
||||
* @contact group@hyperf.io
|
||||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
return [
|
||||
'generator' => [
|
||||
'amqp' => [
|
||||
'consumer' => [
|
||||
'namespace' => 'App\\Amqp\\Consumer',
|
||||
],
|
||||
'producer' => [
|
||||
'namespace' => 'App\\Amqp\\Producer',
|
||||
],
|
||||
],
|
||||
'aspect' => [
|
||||
'namespace' => 'App\\Aspect',
|
||||
],
|
||||
'command' => [
|
||||
'namespace' => 'App\\Command',
|
||||
],
|
||||
'controller' => [
|
||||
'namespace' => 'App\\Controller',
|
||||
],
|
||||
'job' => [
|
||||
'namespace' => 'App\\Job',
|
||||
],
|
||||
'listener' => [
|
||||
'namespace' => 'App\\Listener',
|
||||
],
|
||||
'middleware' => [
|
||||
'namespace' => 'App\\Middleware',
|
||||
],
|
||||
'Process' => [
|
||||
'namespace' => 'App\\Processes',
|
||||
],
|
||||
],
|
||||
];
|
||||
48
config/autoload/server.php
Normal file
48
config/autoload/server.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
*
|
||||
* @link https://www.hyperf.io
|
||||
* @document https://hyperf.wiki
|
||||
* @contact group@hyperf.io
|
||||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
use Hyperf\Server\Event;
|
||||
use Hyperf\Server\ServerInterface;
|
||||
use Swoole\Constant;
|
||||
|
||||
return [
|
||||
'mode' => SWOOLE_PROCESS,
|
||||
'servers' => [
|
||||
[
|
||||
'name' => 'http',
|
||||
'type' => ServerInterface::SERVER_HTTP,
|
||||
'host' => '0.0.0.0',
|
||||
'port' => 9501,
|
||||
'sock_type' => SWOOLE_SOCK_TCP,
|
||||
'callbacks' => [
|
||||
Event::ON_REQUEST => ['HttpServer', 'onRequest'], // 在 dependencies.php 中重写了
|
||||
],
|
||||
],
|
||||
],
|
||||
'settings' => [
|
||||
Constant::OPTION_ENABLE_COROUTINE => true,
|
||||
Constant::OPTION_WORKER_NUM => swoole_cpu_num(),
|
||||
Constant::OPTION_PID_FILE => BASE_PATH . '/runtime/hyperf.pid',
|
||||
Constant::OPTION_OPEN_TCP_NODELAY => true,
|
||||
Constant::OPTION_MAX_COROUTINE => 100000,
|
||||
Constant::OPTION_OPEN_HTTP2_PROTOCOL => true,
|
||||
Constant::OPTION_MAX_REQUEST => 100000,
|
||||
Constant::OPTION_SOCKET_BUFFER_SIZE => 2 * 1024 * 1024,
|
||||
Constant::OPTION_BUFFER_OUTPUT_SIZE => 2 * 1024 * 1024,
|
||||
],
|
||||
'callbacks' => [
|
||||
Event::ON_WORKER_START => [Hyperf\Framework\Bootstrap\WorkerStartCallback::class, 'onWorkerStart'],
|
||||
Event::ON_PIPE_MESSAGE => [Hyperf\Framework\Bootstrap\PipeMessageCallback::class, 'onPipeMessage'],
|
||||
Event::ON_WORKER_EXIT => [Hyperf\Framework\Bootstrap\WorkerExitCallback::class, 'onWorkerExit'],
|
||||
],
|
||||
];
|
||||
66
config/config.php
Normal file
66
config/config.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
*
|
||||
* @link https://www.hyperf.io
|
||||
* @document https://hyperf.wiki
|
||||
* @contact group@hyperf.io
|
||||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
use Hyperf\Contract\StdoutLoggerInterface;
|
||||
use Psr\Log\LogLevel;
|
||||
|
||||
return [
|
||||
'app_name' => env('APP_NAME', 'skeleton'),
|
||||
'app_env' => env('APP_ENV', 'dev'),
|
||||
'scan_cacheable' => env('SCAN_CACHEABLE', false),
|
||||
StdoutLoggerInterface::class => env('APP_STATUS', false)
|
||||
? [
|
||||
'log_level' => [
|
||||
LogLevel::ALERT,
|
||||
LogLevel::CRITICAL,
|
||||
LogLevel::DEBUG,
|
||||
LogLevel::EMERGENCY,
|
||||
LogLevel::ERROR,
|
||||
LogLevel::INFO,
|
||||
LogLevel::NOTICE,
|
||||
LogLevel::WARNING,
|
||||
],
|
||||
]
|
||||
: [
|
||||
'log_level' => [
|
||||
LogLevel::ALERT,
|
||||
LogLevel::CRITICAL,
|
||||
// LogLevel::DEBUG,
|
||||
LogLevel::EMERGENCY,
|
||||
LogLevel::ERROR,
|
||||
LogLevel::INFO,
|
||||
LogLevel::NOTICE,
|
||||
LogLevel::WARNING,
|
||||
],
|
||||
],
|
||||
'language' => env('DEFAULT_LANGUAGE', 'en'),
|
||||
'prefix' => env('PREFIX', 'LuxStudio:token:map:'),
|
||||
|
||||
'aliyun_ak_id' => 'LTAI4GL64uQt4PewrGKKNKZf',
|
||||
'aliyun_ak_secret' => 'gyFtXJjoo1XWl0tfE2NI0pAU5LuzjJ',
|
||||
|
||||
// oss
|
||||
'oss_host' => env('OSS_UPLOAD_HOST', 'lux-studio-test.oss-cn-beijing.aliyuncs.com'),
|
||||
'oss_callback' => env('OSS_CALLBACK_API', 'https://test-studio.luxcreo.cn/api/v1/oss/callback'),
|
||||
|
||||
// Mailer
|
||||
'mailer_dsn' => 'smtp://account@luxcreo.ai:Qfsd8866@smtp.qiye.aliyun.com:465',
|
||||
'mailer_sender' => 'account@luxcreo.ai',
|
||||
'mailer_sender_name' => 'LuxCreo',
|
||||
|
||||
'secure_code_key' => env('SECURE_CODE_KEY', ''),
|
||||
'is_task_sync' => env('IS_TASK_SYNC', false),
|
||||
// 切换晶格时间(202301下架除了 GH-5 所有晶格),此时间之后不再考虑 deleted_at 时间
|
||||
// 202303 下架 GH-5
|
||||
'switch_lattice_time' => env('SWITCH_LATTICE_AT', '2023-03-07 14:55:00'),
|
||||
];
|
||||
24
config/container.php
Normal file
24
config/container.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
* Initialize a dependency injection container that implemented PSR-11 and return the container.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
*
|
||||
* @link https://www.hyperf.io
|
||||
* @document https://hyperf.wiki
|
||||
* @contact group@hyperf.io
|
||||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
use Hyperf\Di\Container;
|
||||
use Hyperf\Di\Definition\DefinitionSourceFactory;
|
||||
use Hyperf\Utils\ApplicationContext;
|
||||
|
||||
$container = new Container((new DefinitionSourceFactory(true))());
|
||||
|
||||
if (! $container instanceof \Psr\Container\ContainerInterface) {
|
||||
throw new RuntimeException('The dependency injection container is invalid.');
|
||||
}
|
||||
return ApplicationContext::setContainer($container);
|
||||
18
config/routes.php
Normal file
18
config/routes.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
*
|
||||
* @link https://www.hyperf.io
|
||||
* @document https://hyperf.wiki
|
||||
* @contact group@hyperf.io
|
||||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
use Hyperf\HttpServer\Router\Router;
|
||||
|
||||
Router::addRoute(['GET', 'POST', 'HEAD'], '/', 'App\Controller\Api\IndexController@index');
|
||||
|
||||
Router::get('/favicon.ico', fn () => '');
|
||||
128
guide.md
Normal file
128
guide.md
Normal file
@@ -0,0 +1,128 @@
|
||||
# PHP Package boilerplate project explanation
|
||||
|
||||
PHP is a general-purpose server-side scripting language primarily used in web development. Originally created by Rasmus Lerdorf in 1994, it is now by The PHP Development Team.
|
||||
|
||||
PHP originally stood for "Personal Home Page", but now stands for "PHP: Hypertext Preprocessor".
|
||||
|
||||
## Further Material
|
||||
|
||||
- Homepage: [php.net](https://secure.php.net/)
|
||||
- Documentation: [php.net/docs.php](https://secure.php.net/docs.php)
|
||||
- PHP: The Right Way: [phptherightway.com](http://www.phptherightway.com/)
|
||||
- Interactive PHP Tutorial: [learn-php.org](http://www.learn-php.org/)
|
||||
|
||||
## Topics, Tools and Terms
|
||||
|
||||
PHP packages were traditionally installed via PEAR (PHP Extension and Application Repository), but more recently the standard package and dependency management tool is Composer.
|
||||
|
||||
Composer lets us run install commands to add packages to our system, for example `composer require phpunit` would add the unit testing framework PHPUnit to our system.
|
||||
|
||||
For instructions on how to install Composer visit [getcomposer.org](https://getcomposer.org/download/).
|
||||
|
||||
### Dependency Management
|
||||
|
||||
Managing dependencies manually is time-consuming, fortunately Composer can automate this.
|
||||
|
||||
We can list our dependencies in a `composer.json` file and run `composer install` to bring these into our project.
|
||||
|
||||
An example `composer.json` file looks like this:
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "example-project",
|
||||
"require": {
|
||||
"twig/twig": "^3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^8.4"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The "require" block tells Composer that the Twig templating package is required for production use and can install Twig with a version of 3.x.x (ie. up to, but not including, version 4).
|
||||
|
||||
The "require-dev" block tells Composer that PHPUnit is required in development, but not in production.
|
||||
|
||||
Dependencies can be added to `composer.json` by
|
||||
|
||||
```bash
|
||||
composer require author/package-name
|
||||
```
|
||||
|
||||
Development dependencies can be added by
|
||||
|
||||
```bash
|
||||
composer require author/package-name --dev
|
||||
```
|
||||
|
||||
Dependencies can be updated to their latest maximum version by running
|
||||
|
||||
```bash
|
||||
composer update
|
||||
```
|
||||
|
||||
Composer will also generate a `composer.lock` file on each `composer update` and the initial `composer install`. This is not meant to be edited directly, it tells Composer to use specific versions of packages - particularly useful when hyhou want your development dependencies to match what you will push to production.
|
||||
|
||||
### Testing Tools
|
||||
|
||||
There are a number of testing tools available for PHP. The most popular one is [PHPUnit](https://phpunit.de/). PHPUnit follows the classic xUnit approach.
|
||||
|
||||
[Behat](http://behat.org/en/latest/) is the most popular behaviour-driven development (BDD) testing framework.
|
||||
|
||||
[Codeception](http://codeception.com/) is a framework combining BDD, unit testing, and integration testing, and is cross-compatible with PHPUnit.
|
||||
|
||||
In this guide we will be using PHPUnit as the testing framework.
|
||||
|
||||
## Directory Structure
|
||||
|
||||
A typical directory structure for a PHP project consists of a `src` directory that contains all source files and a `tests` directory that includes all tests. For web applications the publicly accessible files (eg. `index.php`) would reside in a `public` directory which would then be your webservers document root.
|
||||
|
||||
Another common convention is having a `bin` directory that may contain executable files to start your application.
|
||||
|
||||
- src/
|
||||
- test/
|
||||
- public/
|
||||
- composer.json
|
||||
- composer.lock
|
||||
|
||||
### Naming Conventions
|
||||
|
||||
Directory names are in lower case. Class and interface files should be in upper case and match the class or interface names.
|
||||
Configuration, routes, and publicly accessible files should be in lower case.
|
||||
|
||||
For example the class `Example` should be contained in file `Example.php`, the publicly accessible route to the application should be `index.php`.
|
||||
|
||||
Tests match their production code file names with a `Test` suffix, e.g. tests for code in `src/Example.php` should be written in `test/ExampleTest.php`.
|
||||
|
||||
## Example Project
|
||||
|
||||
The main application consists of basically two files:
|
||||
|
||||
- `public/example.php` is the main executable that instantiates and runs:
|
||||
- `src/Example/Greeting.php` contains the main application.
|
||||
|
||||
### Running the Tests
|
||||
|
||||
All tests can be run by executing
|
||||
|
||||
```bash
|
||||
vendor/phpunit/phpunit/phpunit
|
||||
```
|
||||
|
||||
`phpunit` will automatically find all tests inside the `test` directory and run them based on the configuration in the `phpunit.xml` file.
|
||||
|
||||
#### Testing Approach
|
||||
|
||||
The test for the class `Greeting` verifies that the return value of the `sayHello` method returns the string "Hello {name}", where {name} is the value passed through to the constructor.
|
||||
|
||||
### Running the Application
|
||||
|
||||
PHP has an in-built server for local development. To run this change into the directory `public` and run
|
||||
|
||||
```bash
|
||||
php -S localhost:8000
|
||||
```
|
||||
|
||||
Then open your browser at `http://localhost:8000/example.php`
|
||||
|
||||
You should see the text "Hello Ada Lovelace" being printed.
|
||||
13
phpstan.dist.neon
Normal file
13
phpstan.dist.neon
Normal file
@@ -0,0 +1,13 @@
|
||||
parameters:
|
||||
level: 6
|
||||
reportUnmatchedIgnoredErrors: false
|
||||
checkGenericClassInNonGenericObjectType: false
|
||||
paths:
|
||||
- publish
|
||||
- src
|
||||
- testsi
|
||||
ignoreErrors:
|
||||
- '#Constant BASE_PATH not found#'
|
||||
- '#Property [a-zA-Z0-9\\_]+::\$[a-zA-Z0-9]+ is never written, only read\.#'
|
||||
- '#Method [a-zA-Z0-9\\_]+::[a-zA-Z0-9]+\(\) is unused\.#'
|
||||
- '#Method [a-zA-Z0-9\\_]+::[a-zA-Z0-9]+\(\) has parameter \$response with no value type specified in iterable type array\.#'
|
||||
16
phpunit.xml
Normal file
16
phpunit.xml
Normal file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
bootstrap="./test/bootstrap.php"
|
||||
colors="true"
|
||||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
|
||||
<coverage processUncoveredFiles="true">
|
||||
<include>
|
||||
<directory suffix=".php">./app</directory>
|
||||
</include>
|
||||
</coverage>
|
||||
<testsuites>
|
||||
<testsuite name="Tests">
|
||||
<directory>./test</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
||||
8
scripts/build-image.sh
Executable file
8
scripts/build-image.sh
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env sh
|
||||
docker login harbor.luxcreo.cn -u php -p fTr6oVvqqdzVlYgnZhRPPAP54u7SmqGA
|
||||
|
||||
image_name=harbor.luxcreo.cn/php/hdk-boilerplate
|
||||
docker build --tag $image_name .
|
||||
|
||||
#docker push $image_name
|
||||
#docker push ${image_name}-dev
|
||||
9
scripts/docker-env.sh
Executable file
9
scripts/docker-env.sh
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
docker run \
|
||||
--pull always \
|
||||
-ti --rm --name "hdk-boilerplate" \
|
||||
-w "/srv/www" \
|
||||
-v "$(pwd)":/srv/www \
|
||||
-v ~/.ssh:/root/.ssh \
|
||||
harbor.luxcreo.cn/library/hyperf:8.1-swoole /bin/ash
|
||||
5
scripts/release.sh
Executable file
5
scripts/release.sh
Executable file
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
docker run --rm -it \
|
||||
-v $(pwd):/app -e "GIT_AUTHOR_NAME=ch4o5" -e "EMAIL=dongyun.li@luxcreo.ai" \
|
||||
detouched/standard-version:latest $1
|
||||
28
test/Api/ExampleTest.php
Normal file
28
test/Api/ExampleTest.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
*
|
||||
* @link https://www.hyperf.io
|
||||
* @document https://hyperf.wiki
|
||||
* @contact group@hyperf.io
|
||||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
namespace Test\Api;
|
||||
|
||||
use Test\HttpTestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class ExampleTest extends HttpTestCase
|
||||
{
|
||||
public function testExample(): void
|
||||
{
|
||||
$this->assertTrue(true);
|
||||
$this->assertTrue(is_array($this->get('/')));
|
||||
}
|
||||
}
|
||||
48
test/HttpTestCase.php
Normal file
48
test/HttpTestCase.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
*
|
||||
* @link https://www.hyperf.io
|
||||
* @document https://hyperf.wiki
|
||||
* @contact group@hyperf.io
|
||||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
namespace Test;
|
||||
|
||||
use Hyperf\Testing\Client;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Class HttpTestCase.
|
||||
* @method get($uri, $data = [], $headers = [])
|
||||
* @method post($uri, $data = [], $headers = [])
|
||||
* @method json($uri, $data = [], $headers = [])
|
||||
* @method file($uri, $data = [], $headers = [])
|
||||
* @method request($method, $path, $options = [])
|
||||
*/
|
||||
abstract class HttpTestCase extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var Client
|
||||
*/
|
||||
protected Client $client;
|
||||
|
||||
/**
|
||||
* @param string|null $name
|
||||
* @param array<int, mixed> $data
|
||||
* @param int|string $dataName
|
||||
*/
|
||||
public function __construct(?string $name = null, array $data = [], int|string $dataName = '')
|
||||
{
|
||||
parent::__construct($name, $data, $dataName);
|
||||
$this->client = make(Client::class);
|
||||
}
|
||||
|
||||
public function __call($name, $arguments)
|
||||
{
|
||||
return $this->client->{$name}(...$arguments);
|
||||
}
|
||||
}
|
||||
29
test/bootstrap.php
Normal file
29
test/bootstrap.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
*
|
||||
* @link https://www.hyperf.io
|
||||
* @document https://hyperf.wiki
|
||||
* @contact group@hyperf.io
|
||||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
ini_set('display_errors', 'on');
|
||||
ini_set('display_startup_errors', 'on');
|
||||
|
||||
error_reporting(E_ALL);
|
||||
date_default_timezone_set('Asia/Shanghai');
|
||||
|
||||
! defined('BASE_PATH') && define('BASE_PATH', dirname(__DIR__, 1));
|
||||
! defined('SWOOLE_HOOK_FLAGS') && define('SWOOLE_HOOK_FLAGS', SWOOLE_HOOK_ALL);
|
||||
|
||||
Swoole\Runtime::enableCoroutine(true);
|
||||
|
||||
require BASE_PATH . '/vendor/autoload.php';
|
||||
|
||||
Hyperf\Di\ClassLoader::init();
|
||||
|
||||
$container = require BASE_PATH . '/config/container.php';
|
||||
|
||||
$container->get(Hyperf\Contract\ApplicationInterface::class);
|
||||
Reference in New Issue
Block a user