PHPackages                             quest/cakephp-environment - 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. quest/cakephp-environment

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

quest/cakephp-environment
=========================

Environments Plugin for CakePHP

1.0.0(11y ago)2291MITPHP

Since Jul 2Pushed 9y ago2 watchersCompare

[ Source](https://github.com/quest/cakephp-environment)[ Packagist](https://packagist.org/packages/quest/cakephp-environment)[ Docs](http://victorsanmartin.com)[ RSS](/packages/quest-cakephp-environment/feed)WikiDiscussions master Synced 3w ago

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

[![Build Status](https://camo.githubusercontent.com/ab4c14c31e2bcb02e9a05dad820b611d9e45470f161712e5e003f7c90567caf3/68747470733a2f2f7472617669732d63692e6f72672f71756573742f63616b657068702d656e7669726f6e6d656e742e7376673f6272616e63683d646576)](https://travis-ci.org/quest/cakephp-environment)

Environment Plugin for CakePHP
==============================

[](#environment-plugin-for-cakephp)

for CakePHP 2.x

Requirement
-----------

[](#requirement)

- PHP version: PHP 5.2+
- CakePHP version: 2.x Stable

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

[](#installation)

- Clone/Copy the files in this diectory into `app/Plugin/Environment`
- Ensure the plugin is loaded in `app/Config/bootstrap.php` by calling `CakePlugin::load('Environment', array('bootstrap' => true))`

### Using Composer

[](#using-composer)

Add the plugin to your project's `composer.json` - something like this:

```
	{
	    "require": {
	        "quest/cakephp-environment": "master"
	    }
	}

```

Because this plugin has the type `cakephp-plugin` set in its own `composer.json`, Composer will install it inside your `/Plugins` directory, rather than in the usual vendors file. It is recommended that you add `/Plugins/Environment` to your .gitignore file. (Why? [read this](http://getcomposer.org/doc/faqs/should-i-commit-the-dependencies-in-my-vendor-directory.md).)

### Manual

[](#manual)

- Download this:
- Unzip that download.
- Copy the resulting folder to `app/Plugin`
- Rename the folder you just copied to `Environment`

### GIT Submodule

[](#git-submodule)

In your app directory type:

```
  git submodule add -b master git://github.com/quest/cakephp-environment.git Plugin/Environment
  git submodule init
  git submodule update
```

### GIT Clone

[](#git-clone)

In your `Plugin` directory type:

```
    git clone -b master git://github.com/quest/cakephp-environment.git Environment
```

Enable plugin
-------------

[](#enable-plugin)

In 2.0 you need to enable the plugin in your `app/Config/bootstrap.php` file:

```
    CakePlugin::load('Environment', array('bootstrap' => true));
```

Usage
-----

[](#usage)

Create file `app/Config/env.php` with this example content.

```
	/**
	 * Domains environments
	 * IMPORTANT: This lines on the top of the file
	 */
		Configure::write('Environment.domains', array(
			'development' => '.*',
			'production' => '^(.+\.)?mysite\.com$'
		));

	/**
	 * Development settings
	 */
		Environment::write(array(
			'debug' => 2,
			'Security.salt' => '6978hjkhKjkhskjhd698KGNSLdsDLsdKSAsdf8778sdfg',
			'Security.cipherSeed' => '57283694289374902834892039823756894'
		), 'development');

	/**
	 * Production settings
	 */
		Environment::write(array(
			'debug' => 0
		), 'production');
```

### Environment Detection

[](#environment-detection)

In order to detect the project environment and apply their settings, use the application hostname, just like this:

```
	Configure::write('Environment.domains', array(
		'development' => '^myapp\.local$',
		'production' => '^mycapp\.com$'
	));
```

You must use regex to define the hostname. You can create many environments as you want.

### Methods

[](#methods)

#### Environment::get()

[](#environmentget)

Get the current environment depending on hostname requested:

```
	echo Environment::get(); // print 'development' text
```

#### Environment::set(string $environment)

[](#environmentsetstring-environment)

Avoid set the environment based on hostname request, by using `set()` method. It will overwrite any other environment previously settled.

```
	Environment::set('testing'); // true
```

#### Environment::is(string $environment)

[](#environmentisstring-environment)

Use this method to check the current/working environment.

```
	if (Environment::is('development')) {
		echo 'this is development';
	}
	else {
		echo 'this is ' . Environment::get();
	}
```

#### Environment::write()

[](#environmentwrite)

You can write environment settings by using the `write()` method in two ways:

Multiple

```
	Environment::write(array(
		'debug' => 2,
		'database' => array(
			'login' => 'root',
			'host' => 'localhost',
			'password' => '',
		)
	), 'development');
```

Single

```
	Environment::write('debug', 0, 'production');
```

#### Environment::read()

[](#environmentread)

Read environment settings by using the `read()` method:

- $key: Key to find
- $environment: Optional — Environment scope

```
	// databases.php
	class DATABASE_CONFIG {

		public $default = array(
			'datasource' => 'Database/Mysql',
			'persistent' => false,
			'host' => Environment::read('database.host'),
			'login' => Environment::read('database.login'),
			'password' => Environment::read('database.password'),
			'database' => 'database_name',
			'prefix' => '',
			'encoding' => 'utf8',
		);
	}
```

`Environment::write()` also can be used to update or modify Cake's `app/Config/core.php` file settings. For example:

```
	/**
	 * Development settings
	 */
		Environment::write(array(
			'debug' => 2,
			'Security.salt' => '6978hjkhKjkhskjhd698KGNSLdsDLsdKSAsdf8778sdfg',
			'Security.cipherSeed' => '57283694289374902834892039823756894'
		), 'development');

	/**
	 * Production settings
	 */
		Environment::write(array(
			'debug' => 0,
			'Security.salt' => '6978hjkhKjkhskjhd698KGNSLdsDLsdKSAsdf8778sdfg',
			'Security.cipherSeed' => '57283694289374902834892039823756894'
		), 'production');
```

TODO
----

[](#todo)

Support
-------

[](#support)

To report bugs or request features, please visit the [Issue Tracker](https://github.com/quest/cakephp-environment/issues).

Contributing to this Plugin
---------------------------

[](#contributing-to-this-plugin)

Please feel free to contribute to the plugin with new issues, requests, unit tests and code fixes or new features. If you want to contribute some code, create a feature branch from develop, and send us your pull request. Unit tests for new features and issues detected are mandatory to keep quality high.

License
-------

[](#license)

Copyright 2014, [Victor San Martín](http://twitter.com/questchile)

Licensed under [The MIT License](http://www.opensource.org/licenses/mit-license.php)
Redistributions of files must retain the above copyright notice.

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

4374d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6877?v=4)[Victor San Martin](/maintainers/quest)[@quest](https://github.com/quest)

---

Top Contributors

[![quest](https://avatars.githubusercontent.com/u/6877?v=4)](https://github.com/quest "quest (25 commits)")

---

Tags

utilitycakephpenvironments

### Embed Badge

![Health badge](/badges/quest-cakephp-environment/health.svg)

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

###  Alternatives

[helsingborg-stad/municipio

A bootstrap theme for creating municipality sites.

4028.3k10](/packages/helsingborg-stad-municipio)[mautic/core

Mautic Open Source Distribution

9.8k2.6k9](/packages/mautic-core)[mediawiki/maps

Adds various mapping features to MediaWiki

78149.7k3](/packages/mediawiki-maps)[josegonzalez/cakephp-environments

CakePHP plugin to handle environments-level configuration

4689.8k](/packages/josegonzalez-cakephp-environments)[civicrm/civicrm-drupal-8

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

19246.3k2](/packages/civicrm-civicrm-drupal-8)[altis/core

Core module for Altis

19222.5k2](/packages/altis-core)

PHPackages © 2026

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