Download the PHP package jasny/config without Composer

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

Jasny's Config class

Build Status Code Coverage Scrutinizer Code Quality SensioLabsInsight

Configure your application. Implements PSR-11 to be used as container.

Installation

Jasny Config is registred at packagist as jasny/config and can be easily installed using composer.

composer require jasny/config

Usage

Loaders

The DelegateLoader can pick a loader based on class name or file extension.

For every loader; a Jasny\Config\LoadException is thrown if the loader can't load the settings.

Dir

DirLoader loader will traverse through every file in a directory. It uses the filename (without extension) as key name.

option type default
recursive bool false Traverse recursively through subdirectories
optional bool false Return empty config is directory doesn't exist
base_path string getcwd() Basepath for relative paths

Ini

IniLoader parses an INI file using parse_ini_file.

option type default
process_sections bool false Group settings by section name
mode enum INI_SCANNER_NORMAL Mode of parsing options (off = false, etc)
optional bool false Return empty config is file doesn't exist
base_path string getcwd() Basepath for relative paths

Json

JsonLoader parses a JSON file using json_decode.

option type default
optional bool false Return empty config is file doesn't exist
base_path string getcwd() Basepath for relative paths

Yaml

YamlLoader parses a YAML file using yaml_parse.

option type default
num int 0 Document to extract from stream (0 is first doc)
callbacks array [] Content handlers for YAML nodes
optional bool false Return empty config is file doesn't exist
base_path string getcwd() Basepath for relative paths

The YamlLoader is used by default if the yaml extension is loaded.

Symfony\Yaml

YamlSymfonyLoader is an alternative loader for YAML, using the Symfony Yaml component.

option type default
optional bool false Return empty config is file doesn't exist
base_path string getcwd() Basepath for relative paths

When constructing the loader a Symfony\Component\Yaml\Parser object may be passed.

Env

EnvLoader maps environment variables to settings. In the mapping the settings key supports dot notation.

option type default
map array (required) key/value pairs from env name to setting key

Example

DynamoDB

DynamoDBLoader allows loading settings from an AWS DynamoDB database. It expects all settings to be in a single item. It will not do a table scan. By default the whole item is taken as settings. Alternatively, use the settings_field option to specify a Map field that holds the settings.

option type default
table string (required) DynamoDB table name
key_field string 'key' Indexed field (typically primary index)
key_value string (required) Value to select item on
settings_field string null within the item that holds the settings

Example

DelegateLoader

The DelegateLoader is a map with loaders, than can automatically pick a loader based on the file extension or class name.

By default it holds all the loaders of this library. You may pass an array of loaders as dependency injection.

Config

The Config object is a dynamic object; settings are added as public properties. It extends the stdClass object.

Upon construction you can pass settings as associative array or stdClass object.

Optionally you can pass a loader. If your config is only in JSON files, consider passing the JsonLoader. This saves the creation of the DelegateLoader and loaders for all other file types.

load()

Load new setting from file or other data source and add it to the config.

load(string|object $source, array $options = [])

This is a fluent interface, so the method returns $this.

Example

merge()

Merge one or more Config (or stdClass) objects into the config.

merge(stdClass $settings, ...)

This is a fluent interface, so the method returns $this.

get()

The Config object implements the PSR-11 ContainerInterface. The get method finds a setting in the config by key. The dot notation may be used to get child properties.

mixed get(string $key)

If the setting doesn't exist, a Jasny\Config\Exception\NotFoundException is thrown.

Example

has()

The has method is part of the PSR-11 ContainerInterface. It checks if a setting exists. As with get(), the key supports the dot notation.

bool has(string $key)

saveAsScript() / loadFromScript()

The saveAsScript() method create parsable string representation of a variable using var_export and store it as a PHP script.

As described in the 500x faster caching article, storing the parsed configuration as a PHP script can make loading it much faster.

The loadFromScript() method can be used to load the settings. It's recommended to use this function rather than just file_exists and include, as checking the file exists would always hit the file system. This function checks the opcode cache first.


All versions of config with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1
jasny/php-functions Version ^3.3|^4.0
psr/container Version ^1.0
jasny/dotkey Version ^1.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 jasny/config contains the following files

Loading the files please wait ....