Download the PHP package lokhman/silex-config without Composer

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

silex-config

Build Status StyleCI codecov Downloads Packagist License

Lightweight configuration service provider for Silex 2.0+ micro-framework.

This project is a part of silex-tools library.

Installation

You can install silex-config with Composer:

composer require lokhman/silex-config

Documentation

Simple and lightweight configuration provider, which uses JSON files to manage application configuration. Library supports different environments via setting a global environment variable.

use Lokhman\Silex\Provider\ConfigServiceProvider;

$app->register(new ConfigServiceProvider(), [
    'config.dir' => __DIR__ . '/../app/config',
]);

File structure

First off, create a config folder in your application directory and add configuration JSON files one per intended environment (default is local):

/
  app/
    config/
      dev.json
      local.json
      prod.json
      staging.json
    logs/
  src/
  tests/
  vendor/
  web/
    index.php
  composer.json
  ...

Config files

Next, add all your defaults to the config files, e.g.:

{
    "env": "%__ENV__%",
    "debug": true,
    "dbs.options": {
        "default": {
            "driver": "pdo_mysql",
            "host": "localhost",
            "dbname": "database",
            "user": "root",
            "password": "",
            "charset": "utf8"
        }
    },
    "any": {
        "other": "constant"
    }
}

Register

Now register service provider in your Silex application:

use Lokhman\Silex\Provider as ToolsProviders;

$app->register(new ToolsProviders\ConfigServiceProvider(), [
    'config.dir' => __DIR__ . '/../app/config',
]);

config.dir parameter refers to a configuration folder path with JSON files.

Global environment variable

Finally, you can set up your web server to add support of different deployment environments. In order to do this, you have to set a global environmental variable.

nginx + PHP-FPM

fastcgi_param SILEX_ENV prod

Apache

SetEnv SILEX_ENV prod

CLI

$ SILEX_ENV=prod bash -c "php bin/console migrations:status"

If you use Console Application together with ConfigServiceProvider you can pass --env (-e in short) option to all registered commands:

$ php bin/console migrations:status --env=prod

Parameters

ConfigServiceProvider supports the following parameters:

Parameter Description Default
config.dir Folder path with JSON files. null
config.params Array of replacement tokens to use in configuration. []
config.env Environment to use strictly on provider registration (ignores global environment variable). "local"
config.varname Name of global environment variable. "SILEX_ENV"

By default, service provider embeds tokens __DIR__ and __ENV__, as well as all PHP environment variables (e.g. REMOTE_ADDR, SERVER_NAME, etc).

Dynamic tokens

You can define tokens dynamically in the JSON files using property $params:

local.json
{
    "$params": {
        "SECRET": "3ecd45ff71c87269569e682f2f6b2ec4"
    },
    "settings": {
        "prop1": "%SECRET%",
        "prop2": "%secret%",
        "prop3": "%SeCrEt%"
    }
}

N.B.: All tokens are case insensitive.

Extending

You can extend JSON configuration (include one JSON file into another) simply using root property $extends, that points to the file to extend (file extension can be omitted). For example:

local.json
{
    "env": "%__ENV__%",
    "debug": true,
    "locale": "en"
}

prod.json
{
    "$extends": "local",
    "debug": false
}

License

Library is available under the MIT license. The included LICENSE file describes this in detail.


All versions of silex-config with dependencies

PHP Build Version
Package Version
Requires silex/silex Version ~2.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 lokhman/silex-config contains the following files

Loading the files please wait ....