digbang / laravel-project
项目名称
Requires
- php: ^8.0.2
- ext-json: *
- cakephp/chronos: ^2.3
- digbang/backoffice: ^9.0
- digbang/doctrine-extensions: ^3.0
- digbang/safe-queue: ^1.0
- digbang/utils: ^2.0
- flugger/laravel-responder: ^3.2
- fruitcake/laravel-cors: ^2.0
- gedmo/doctrine-extensions: ^3.2
- laravel-doctrine/extensions: ^1.4
- laravel-doctrine/fluent: ^1.2
- laravel-doctrine/orm: ^1.8
- laravel/framework: ^9.0
- laravel/sanctum: ^2.14
- laravel/tinker: ^2.7
- php-open-source-saver/jwt-auth: ^2.0
- sentry/sentry-laravel: ^2.11
Requires (Dev)
- arcanedev/log-viewer: ^9.0
- barryvdh/laravel-debugbar: ^3.6
- barryvdh/laravel-ide-helper: ^2.12
- beyondcode/laravel-dump-server: ^1.8
- brainmaestro/composer-git-hooks: dev-master
- fakerphp/faker: ^1.19
- friendsofphp/php-cs-fixer: ^3.8
- garygreen/pretty-routes: ^1.0
- laravel/pint: ^1.0
- mockery/mockery: ^1.5
- nunomaduro/collision: ^6.1
- nunomaduro/larastan: ^2.1
- nunomaduro/patrol: ^1.1
- nunomaduro/phpinsights: ^2.2
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.2
- phpunit/phpunit: ^9.5
- spatie/laravel-ignition: ^1.1
Suggests
- cviebrock/image-validator: Extra Laravel validation rules for dealing with images.
- digbang/files: File and Image storage.
- digbang/settings: Dynamic settings, stored in the database, editable by users
- guzzlehttp/guzzle: Guzzle is a PHP HTTP client that makes it easy to send HTTP requests and trivial to integrate with web services.
- intervention/image: PHP image handling and manipulation library.
- lcobucci/jwt: A simple library to work with JSON Web Token and JSON Web Signature based on the RFC 7519.
- maatwebsite/excel: Supercharged Excel exports and imports. A simple, but elegant Laravel wrapper around PhpSpreadsheet exports and imports.
- moneyphp/money: Work with money safer, easier, and fun!
- omnipay/omnipay: Payment gateway abstraction.
- dev-master-digbangs-way
- v9.3.0
- v9.2.0
- v9.1.0
- v9.0.2
- v9.0.1
- v9.0.0
- v8.4.1
- v8.4.0
- v8.3.5
- v8.3.4
- v8.3.3
- v8.3.2
- v8.3.1
- v8.3.0
- v8.2.3
- v8.2.1
- v8.2.0
- v8.1.2
- v8.1.1
- v8.1.0
- v8.0.3
- v8.0.2
- v8.0.1
- v8.0.0
- v7.1.5
- v7.1.4
- v7.1.3
- v7.1.2
- v7.1.1
- v7.1.0
- v7.0.13
- v7.0.12
- v7.0.11
- v7.0.10
- v7.0.9
- v7.0.8
- v7.0.7
- v7.0.6
- v7.0.5
- v7.0.4
- v7.0.3
- v7.0.2
- v7.0.1
- v7.0.0
- v6.1.1
- v6.1.0
- v6.0.1
- v6.0
- v5.8.2
- v5.8.1
- v5.8
- v5.7.10
- v5.4.3
- v5.3.7
- dev-9.0_digbangs-way
- dev-8.0_digbangs-way
- dev-7.0_digbangs-way
- dev-6.0_digbangs-way
- dev-5.8_digbangs-way
- dev-master
- dev-5.7_digbangs-way
- dev-5.6_digbangs-way
- dev-5.5_digbangs-way
- dev-digbangs-way
This package is auto-updated.
Last update: 2024-09-11 16:59:53 UTC
README
安装
- 克隆仓库
- 启动容器
- 访问PHP容器并
A. 运行
composer config -g github-oauth.github.com <token>
(创建token请访问:https://github.com/settings/tokens/new 并设置repo权限)
B. 运行
composer install
C. 运行
ln -s /proxies proxies
D. 运行
composer build
Minio配置
- 将"127.0.0.1 s3"添加到hosts文件中
- 访问
https://:9000/minio
, - 使用位于
docker-compose.yml
中的访问和秘密密钥登录。 - 创建一个具有某些名称的存储桶。给存储桶添加一个读写策略。
- 在您的env文件中配置存储桶名称
- 将文件系统驱动程序更改为
minio
Sentry配置
- 配置您的.env变量
- 在.env文件中启用Sentry
系统配置
- 请记住,所有网站都必须使用HTTPS。请选择适当的重定向。
- http://www.site.com应重定向到https://www.site.com
- http://site.com应重定向到https://www.site.com
- https://site.com应重定向到https://www.site.com
- 子域名(www)可以在示例中互换。但您必须选择使用它并将重定向到它,或者不使用它并从它重定向。
- 请参阅docker/apache/default.conf以获取访问网站和资源的服务器配置。
发布资产
php artisan vendor:publish --provider "Digbang\\Backoffice\\BackofficeServiceProvider" --tag assets --force
编译资产(Vite)
Vite是一个现代前端构建工具,它提供了一个极快的开发环境,并将您的代码捆绑到生产中。
为了在开发中提供资产,您应使用npm run dev
命令(该命令编译资产并通过localhost:3000提供服务器),而在生产构建中应使用npm run build
命令。
如果您使用Vite,请确保您的布局使用@vite指令并正确指向资源:@vite(['resources/css/app.css', 'resources/js/app.js'])
有关Vite的更多信息,请参阅官方文档:https://laravel.net.cn/docs/9.x/vite
巡逻 - 跟踪有漏洞或过时的依赖项
巡逻是一个优雅的命令行工具,可确保您的PHP项目的依赖项处于受控状态。
composer patrol
Pint - 代码风格修复器
Laravel Pint是一个针对简约主义者的PHP代码风格修复器。Pint建立在PHP-CS-Fixer之上,使确保您的代码风格保持干净和一致变得简单。
composer cs
特殊目录
权限
// at the root of the project (only on linux)
sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache
代理(确保存在符号链接...)
// ... if not; inside of the PHP container run
ln -s /proxies /proxies
请求仓库
如果您需要一个仓库,您可能这样做
示例
public function users(): ?array { if ($this->input(self::USER_IDS)) { return $this->repository(UserRepository::class)->find($this->input(self::USER_IDS)); } return null; }
如果您需要ReadRepository中不存在的仓库方法,您必须在您的请求中创建一个私有方法。
示例
private function roleRepository(): RoleRepository { /** @var RoleRepository $repository */ $repository = $this->repository(RoleRepository::class); return $repository; } public function roles(): ?array { if ($this->input(self::ROLE_NAME)) { return $this->roleRepository()->findByName($this->input(self::ROLE_NAME)); } return null; }
HTTP状态码参考
以下列表包含API返回的HTTP状态码及其在本上下文中的含义
- HTTP 200 Ok:请求已成功处理。
- HTTP 201 Created:资源已创建。它与POST请求相关。
- HTTP 204 No Content:请求已成功处理,但不需要返回实体主体。
- HTTP 400 Bad Request:请求无法被API处理。您应检查发送的数据。
- HTTP 401 Unauthorized:当请求执行到登录端点时,表示凭证与任何凭证都不匹配。当请求执行到另一个端点时,表示令牌已因TTL过期而无效。
- HTTP 403 Forbidden:请求中提供的凭据没有必要的权限进行处理。
- HTTP 404 Not Found:请求的端点在API中不存在。
- HTTP 422:发送到API的数据包未通过验证过程。
- HTTP 500:在处理过程中触发了未知错误。
请参考https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html以获取更多信息
Php Stan
现在您应该有一个phpstan.neon
文件,允许您配置此包的基本设置。
https://github.com/nunomaduro/larastan https://phpstan.org/user-guide/getting-started
Php Insight
配置文件
现在您应该有一个config/insights.php
文件,允许您配置此包的基本设置。
https://phpinsights.com/get-started.html
Laravel Responder
创建响应
return responder() ->success($user, UserProfileTransformer::class) ->meta([ 'meta' => $this->shouldRefreshToken(), ]) ->respond();
创建转换器
php artisan make:transformer ProductTransformer --plain
处理异常
转换自定义异常
除了让包转换Laravel异常之外,您还可以使用render
方法中的convert
方法转换您自己的异常
$this->convert($exception, [ InvalidValueException => PageNotFoundException, ]);
如果您想传递构造函数参数,可以可选地提供一个闭包来抛出新异常
$this->convert($exception, [ MaintenanceModeException => function ($exception) { throw new ServerDownException($exception->retryAfter); }, ]);
创建HTTP异常
异常类是存储错误信息的便利位置。该包提供了一个抽象异常类Flugg\Responder\Exceptions\Http\HttpException
,它了解状态码、错误码和错误消息。继续使用我们上面的产品示例,我们可以创建自己的HttpException
类
<?php namespace App\Exceptions; use Flugg\Responder\Exceptions\Http\HttpException; class SoldOutException extends HttpException { /** * The HTTP status code. * * @var int */ protected $status = 400; /** * The error code. * * @var string|null */ protected $errorCode = 'sold_out_error'; /** * The error message. * * @var string|null */ protected $message = 'The requested product is sold out.'; }
您还可以添加一个返回额外错误数据的data
方法
/** * Retrieve additional error data. * * @return array|null */ public function data() { return [ 'shipments' => Shipment::all() ]; }
如果您让包处理异常,现在您可以在应用程序的任何地方抛出异常,它将自动渲染为错误响应。
throw new SoldOutException();
https://github.com/flugger/laravel-responder
JWT Auth
配置文件
现在您应该有一个config/jwt.php
文件,允许您配置此包的基本设置。
####生成密钥
我包含了一个辅助命令来为您生成密钥
php artisan jwt:secret
这将更新您的.env
文件,类似于JWT_SECRET=foobar
这是用于签名令牌的密钥。具体如何进行将取决于您选择的算法。
https://github.com/tymondesigns/jwt-auth
系统要求
-
php: 7.4.x
-
php ini配置
upload_max_filesize = 100M
post_max_size = 100M
- 这些数字仅供参考。根据项目需求进行设置。
-
php扩展
- bcmath
- 核心
- ctype
- curl
- date
- dom
- fileinfo
- filter
- ftp
- gd
- hash
- iconv
- imagick
- intl
- json
- libxml
- mbstring
- mcrypt
- mysqlnd
- openssl
- pcntl
- pcre
- PDO
- pdo_pgsql
- pdo_sqlite
- Phar
- posix
- readline
- redis
- 反射
- session
- SimpleXML
- soap
- SPL
- sqlite3
- 标准
- tidy
- tokenizer
- xdebug
- xml
- xmlreader
- xmlwriter
- ZendOPcache
- zip
- zlib
-
Composer PHP
-
apache: 2.4.x / nginx
-
postgres: 11.x / 12.x
-
postgres 扩展
- Unaccent 扩展
-
redis
-
node
-
npm
-
yarn
-
SO 包
- locales
- locales-all
覆盖 php 配置
覆盖 php ini 默认配置
为了覆盖 .ini 配置,请使用项目根目录下的 ./docker/php/conf.d
目录中的 custom.ini
文件。修改文件后,您需要重新构建容器: docker-compose up -d --build php
。
建议更改
upload_max_filesize
和post_max_size
。请注意,这些值应该在所有环境中更改。
如果您需要,建议更改
memory_limit
。在这种情况下,仅在开发环境中更改。
覆盖扩展配置
为了覆盖任何扩展设置,您应该能够在应用程序根目录相对的 ./docker/php/conf.d 文件夹中放置相应的 .ini 文件。
请记住,按照惯例,任何扩展配置文件都应该命名为
docker-php-ext-{extension name}.ini
。
例如,如果您想覆盖 opcache,您应该创建以下文件: ./docker/php/conf.d/docker-php-ext-opcache.ini
并填写所需内容。同样,对于 xdebug: ./docker/php/conf.d/docker-php-ext-xdebug.ini
。
然后,使用以下命令将文件从主机复制到容器中,在 ./docker/php/Dockerfile
内部: COPY conf.d /usr/local/etc/php/conf.d/
这将在下一次
docker-compose up --build
时生效
注意
If you want to test different configurations, you can mount the files in conf.d as volumes. That way, restarting apache or the container will use the new configurations.
To do so, you can add this (as an example) to the volumes configured on docker-compose.yml:
- .:/docker/php/conf.d/custom.ini:/usr/local/etc/php/conf.d/custom.ini:ro
After finishing with the tests and changes, please remove the volume configuration and rebuild the container with the new configs.