Download the PHP package caseyamcl/configula without Composer

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

Configula

Configula is a configuration library for PHP 7.3+.

Latest Version on Packagist Github Build PHPStan Level 8 Total Downloads

Use this library when you want to load configuration from the filesystem, environment, and other sources. It implements your configuration values as an immutable object in PHP. It is a framework-independent tool, and can be easily used in any PHP application.

Features

Installation

Need PHP v7.1, 7.2 or Symfony v3 compatibility?

Configula v4.x is compatible with PHP v7.3+ or v8.0+. If you need PHP 7.1, 7.2 compatibility, instruct Composer to use the 3.x version of this library instead of the current one:

Need PHP v5.* compatibility?

Configula Version 2.x is compatible with PHP v5.3+. If you need PHP 5.x compatibility, instruct Composer to use the 2.x version of this library instead of the current one:

Upgrading?

Refer to UPGRADE.md for notes on upgrading from Version 2.x, 3.x to v4.

Loading Configuration

You can use the Configula\ConfigFactory to load configuration from files, the environment or other sources:

Or, if you are loading an array, you can instantiate Configula\ConfigValues directly:

Or, you can manually invoke any of the loaders in the Configula\Loader namespace:

Accessing Values

The Configula\ConfigValues object provides several ways to access your configuration values:

Accessing values using dot notation

Configula supports accessing values via dot-notation (e.g some.nested.var):

Property-like access to your config settings via __get() and __isset():

Iterator and count access to your config settings:

Callable access to your config settings via __invoke():

Array access to your config settings:

Merging Configuration

Since Configula\ConfigValues is an immutable object, you cannot mutate the configuration once it is set. However, you can merge values and get a new copy of the object using the merge or mergeValues methods:

Configula performs a deep merge. Nested arrays are traversed and the last value always takes precedence.

Note that Configula does not deep merge nested objects, only arrays.

Iterator and Count

The built-in ConfigValues::getIterator() and ConfigValues::count() methods flattens nested values when iterating or counting:

If you want to iterate only the top-level items in your configuration, you can use the getArrayCopy() method:

Using the Folder Loader - Config Folder Layout

The folder loaders in Configula will load files with the following extensions (you can add your own custom loaders; see below):

The ConfigFactory::loadPath($path) method will traverse directories in your configuration path recursively.

The ConfigFactory::loadSingleDirectory($path) method will load your configuration in a single directory non-recursively.

Local Configuration Files

In some cases, you may want to have local configuration files that override the default configuration files. There are two ways to do this:

  1. prefix the default configuration file extension with .dist (e.g. config.dist.yml), and name the local configuration file normally: config.yml
  2. name the default configuration file normally (e.g. config.yml) and prefix .local to the extension for the local configuration file: config.local.yml.

Either way will work, and you could even combine approaches if you want. The file iterator will always cascade merge files in this order:

This is useful if you want to keep local configuration files out of revision control. Choose a paradigm, and simply add the following to your .gitignore

Example

Consider the following directory layout...

If you use ConfigFactory::loadPath('/my/app/config'), the files will be parsed according to their extension and values will be merged in the following order (values in files that are later in the list will clobber earlier values):

Loading from environment variables

There are two common ways that configuration is generally stored in environment:

  1. As multiple environment variables (perhaps loaded by phpDotEnv or Symfony dotEnv, or exposed by Heroku/Kubernetes/etc.).
  2. As a single environment variable with a JSON-encoded value, which exposes the entire configuration tree.

Configula supports both. You can also write your own loader if your environment is different.

Loading multiple environment variables

Configula supports loading environment variables as configuration values using getenv(). This is the 12 Factor App way of doing things.

Common use-cases for this loader include:

  1. Loading system environment as config values
  2. Loading values using phpDotEnv or Symfony dotEnv
  3. Accessing values injected into the environment by a cloud provider (Kubernetes, Docker, Heroku, etc.)

Default environment variable loading

The default behavior is to load the configuration values directly:

Result:

Load only environment variables with prefix

You can load ONLY environment variables with a specific prefix. Configula will remove the prefix when loading the configuration:

Result:

Convert environment variables to nested configuration

You can convert a flat list into nested config values by passing a delimiter to break on:

Result:

This allows you to access nested values as an array:

Transform environment variables to lower-case

You can transform all the values to lower-case by passing TRUE as the last argument:

Result:

Loading environment variables with regex pattern

Instead of using a prefix, you can pass a regex string to limit returned values:

Result:

Loading a single JSON-encoded environment variable

Use the Configula\Loader\JsonEnvLoader to load a JSON environment variable:

Loading from multiple loaders

You can use the Configula\ConfigFactory::loadMultiple() to load from multiple sources and merge results. This method accepts an iterator where each value is one of the following:

Any other value in the iterator will trigger an \InvalidArgument exception

Handling Errors

All exceptions extend Configula\Exception\ConfigException. You can catch this exception to catch certain types of Configula errors during loading and reading of configuration values.

Loading Exceptions:

NOTE: Configula does NOT catch non-Configula exceptions and convert them to Configula exceptions. If you wan to catch all conceivable errors when loading configuration, you should surround your configuration loading code with a try...catch (\Throwable $e).

Config Value Exceptions:

Extending the ConfigValues class (for IDE type-hinting)

While it is entirely possible to use the Configula\ConfigValues class directly, you might also want to provide some application-specific methods to load configuration values. This creates a better developer experience.

Note: Notice that the example above uses the InvalidConfigValueException, which is included with Configula for exactly this use-case.

You can use your custom AppConfig class as follows:

Using Symfony Config to define a configuration schema

In some cases, you may wish to strictly control what configuration values are allowed and also validate those values when loading the configuration. The Symfony Config Component provides an excellent mechanism for accomplishing this.

First, include the Symfony Config Component library in your application:

Then, create a class that provides your configuration tree. Refer to the Symfony Docs for all the cool stuff you can do in your configuration tree:

Load your configuration as you normally would, and then pass the resulting ConfigValues object through the Symfony filter:

Writing your own loader

In addition to using the built-in loaders, you can write your own loader. There are two ways to do this:

Create your own file loader

Extend the Configula\Loader\AbstractFileLoader to write your own loader that reads data from a file.

Use it:

If you want to use the FolderLoader and automatically map your new type to a file extension, you can do so:

Create your own custom loader

Create your own implementation of Configula\Loader\ConfigLoaderInterface, and you can load configuration from anywhere:

Use it:

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of configula with dependencies

PHP Build Version
Package Version
No informations.
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 caseyamcl/configula contains the following files

Loading the files please wait ....