Download the PHP package popphp/pop-config without Composer

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

pop-config

Build Status Coverage Status

Join the chat at https://discord.gg/TZjgT74U7E

Overview

pop-config is a basic configuration component that helps centralize application configuration values and parameters. Values can be accessed via array notation, object arrow notation, or dot notation for nested values. It can disable changes to the configuration values if need be for the life-cycle of the application. It also can parse configuration values from common formats, such as JSON, XML, INI and YAML.

pop-config is a component of the Pop PHP Framework.

Install

Install pop-config using Composer.

composer require popphp/pop-config

Or, require it in your composer.json file

"require": {
    "popphp/pop-config" : "^5.0.0"
}

Top

Quickstart

Set and access values

Access nested values with dot notation

Nested values can also be accessed directly with dot notation, without manually chaining array access at each level.

A literal key always takes priority over dot-path traversal — a key that happens to contain a . (e.g. 'example.com') is matched exactly first, and only falls back to nested traversal when no literal key matches.

Setting and unsetting values also support dot notation, when changes are allowed:

Note: setting a brand-new dotted key — one that doesn't already exist as a literal key — always creates a nested structure, not a literal key. $config['example.com'] = 'x' on an empty config produces ['example' => ['com' => 'x']], not ['example.com' => 'x']. A literal key only "wins" when it already exists in the underlying data (e.g. loaded from a file).

Allow changes

Changes to configuration values are disabled by default. Attempting to set or unset a value on a config that doesn't allow changes throws a Pop\Config\ChangesNotAllowedException. Check whether a config allows changes with changesAllowed().

Merge new values into the config object

By default, incoming values overwrite existing ones on a collision:

Pass true as the second argument to preserve existing values instead — on a scalar collision, the existing value wins, and two colliding list values are kept as the original list wholesale rather than spliced together.

Note: when a list value collides with an associative array value at the same key (in either merge mode), the two are combined into a hybrid array rather than one side winning outright. For example, merging existing ['a' => ['x', 'y', 'z']] with incoming ['a' => ['one' => 1]] produces ['a' => ['x', 'y', 'z', 'one' => 1]] in both default and preserve: true modes. This asymmetric case is a known limitation — avoid mixing list and associative shapes at the same key across merges if you need predictable results.

mergeFromData() merges directly from a file path (or anything parseData() accepts), parsing it first:

Both merge() and mergeFromData() throw Pop\Config\ChangesNotAllowedException if the config doesn't allow changes; mergeFromData() also throws Pop\Config\ParseException/Pop\Config\UnsupportedFormatException if the file can't be read or parsed.

Convert config object down to a basic array

Convert config object to an ArrayObject

Both are built from a fresh copy of the data — mutating the returned object never affects the original Config.

Parse a configuration file

; This is a sample configuration file config.ini
[foo]
bar = 1
baz = 2

Render config data to a string format

Supported formats include PHP, JSON, XML, INI and YAML

Write config data to a file

writeToFile() picks the format from the filename's extension and writes the rendered output directly to disk:

Supported extensions are the same five formats as render() — an unsupported extension throws Pop\Config\UnsupportedFormatException. Note: a filename with no extension at all (no . in it) silently does nothing — no file is written and no exception is thrown.

A note on YAML support

YAML parsing and rendering go through symfony/yaml (a required dependency, not an optional PHP extension). Two scalar-parsing differences from the previous PECL yaml extension are worth knowing about:

Exceptions

All exceptions thrown by pop-config extend the base Pop\Config\Exception, so existing code catching that class continues to work. More specific subclasses are available for finer-grained handling:

Top


All versions of pop-config with dependencies

PHP Build Version
Package Version
Requires php Version >=8.4.0
popphp/pop-utils Version ^3.0.0
symfony/yaml Version ^6.4 || ^7.0 || ^8.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 popphp/pop-config contains the following files

Loading the files please wait ...