Download the PHP package xapon/yii2-environment without Composer

On this page you can find all versions of the php package xapon/yii2-environment. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package yii2-environment

yii2-environment Latest Stable Version

Environment-based configuration class (for example in development, testing, staging and production) for Yii2 basic application template.

It is used to set configuration and debugging depending on environment. You can predefine configurations for use in different environments, like development, testing, staging and production.

This library is mainly based on Environment extension for Yii 1 by Marco van 't Wout. Those who have accustomed with it's previous version could easily use this version with Yii2. It is probably useless for advanced application template since environment management for it has already been provided by framework developers. Nevertheless, I don't like advanced template for several reasons but do want to handle environment configurations in basic template.

The main config (main.php) is extended to include the Yii path and debug flags. There are mode_<environment>.php files for overriding and extending main.php for specific environments. Additionally, you can overrride the resulting config by using a local.php config, to make changes that will only apply to your specific installation.

This class was designed to have minimal impact on the default Yii generated files. Minimal changes to the index/bootstrap and existing config files are needed.

The Environment is determined with PHP's getenv(), which searches $_SERVER and $_ENV. There are multiple ways to set the environment depending on your preference. Setting the environment variable is trivial on both Windows and Linux, instructions included. You can optionally override the environment by creating a mode.php in the config directory.

If you want to customize this class or its config and modes, extend it! (see ExampleEnvironment.php)

Requirements

Tested on current (unstable) Yii2, and will probably work after final release (I'll keep track on it's updates to be sure).

Installation

Installation via Composer

The preferred installation method is through Composer. We assume the vendor directory is placed in application root.

  1. Add the dependency to your project

  2. Modify your web/index.php (and other bootstrap files)
  3. Modify your main.php config file and add mode specific config files
  4. Set your local environment (see next section)

Installation from zip file

Download zip archive and extract it to, say, components directory. Then include the Environment class manually in your index.php since composer autoload will not be available for it.

Setting environment

Here are some examples for setting your environment to DEV.

Windows

  1. Go to: Control Panel > System > Advanced > Environment Variables
  2. Add new SYSTEM variable: name = YII_ENV, value = DEV

Linux/Mac

  1. Open profile files:
    • Global bash shell: /etc/profile
    • Apache (as service): /etc/apache2/envvars
  2. Add the following line: export YII_ENV="DEV"

Apache only (cannot be used for console applications)

  1. Check if mod_env is enabled
  2. Open your httpd.conf or create a .htaccess file
  3. Add the following line: SetEnv YII_ENV DEV

Project only

  1. Create a file mode.php in the config directory of your application.
  2. Set the content of the file to: DEV

Usage

Update bootstrap files

See example-index/index.php

Structure of config directory

Your config/ directory will look like this:

Modify your config/main.php

See example-config/main.php

Optional: in configConsole you can copy settings from configWeb by using value key @ (see examples folder).

Create mode-specific config files

Create config/mode_<mode>.php files for the different modes. These will override or merge attributes that exist in the main config.

Optional: also create a config/local.php file for local overrides.

Credits

Original library for Yii 1: https://github.com/marcovtwout/yii-environment

Notes


All versions of yii2-environment with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package xapon/yii2-environment contains the following files

Loading the files please wait ....