Download the PHP package brightnucleus/config without Composer

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

Bright Nucleus Config Component

PHP Version Require Scrutinizer Code Quality Code Coverage Build Status Codacy Badge Code Climate

Latest Stable Version Total Downloads Latest Unstable Version License

This is a very lean Config component to help you write reusable code. It only offers basic functionality and is meant to be used in libraries and small projects. If you need a Config component for more complex projects, you should take a look at the Symfony Config Component.

Table Of Contents

Installation

The best way to use this component is through Composer:

Basic Usage

A class that wants to be configurable should accept a ConfigInterface in its constructor, so that the Config can be injected. The surrounding code then should inject an instance of an object (for example the generic Config that is provided with this component). This way, the class that accepts the Config can be written in a 100% reusable way, while all project-specific stuff will be injected through the Config.

Working With Config Data

Checking The Existence Of A Key

To check whether the configuration has a certain key, you can use the ConfigInterface::hasKey($key) method, or, if you are using the ConfigTrait in your class, you can use the convenience method $this->hasConfigKey($key).

Getting The Value Of A Key

To get the configuration value of a certain key, you can use the ConfigInterface::getKey($key) method, or, if you are using the ConfigTrait in your class, you can use the convenience method $this->getConfigKey($key).

If you use closures in your Config file, you can also use the convenience function $this->getConfigCallable( $key, array $args ) provided by the ConfigTrait, which will immediately execute the closure by passing it the provided arguments, and return the resultant value instead.

Nested Keys

If your keys are nested, you can provide multiple levels of keys in one request. So, whenever you need to provide a key and want to use a nested one, you can either provide a comma-separated list of keys ( $this->getConfigKey( 'level1', 'level2', 'level3' ); ) or a string that contains the list of keys separated by a delimiter ( $this->getConfigKey( 'level1/level2/level3' ); ).

You can freely mix-and-match these two approaches as you like.

The default delimiters are: /, \ and .. You can choose different delimiters by passing an array of delimiters as a fourth argument to the Configs constructor.

Example - Configuration File

The snippet below shows the basic structure of a config file.

Example - Configurable Class

Here is an example setup of how you could feed this configuration into a plugin.

Example - Getting The Config Into The Class

You can combine all of your configurations into 1 single file and only pass "Sub-Configurations" to the individual components using the getSubConfig() method. This way, you can avoid an additional file access and an additional validation pass for each component.

To create a new instance of a ConfigInterface, you should use the ConfigFactory. The basic method ConfigFactory::create() can take either an array of values, or one or more file names (with absolute paths) as strings.

If you provide a comma-separated list of file names, they are processed consecutively until the first one could be loaded successfully.

There's a convenience function ConfigFactory::createSubConfig() to immediately fetch a sub-config from a loaded config file. This allows you to quickly bypass the vendor/package prefixes and only pass in the relevant data into the new object.

Here's how you can pass the configuration file into the class:

Example - Class That Loads Default Config Unless Config Was Injected

The ConfigTrait provides some convenience functionality that lets you write classes that can receive an injected Config, but fall back to a default configuration file if non was injected.

Here's you can code such a class:

Example - Merging Several Configs Into One

You can provide a comma-separated list of file names to the ConfigFactory::merge() method. They are loaded consecutively and merged into one coherent Config. For each duplicate Config key, the value in the later files will override the value in the earlier files.

For our example, we'll define a new Config file called override_settings.php, that overrides a key that was already set in the default Config file.

Config Formats

The Bright Nucleus Config component can be extended to load a multitude of different file formats. The base package includes a very minimal PHPLoader class. It can load basic PHP files that just return an array.

Additional packages that add other formats like JSON or YAML are planned and will be released soon.

Custom loaders are lazily instantiated only when needed.

Advanced Usage

Configuration Schema

TODO

Configuration Validation

TODO

Custom Implementations

TODO

Contributing

All feedback / bug reports / pull requests are welcome.

License

This code is released under the MIT license.

For the full copyright and license information, please view the LICENSE file distributed with this source code.


All versions of config with dependencies

PHP Build Version
Package Version
Requires symfony/options-resolver Version >=2.8
brightnucleus/exceptions Version >=0.2
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 brightnucleus/config contains the following files

Loading the files please wait ....