Coder Social home page Coder Social logo

frankfoerster / cakephp-environment Goto Github PK

View Code? Open in Web Editor NEW
9.0 6.0 3.0 48 KB

Manage multiple environments (development, staging, production, etc) in your CakePHP application

License: MIT License

PHP 100.00%
cakephp cakephp3 environment-detection environment cakephp-plugin

cakephp-environment's Introduction

CakePHP 3.x Environment Plugin

Software License Build Status Coverage Status Total Downloads Latest Stable Version

Manage multiple environments in your CakePHP application that differ in, e.g.:

  • database setup
  • configuration settings (Configure)
  • custom feature flags

Requirements

  • PHP 5.6.0+
  • CakePHP 3.x

What it does

The Environment plugin hooks into your bootstrap process to initialize the database configuration, configuration parameters and additional custom logic for different environments.

An environment is defined and detected either by a set of domains (e.g. www.domain.com, domain.com, domain.net) or optionally by the absolute app path on a server (cli).

Install and use the plugin

  1. composer require frankfoerster/cakephp-environment

  2. Copy the example configuration files from example/config/Environment to your app /config/Environment

  3. Add the following lines to your config/bootstrap.php file

    use FrankFoerster\Environment\Environments;
    
    Environments::init();

    before

    ConnectionManager::setConfig(Configure::consume('Datasources'));

    If you want to setup environment specific settings for any "consumed" configuration option, then make sure your environments are initialized before the corresponding Configure::consume('...') call.

Tags ~1.0 are releases for CakePHP 2.x support (master branch).
Tags ~3.0 are releases for CakePHP 3.x support (cake3 branch).

Configuration

The configuration of your environments is managed with multiple files.

  • config.php is the global configuration file that is applied to all detected environments.
  • environment.{name}.php is a single environment file that contains the environment specific $configure array

Settings defined in an environment configuration file are deeply merged with the global configuration.

cakephp-environment's People

Contributors

frankfoerster avatar stephangonder avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

cakephp-environment's Issues

Database Config not being picked up

I have been looking for a good CakePHP Environments plugin and this ones seems to be it. However, at setup I have run into an issue. I created the following file at config/Environment/config.php

    <?php
        $availableEnvironments = [
            'live' => [
                'domain' => [
                    'www.mydomain.com',
                    'mydomain.com'
                ]
            ]
        ];

and then I created the following file config/Environment/environment.live.php

    <?php
        $configure = [
            'debug' => true,

            'Datasources.default' => [
                'host' => 'localhost',
                'username' => 'my_user',
                'password' => 'japdjfolahn44',
                'database' => 'my_db',
                'prefix' => '',
                'quoteIdentifiers' => true,
            ],
        ];

THE ISSUE: Debug is applying correctly. Ie. if I make it false here debugging information will stop showing and if I swich to true I will see all the debugging information. Datasources on the other hand is not applying at all. I am getting an error that my app cannot access the Database and when I check it is trying to connect with configuration from config\app.php.

Can you assist in figuring out why debug applies but Datasources does not? Thanks in advance.

Doesn't work with Cake v3.4

Does this still work with the latest Cake version?

I have setup and installed this but no matter what I do the environment settings are not being used:

config.php

$availableEnvironments = [
    'local' => [
        'domain' => [
            'foo.dev'
        ],
    ],
];

environment.local.php

$configure = [
    
    'debug' => true,

    'Datasources.default' => [
        'host' => 'localhost',
        'username' => 'root',
        'password' => '',
        'database' => 'foobar',
        'prefix' => '',
        'quoteIdentifiers' => true,
    ],
    
];

At the bottom of my bootstrap.php (have also tried adding to top of the file)

use FrankFoerster\Environment\Environments;
Plugin::load('FrankFoerster/Environment');
Environments::init();

I am using the dev url: foo.dev

If I remove the default datasource from app.php then I get an error:

Error: The datasource configuration default was not found in config\app.php.

If I put it back and add the wrong credentials with the correct credentials in the environment.local.php I get db credentials error. Therefore this isn't reading the environment.local.php

It seems this doesn't work with Cake v3.4?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.