定制 red-freak/modular-monolith-laravel-env 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

red-freak/modular-monolith-laravel-env

Composer 安装命令:

composer require red-freak/modular-monolith-laravel-env

包简介

dotenv management for modular monoliths inspired by https://github.com/avosalmon/modular-monolith-laravel

README 文档

README

Warning This Package is still work in progress!

Warning The package is basically functional, but there is no logic to handle the files in a repo.

Modular Monolith Laravel Env

The task of this package is to manage module dotnev-files used by the Laravel integration of phpdotenv. To store these files in source control without populating its contents to tjhe public the package is also based on Laravels environment encrypting by a shared secret. This way the package can also be used for forge or envoyer deployments.

Systemrequirements

  • This package is only tested with Laravel 9. So it requires "vlucas/phpdotenv": "^5.4.1".
  • The package is written in PHP 8.1.

Installation

To install you have to replace the Kernel-classes of Laravel.

app/Http/Kernel.php

// replace
5: use Illuminate\Foundation\Http\Kernel as HttpKernel;
// with
5: use RedFreak\ModularEnv\Foundation\Http\Kernel as HttpKernel;

app/Console/Kernel.php

// replace
6: use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
// with
6: use RedFreak\ModularEnv\Foundation\Console\Kernel as ConsoleKernel;

Testing

run in develope

./vendor/bin/phpunit

How to use

getting started

The package assumes that the including package is structured following the modular monolith talk with the additional dotenv-files by this logic:

.
├── app
├── .env
├── ...
├── src
│    ├── ModuleOne
│    │    ├── ...
│    │    └── .env
│    ├── ...
│    └── ModuleLast
│         ├── ...
│         └── .env
└── ...

If your structure is different you have to implement the ModularEnvironmentApplication-Contract into your application. By the method ModularEnvironmentApplication::additionalEnvFiles() the package will recognize different paths (* and ** are allowed and used like in the .gitignore).

using the variables

Variables form the default .env are accessed like before with the env()-helper.

Variables from the modules are accessed the same way with the difference that they are prefixed with the module name in SNAKE_CASE (caps) and __. E.g. the Variable HELLO=WORLD from the file /src/FooBar/.env can be accessed by env('FOO_BAR__HELLO').

tasks

tasks for 0.3.0 - encrypting the files

  • support for env:encrypt and env:decrypt to handle the files
  • implementing modular_env:encrypt and modular_env:deecrypt to support deployment processes

1.0.0-alpha

  • maybe writing additional tests
  • adding a test-pipeline for gitHub
  • fixing and testing of 0.3.0 in real-life-environments

1.0.0 - MVP

  • fixed release of 1.0.0-alpha

1.1.0 - LaravelRay

  • support for LaravelRay

recommendations

use the following in your .gitignore

.env
.env.*
!.env.example
!.env*.encrypted
!.env.pipelines
/src/**/.env
/src/**/.env.*
!/src/**/.env*.encrypted
!/src/**/.env.example

Why do I?

Why do I have to replace Kernel-Classes?

I see, replacing the Kernel is a big issue. But .env-files are bootstrapped before anything else, so we have to hook something before everything else. The Kernels are present and inheriting, so it's a good point to hook in.

Need to create my own Application class?

You don't have to it's just a possibility to determine a custom path-structure on your dotenv-files. The default "setting" will be to guess files in /src/**/.

Need to create my own Application class if I have a custom path-structure on my .env-files?

The problem for this package is, that we want to hook a behaviour which is deep in the functionality of Laravel. At the moment the dotenv-files are loaded there is just a "stub" of the Application, there is no way to use config or env. So this seemed the best option to not produce unnecessary disk-requests. This is especially important for applications handling hundreds of requests per second.

Licence

This package is free to use as stated by the LICENCE.md under the MIT License, but you can buy me a coffee if you want :D.

red-freak/modular-monolith-laravel-env 适用场景与选型建议

red-freak/modular-monolith-laravel-env 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 3, 最近一次更新时间为 2022 年 10 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 red-freak/modular-monolith-laravel-env 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 red-freak/modular-monolith-laravel-env 我们能提供哪些服务?
定制开发 / 二次开发

基于 red-freak/modular-monolith-laravel-env 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 3
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 25
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-10-09