Download the PHP package yiisoft/config without Composer

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

Yii

Yii Config


Latest Stable Version Total Downloads Build status Code Coverage Mutation testing badge static analysis type-coverage

This Composer plugin provides assembling of configurations distributed with composer packages. It is implementing a plugin system which allows to provide the configuration needed to use a package directly when installing it to make it run out-of-the-box. The package becomes a plugin holding both the code and its default configuration.

Requirements

Installation

How it works?

The package consist of two parts: Composer plugin and config loader.

After composer updates its autoload file, and that happens after dump-autoload, require, update or remove, Composer plugin:

In the application entry point, usually index.php, we create an instance of config loader and require a configuration we need:

The web in the above is a config group. The config loader obtains it runtime according to the merge plan. The configuration consists of three layers that are loaded as follows:

Please note that same named keys are not allowed within a configuration layer.

When calling the get() method, if the configuration group does not exist, an \ErrorException will be thrown. If you are not sure that the configuration group exists, then use the has() method:

Config groups

Each config group represents a set of configs that is merged into a single array. It is defined per package in each package composer.json:

In the above example the mapping keys are config group names and the values are configuration files and references to other config groups. The file paths are relative to the source-directory, which by default is the path where composer.json is located.

Markers


Define your configs like the following:

A special variable $params is read from config (by default, group is named params).

Using custom group for $params

By default, $params variable is read from params group. You can customize the group name via constructor of Config:

You can pass null as $params group name. In this case $params will empty array.

Using sub-configs

In order to access a sub-config, use the following in your config:

Options

A number of options is available both for Composer plugin and a config loader. Composer options are specified in composer.json:

source-directory

The source-directory option specifies where to read the configs from for a package the option is specified for. It is available for all packages, including the root package, which is typically an application. The value is a path relative to where the composer.json file is located. The default value is an empty string.

If you change the source directory for the root package, don't forget to adjust configs path when creating an instance of Config. Usually that is index.php:

vendor-override-layer

The vendor-override-layer option adds a sublayer to the vendor, which allocates packages that will override the vendor's default configurations. This sublayer is located between the vendor and application layers.

This can be useful if you need to redefine default configurations even before the application layer. To do this, you need to create your own package with configurations meant to override the default ones:

And in the root file composer.json of your application, specify this package in the vendor-override-layer option:

In the same way, several packages can be added to this sublayer:

You can use wildcard pattern if there are too many packages:

For more information about the wildcard syntax, see the yiisoft/strings.

Please note that in this sublayer keys with the same names are not allowed similar to other layers.

merge-plan-file

This option allows you to override path to merge plan file. It is .merge-plan.php by default. To change it, set the value:

This can be useful when developing. Don't forget to set same path in Config constructor when changing this option.

build-merge-plan

The build-merge-plan option allows you to disable creation/updating of the config/.merge-plan.php. Enabled by default, to disable it, set the value to false:

This can be useful when developing. If the config package is a dependency of your package, and you do not need to create a merge plan file when developing your package. For example, this is implemented in yiisoft/yii-runner.

package-types

The package-types option define package types for process by composer plugin. By default, it is "library" and "composer-plugin". You can override default value by own types:

Environments

The plugin supports creating additional environments added to the base configuration. This allows you to create multiple configurations for the application such as production and development.

Note that environments are supported on application level only and are not read from configurations of packages.

The environments are specified in the composer.json file of your application:

Configuration defines the merge process. One of the environments from config-plugin-environments is merged with the main configuration defined by config-plugin. In given example, in the dev environment we use $web configuration from the main environment.

This configuration has the following structure:

To choose an environment to be used you must specify its name when creating an instance of Config:

If defined in an environment, params will be merged with params from the main configuration, and could be used as $params in all configurations.

Configuration in a PHP file

You can define configuration in a PHP file. To do it, specify a PHP file path in the extra section of the composer.json:

Configurations are specified in the same way, only in PHP format:

If you specify the file path, the remaining sections (config-plugin-*) in composer.json will be ignored and configurations will be read from the PHP file specified. The path is relative to where the composer.json file is located.

Configuration modifiers

Recursive merge of arrays

By default, recursive merging of arrays in configuration files is not performed. If you want to recursively merge arrays in a certain group of configs, such as params, you must pass RecursiveMerge modifier with specified group names to the Config constructor:

If you want to recursively merge arrays to a certain depth, use the RecursiveMerge::groupsWithDepth() method:

Note: References to another configs use recursive modifier of root group.

Reverse merge of arrays

Result of reverse merge is being ordered descending by data source. It is useful for merging module config with base config where more specific config (i.e. module's) has more priority. One of such cases is merging events.

To enable reverse merge pass ReverseMerge modifier with specified group names to the Config constructor:

Note: References to another configs use reverse modifier of root group.

Remove elements from vendor package configuration

Sometimes it is necessary to remove some elements of vendor packages configuration. To do this, pass RemoveFromVendor modifier to the Config constructor.

Remove specified key paths:

Remove specified configuration groups:

Combine modifiers

Config supports simultaneous use of several modifiers:

Commands

yii-config-copy

The plugin adds extra yii-config-copy command to Composer. It copies the package config files from the vendor to the config directory of the root package:

Copies all config files of the yiisoft/view package:

Copies the specified config files of the yiisoft/view package:

In order to avoid conflicts with file names, a prefix is added to the names of the copied files: yiisoft-view-params.php, yiisoft-view-web.php.

yii-config-rebuild

The yii-config-rebuild command updates merge plan file. This command may be used if you have added files or directories to the application configuration file structure and these were not specified in composer.json of the root package. In this case you need to add to the information about new files to composer.json of the root package by executing the command:

yii-config-info

The yii-config-rebuild command displays application or package configuration details.

Documentation

If you need help or have a question, the Yii Forum is a good place for that. You may also check out other Yii Community Resources.

License

The Yii Config package is free software. It is released under the terms of the BSD License. Please see LICENSE for more information.

Maintained by Yii Software.

Credits

The plugin is heavily inspired by Composer config plugin originally created by HiQDev (https://hiqdev.com/) in 2016 and then adopted by Yii.

Support the project

Open Collective

Follow updates

Official website Twitter Telegram Facebook Slack


All versions of config with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
composer-plugin-api Version ^2.0
yiisoft/arrays Version ^3.0
yiisoft/strings Version ^2.0
yiisoft/var-dumper Version ^1.1
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 yiisoft/config contains the following files

Loading the files please wait ....