PHPackages                             josegonzalez/cakephp-environments - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. josegonzalez/cakephp-environments

ActiveCakephp-plugin[Utility &amp; Helpers](/categories/utility)

josegonzalez/cakephp-environments
=================================

CakePHP plugin to handle environments-level configuration

3.0.0(10y ago)4785.9k↓16.6%12MITPHPPHP &gt;=5.4

Since Apr 13Pushed 10y ago10 watchersCompare

[ Source](https://github.com/josegonzalez/cakephp-environments)[ Packagist](https://packagist.org/packages/josegonzalez/cakephp-environments)[ Docs](https://github.com/josegonzalez/cakephp-environments)[ RSS](/packages/josegonzalez-cakephp-environments/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (4)Versions (4)Used By (0)

[![Build Status](https://camo.githubusercontent.com/8cd856b3ea482fa52b4f45467434723c295939c7ff7926a82f1b3b30b116ef9b/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6a6f7365676f6e7a616c657a2f63616b657068702d656e7669726f6e6d656e74732f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/josegonzalez/cakephp-environments)[![Coverage Status](https://camo.githubusercontent.com/368722b54715dc253e5b31691a0400105d01c3525d5fe943b09f79b28c1d222e/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6a6f7365676f6e7a616c657a2f63616b657068702d656e7669726f6e6d656e74732e7376673f7374796c653d666c61742d737175617265)](https://coveralls.io/r/josegonzalez/cakephp-environments?branch=master)[![Total Downloads](https://camo.githubusercontent.com/cdc2edefd792a42844be91105b9c5e632ace680cfbbb32b3c17a525a7fee3ffb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a6f7365676f6e7a616c657a2f63616b657068702d656e7669726f6e6d656e74732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/josegonzalez/cakephp-environments)[![Latest Stable Version](https://camo.githubusercontent.com/417744608bde3e2d8c4bfcb77310b5d60de8d1d8a208152da58272ccea6b78dc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a6f7365676f6e7a616c657a2f63616b657068702d656e7669726f6e6d656e74732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/josegonzalez/cakephp-environments)[![Documentation Status](https://camo.githubusercontent.com/09ebf605bb9ef4847278365c6ea9d03ce371fa557ad1ab453c00054f7ba77be0/68747470733a2f2f72656164746865646f63732e6f72672f70726f6a656374732f63616b657068702d656e7669726f6e6d656e74732f62616467652f3f76657273696f6e3d6c6174657374267374796c653d666c61742d737175617265)](https://readthedocs.org/projects/cakephp-environments/?badge=latest)[![Gratipay](https://camo.githubusercontent.com/40a48c7b3fc02e9d39dd715fe09e404c4cb2e89288c6ace0773d2aab6913b46f/68747470733a2f2f696d672e736869656c64732e696f2f67726174697061792f6a6f7365676f6e7a616c657a2e7376673f7374796c653d666c61742d737175617265)](https://gratipay.com/~josegonzalez/)

Environments Plugin
===================

[](#environments-plugin)

A plugin to handle environment-level configuration

Requirements
------------

[](#requirements)

- CakePHP 3.x

Installation
------------

[](#installation)

*\[Using [Composer](http://getcomposer.org/)\]*

[View on Packagist](https://packagist.org/packages/josegonzalez/cakephp-environments), and copy the json snippet for the latest version into your project's `composer.json`. Eg, v. 1.0.0 would look like this:

```
{
	"require": {
		"josegonzalez/cakephp-environments": "3.0.0"
	}
}
```

### Enable plugin

[](#enable-plugin)

You need to enable the plugin your `config/bootstrap.php` file:

```
Plugin::load('Josegonzalez/Environments');
```

If you are already using `Plugin::loadAll();` before usage, then this is not necessary.

Usage
-----

[](#usage)

Setup a directory structure as follows:

```
config/environments.php
config/environments/production.php
config/environments/staging.php
config/environments/development.php

```

We specify multiple **environment** files to separate the various configurations and make it easy to inspect a given environment. This is not necessary, but useful if you are configuring a large amount of information.

Your `environments.php` should contain the following:

```

```

Then, you need to include the `environments.php` file you created in your application, for example in `bootstrap.php`:

```
include dirname(__FILE__) . DS . 'environments.php';
```

This will:

- Load the environments plugin in cases where it may not already be loaded
- Include every environment, in order of specificity (development is usually last)
- Start the environment

### Environment Configuration

[](#environment-configuration)

Each environment may be configured as follows:

```
Josegonzalez\Environments\Environment::configure($name, $params, $config = null, $callable = null);
```

Example usage of the `\Josegonzalez\Environments\Environment::configure()` call is available in the `config/environments` folder of this plugin.

- `$name`: Usually something like `production` or `development`. Good practice is to name it the same as the file it was in, so that there isn't any confusion as to what a given env file contains
- `$params`: An array or boolean of environment variables used to check whether this environment applies. If a boolean and set to true, this environment is automatically initiated. A value of `true` should only be used for development:

    If a previous environment is not enabled, this one will be set

    ```
    \Josegonzalez\Environments\Environment::configure(
        'development',
        true,
        ['debug' => true]
    );
    ```

    If an array, the **keys** may be function names that are called, with the **values** being passed to it:

    ```
    \Josegonzalez\Environments\Environment::configure(
        'development',
        [
        	'some_function' => 'aValueForThisCheck',
        	'another_function' => 'aDifferentValueForThisCheck',
    	]
    );
    ```

    In all other cases, we simply check the environment:

    ```
    \Josegonzalez\Environments\Environment::configure(
        'octo_development',
        [
        	'SERVER_NAME' => 'octo-example.dev',
        ]
    );

    \Josegonzalez\Environments\Environment::configure(
        'bear_development',
        [
        	'SERVER_NAME' => 'bear-example.dev',
        ]
    );

    \Josegonzalez\Environments\Environment::configure(
        'development',
        [
    		'CAKE_ENV' => 'development',
    	]
    );
    ```

    If we are running in CLI, the only check enforced is `CAKE_ENV`, and the value MUST be the name of the environment:

    ```
    CAKE_ENV=production Console/cake bake all
    ```

    If the `CAKE_ENV` environment variable is set at all, it takes precedence over everything, including a boolean value for `$params`.
- `$config`: If set, an array of `keys` =&gt; `values` that are set via `Configure::write()`. Useful for batch-setting api keys, database connection information, etc.
- `$callable`: A PHP callable, such as `['ClassName', 'functionName']`. It is also possible to use an anonymous function. This is the preferred method of setting information that might depend upon the value of some function call.

License
-------

[](#license)

Copyright (c) 2014 Jose Diaz-Gonzalez

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.

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity44

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 73.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~304 days

Total

3

Last Release

3810d ago

Major Versions

1.0.1 → 3.0.02015-12-13

### Community

Maintainers

![](https://www.gravatar.com/avatar/f38b500117ee9754ea7a4c56b800c8151ca0605b1715a3b2ff054aae504f7393?d=identicon)[josegonzalez](/maintainers/josegonzalez)

---

Top Contributors

[![josegonzalez](https://avatars.githubusercontent.com/u/65675?v=4)](https://github.com/josegonzalez "josegonzalez (30 commits)")[![davidsteinsland](https://avatars.githubusercontent.com/u/125661?v=4)](https://github.com/davidsteinsland "davidsteinsland (8 commits)")[![dkullmann](https://avatars.githubusercontent.com/u/422899?v=4)](https://github.com/dkullmann "dkullmann (2 commits)")[![ramiroaraujo](https://avatars.githubusercontent.com/u/46276?v=4)](https://github.com/ramiroaraujo "ramiroaraujo (1 commits)")

---

Tags

configurationcakephpenvironments

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/josegonzalez-cakephp-environments/health.svg)

```
[![Health](https://phpackages.com/badges/josegonzalez-cakephp-environments/health.svg)](https://phpackages.com/packages/josegonzalez-cakephp-environments)
```

###  Alternatives

[dereuromark/cakephp-tools

A CakePHP plugin containing lots of useful and reusable tools

338920.1k32](/packages/dereuromark-cakephp-tools)[markstory/asset_compress

An asset compression plugin for CakePHP. Provides file concatenation and a flexible filter system for preprocessing and minification.

3761.0M11](/packages/markstory-asset-compress)[dereuromark/cakephp-shim

A CakePHP plugin to shim applications between major framework versions.

401.0M11](/packages/dereuromark-cakephp-shim)[cakedc/tiny-mce

TinyMCE Plugin for CakePHP

10790.2k](/packages/cakedc-tiny-mce)[dereuromark/cakephp-dto

A CakePHP plugin for generating immutable Data Transfer Objects with full type safety

2988.9k3](/packages/dereuromark-cakephp-dto)[dereuromark/cakephp-geo

A CakePHP plugin around geocoding tools and helpers.

51174.9k4](/packages/dereuromark-cakephp-geo)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
