承接 quest/cakephp-environment 相关项目开发

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

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

quest/cakephp-environment

Composer 安装命令:

composer require quest/cakephp-environment

包简介

Environments Plugin for CakePHP

README 文档

README

Build Status

Environment Plugin for CakePHP

for CakePHP 2.x

Requirement

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

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

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.)

Manual

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

In your Plugin directory type:

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

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

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

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

Environment::get()

Get the current environment depending on hostname requested:

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

Environment::set(string $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)

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()

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()

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

Support

To report bugs or request features, please visit the Issue Tracker.

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

Copyright 2014, Victor San Martín

Licensed under The MIT License
Redistributions of files must retain the above copyright notice.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-07-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固