2017 © Pedro Peláez
 

cakephp-plugin cakephp-environments

CakePHP plugin to handle environments-level configuration

image

josegonzalez/cakephp-environments

CakePHP plugin to handle environments-level configuration

  • Friday, January 22, 2016
  • by josegonzalez
  • Repository
  • 10 Watchers
  • 47 Stars
  • 39,461 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 12 Forks
  • 0 Open issues
  • 4 Versions
  • 2 % Grown

The README.md

Build Status Coverage Status Total Downloads Latest Stable Version Documentation Status Gratipay, (*1)

Environments Plugin

A plugin to handle environment-level configuration, (*2)

Requirements

  • CakePHP 3.x

Installation

[Using Composer], (*3)

View on Packagist, and copy the json snippet for the latest version into your project's composer.json. Eg, v. 1.0.0 would look like this:, (*4)

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

Enable plugin

You need to enable the plugin your config/bootstrap.php file:, (*5)

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

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

Usage

Setup a directory structure as follows:, (*7)

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., (*8)

Your environments.php should contain the following:, (*9)


Then, you need to include the environments.php file you created in your application, for example in bootstrap.php:, (*10)

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

This will:, (*11)

  • 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

Each environment may be configured as follows:, (*12)

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., (*13)

  • $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:, (*14)

    If a previous environment is not enabled, this one will be set, (*15)

    \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:, (*16)

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

    In all other cases, we simply check the environment:, (*17)

    \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:, (*18)

    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., (*19)

  • $config: If set, an array of keys => 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

Copyright (c) 2014 Jose Diaz-Gonzalez, (*20)

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:, (*21)

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software., (*22)

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., (*23)

The Versions

22/01 2016

dev-master

9999999-dev https://github.com/josegonzalez/cakephp-environments

CakePHP plugin to handle environments-level configuration

  Sources   Download

MIT

The Requires

 

The Development Requires

configuration cakephp environments

13/12 2015

3.0.0

3.0.0.0 https://github.com/josegonzalez/cakephp-environments

CakePHP plugin to handle environments-level configuration

  Sources   Download

MIT

The Requires

 

The Development Requires

configuration cakephp environments

29/11 2015

1.0.1

1.0.1.0 http://github.com/josegonzalez/cakephp-environments

CakePHP plugin to handle environments-level configuration

  Sources   Download

MIT

The Requires

 

configuration cakephp environments

13/04 2014

1.0.0

1.0.0.0 http://github.com/josegonzalez/cakephp-environments

CakePHP plugin to handle environments-level configuration

  Sources   Download

MIT

The Requires

 

configuration cakephp environments