casperwilkes/laravel-environment_detector 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

casperwilkes/laravel-environment_detector

Composer 安装命令:

composer require casperwilkes/laravel-environment_detector

包简介

Builds appropriate .env configs, detects current laravel environment, uses corresponding .env. Requires Laravel Framework 5 or 6.

README 文档

README

This is a simple environment detector made for working with multiple environments. This package should not need to be run very often, if at all after it's initial setup.

This is great for multiple environment setups.

Sometimes you don't want to save your .env files to your repository, in that case, add .env* to your .gitignore file.

Requirements

This package is only available for Laravel Framework versions 5 & 6.

Installation

There are a couple steps necessary to get the environment detector up and running.

Composer

To install the package through composer:

composer require casperwilkes/laravel-environment_detector

Laravel Publish

Once you have installed through composer, you will want to publish the assets of the project

php artisan vendor:publish --tag=env-detector

This will publish the necessary bootstrap files and the config file.

The bootstrap file will be located at ./bootstrap/environment_detector.php.

The config will be at ./config/environment_detector.php

Check Config

After you've published your config file, you'll want to update it with your environments, and perspective short names.

By default, there are some environments already setup.

'environments' => [
        'local' => 'local',
        'dev' => 'localhost',
        'qa' => '',
        'stage' => '',
        'prod' => '',
    ],

You can use whatever short names you want to describe your environment stage. This will create the shortname for the .env files.

For the environment name, you'll want the machines hostname. You can run hostname from the command line to get it.

For example, if you had 2 production environments called prod_one, and prod_two, you would use those for the short name, and use the machine's hostname for the environment field.

'environments' => [
        'local' => 'local',
        'dev' => 'localhost',
        'prod_one' => 'box284.gatorhost.com',
        'prod_two' => 'box246.redhost.com'
    ],

Package Publish

After you've published the vendor assets, you will want to publish the package.

To publish the package, run:

php artisan envdetector:publish

This will create the necessary environment files, and update your App.php to require the environment_detector. A backup of your previous version of App.php will be backed up in the same directory.

This will work it's way through your environment_detector config, and create a .env file for each environment found.

So, for our previous example, we'll get 4 different .env files.

  • .env.local
  • .env.dev
  • .env.prod_one
  • .env.prod_two

Remove Package

If for whatever reason you wish to remove the package, you can un-publish the package.

Run

php artisan envdetector:unpublish

This will remove the bootstrap files, the new config files, and restore your app from the backup process.

note: If no backup is found, it will attempt to remove the require statement from App.php.

Usage

There are a couple usage options for both the envdetector commands.

Publish

For the publish command, there are 3 options:

  • bootstrap (-b|--bootstrap)
    • this will backup App.php and add the require statement to bootstrap to load the correct .env file based on config.
  • configs (-c|--configs)
    • This will create the necessary .env.* config files based on the config file. They will be copied from the original .env file.
  • all (-a|--all), this will run all other options

Notes

For the bootstrap option, a backup copy of the original App.php is created and stored in the same directory. This will be used in case you've made previous changes to App.php, and you wish to revert back.

For the configs option, it will detect if a particular config already exists, and whether it should be overwritten. A prompt will appear asking for permission before assuming. If not configs are already setup, it will go ahead and create them. You can choose to overwrite all, or only some.

This is useful for when you've only added 1 or 2 new environments.

The original .env.example and .env will always remain untouched by this package.

Un-publish

For the un-publish command, there are 3 options:

  • bootstrap (-b|--bootstrap)
    • This will restore the App.php file to it's original contents.
  • configs (-c|--configs)
    • This will remove the config file, and all package created .env.* files.
  • all (-a|--all), this will run all other options

casperwilkes/laravel-environment_detector 适用场景与选型建议

casperwilkes/laravel-environment_detector 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 111 次下载、GitHub Stars 达 2, 最近一次更新时间为 2019 年 11 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「multiple」 「laravel」 「environment」 「detector」 「multiple environments」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 casperwilkes/laravel-environment_detector 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-11-15