Download the PHP package codemix/yii2-configloader without Composer

On this page you can find all versions of the php package codemix/yii2-configloader. 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-configloader

Yii2 Configloader

Build Status Latest Stable Version Latest Unstable Version Total Downloads License

Build configuration arrays from config files and environment variables.

Features

You can use this extension to solve some or all of the following tasks:

Installation

Install the package with composer:

composer require codemix/yii2-configloader

Description

We mainly use this extension to configure our dockerized yii2 applications. It's good practice to build your docker applications in such a way, that the runtime configuration in productive mode happens solely via environment variables.

But during local development we can loosen these strict requirement a little as we sometimes have to add debug options or the like that should not be part of the main configuration. Here the extension helps to override settings with local configuration files that live outside of version control.

You have several options how to use this extension:

  1. Use only the Yii environment initialization
  2. Use only the configuration loader
  3. Use both

We first show how to use the first two options "standalone" and then a third, combined way that includes all features.

1. Initializing Yii environment

This will set the YII_DEBUG and YII_ENV variables according to the respective environment variables if those are set. It can also load them from a .env file.

In debug mode error_reporting() will also be set to E_ALL.

If you leave away the application path, no .env file will be loaded.

2. Loading configuration

If want to load your configuration with this extenstion, the following naming scheme must be followed:

If you only want to load configuration from files but whithout initializing the Yii environments as shown above, you'd create a Config instance and pass the application base directory and, as second argument, false to the constructor:

2.1 Local configuration

By default local configuration files local.php and local-console.php are not loaded. To activate this feature you can either set the ENABLE_LOCALCONF environment variable (either in your server environment or in .env):

Now the methods will return the corresponding merged results:

Alternatively you can explicitely ask for local configuration:

2.2 Merging custom configuration

You can also inject some other configuration when you fetch the web or console config:

3. Initialize Yii environment and load configuration

Let's finally show a full example that demonstrates how to use all the mentioned features in one go. A typical setup will use the following files:

.env

Here we define the Yii environment and DB credentials. You'd add more config options in the same manner:

config/web.php

This file is later included in the scope of codemix\yii2confload\Config, so you can easily access instance and class methods:

config/console.php

Having access to the config instance allows for example to reuse parts of your web configuration in your console config.

web/index.php

We've streamlined the process of setting up a Config object and loading the Yii 2 bootstrap file into a single method Config::boostrap() which only receives the application directory as argument.

This makes sure that things are loaded in the right order. If you prefer a more verbose version, the code above is equivalent to:

yii

The same approach is used for the console application:


All versions of yii2-configloader with dependencies

PHP Build Version
Package Version
Requires php Version ^7.1.3 || ^8.0
yiisoft/yii2 Version *
vlucas/phpdotenv Version ^5.0
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 codemix/yii2-configloader contains the following files

Loading the files please wait ....