承接 jstewmc/detect-environment 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

jstewmc/detect-environment

Composer 安装命令:

composer require jstewmc/detect-environment

包简介

Detect an application's environment

README 文档

README

Detect an application's environment.

namespace Jstewmc\DetectEnvironment;

// define our possible environments
$values = [
    'development' => 'foo',
    'testing'     => 'bar',
    'staging'     => 'baz',
    'production'  => 'qux'
];

// put the environment variable
putenv('APP_ENV=foo');

// instantiate the service
$service = new DetectEnvironment('APP_ENV', $values);

// detect the environment
$service->isDevelopment();  // returns true
$service->isTesting();      // returns false
$service->isStaging();      // returns false
$service->isProduction();   // returns false

// get the environment's name
$service();  // returns "development"

Usage

To instantiate the service, you MUST pass the environment variable name and the environment variable values, indexed by application environment name:

namespace Jstewmc\DetectEnvironment;

putenv('APP_ENV=foo');

$service = new DetectEnvironment(
    'APP_ENV', 
    [
        'development' => 'foo',
        'testing'     => 'bar',
        'staging'     => 'baz',
        'production'  => 'qux'
    ]
);

In the example above, the service would detect the environment as development, testing, staging, and production when the APP_ENV environment was 'foo', 'bar', 'baz', and 'qux', respectively.

Keep in mind, the environment variable name, the environment variable values, and the application environment names MAY be any string. The environment variable values and the application environment names are case-insensitive.

You can check the application's environment using isX() methods, where X is any valid application environment name:

namespace Jstewmc\DetectEnvironment;

putenv('APP_ENV=foo');

$service = new DetectEnvironment(
    'APP_ENV', 
    [
        'development' => 'foo',
        'testing'     => 'bar',
        'staging'     => 'baz',
        'production'  => 'qux'
    ]
);

$service->isDevelopment();  // returns true
$service->isTesting();      // returns false
$service->isStaging();      // returns false
$service->isProduction();   // returns false
$service->foo();            // throws exception (MUST start with "is")
$service->isFoo();          // throws exception (MUST be valid environment name)

Environment variable

In the examples above, the environment variable was set using the putenv() function. However, in the real world, you should define the environment variable in your server configuration (e.g., .htaccess, httpd.conf, etc).

No matter where you define the environment variable, it MUST be accessible to PHP's getenv function.

That's it!

License

MIT

Author

Jack Clayton

Version

2.0.0, October 2, 2016

  • Add __invoke() method to return environment name.
  • Rename class to DetectEnvironment. The longer name seems more intentional.

1.0.0, August 13, 2016

  • Major release
  • Update composer.json

0.2.0, August 13, 2016

  • Refactor to support user-defined environments

0.1.0, June 25, 2016

  • Initial release

jstewmc/detect-environment 适用场景与选型建议

jstewmc/detect-environment 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 65 次下载、GitHub Stars 达 0, 最近一次更新时间为 2016 年 08 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 jstewmc/detect-environment 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-08-07