Fork me on GitHub

Configuration

For configuration Silex-MVC application there are a few things you need to consider.

First, Silex-MVC consists of two independent applications. It is Web Application and Console Application. These applications are configured differently, although they have a common configuration files.

Second, Web Application can be configured in two ways via Yml files or set configuration in the program code. The choice between the configuration process is carried out in the method _iniConfig in class Bootstrap /app/Bootstrap.php.

The configuration in the program code is faster.


Configuration files

Configuration files are shown below.

|-- app/
    |-- Resources/              # Resources
        |-- Config/             # Configuration files
            |-- Config.php      # `Config` class
            |-- application.yml # Configuration for Web applications
            |-- config.yml      # General configuration is used as 
                                # a web application as well as console application 
            |-- console.yml     # The configuration for the console application
            |-- parameters.yml  # The basic configuration parameters
            |-- security.yml    # Security configuration

If you are using in your configuration yml files expressionimports, then your configuration is recursively combined with config specified in the expression imports.

Config.php

It Config class - service with which you can get the basic configuration parameters via $app['config']['parameters']. With this class can also get the path to the main working directory for example to log files, cache files and other. As well as using this service can be create the necessary directories when you first open the application.

parameters.yml

Here set values of the main parameters of your configuration, which can be used in other your configurations. The parameters can be accessed through $app['config']['parameters'].

The values of the basic parameters:

  • Time zone (timezone)
  • Language localization (locale)
  • The color scheme of the site (scheme)
  • Debugging mode (debug)
  • Environment (environment)
  • Data storage directory for console application (data_dir)
  • Host address for local testing (url_test)
  • UBKI params (ubki_login, ubki_pass, ubki_test_login, ubki_test_pass)
  • Database Options (db.driver, db.path, db.name, db.models.path, db.models.namespace, db.connection.production, db.connection.development, db.connection.test)
  • Email Options (mail.host, mail.port, mail.username, mail.password)
  • PagerFanta Options (pagerfanta.max_per_page, pagerfanta.proximity)

config.yml

General configuration is used as a web application as well as console application. Place the information about your services in common section service_providers.

 service_providers:
    ...
    swiftmailer:
        class: Silex\Provider\SwiftmailerServiceProvider
        parameters:
            swiftmailer.options:
                host: %mail.host%
                port: %mail.port%
                username: %mail.username%
                password: %mail.password%
                encryption: %mail.encryption%
                auth_mode: %mail.auth_mode%
...

console.yml or application.yml

Configurations are used correspondingly for the console or web application.

security.yml

There are set values method of user authentication and authorization. The details can be found here.

env.yml

It is often helpful to have different configuration values based on the environment the application is running in. For example, you may wish to use a different cache driver locally than you do on your production server.

For this task you can create a file env.yml with specific settings and place it in the root of your application. The file env.yml will replace the values of existing file parameters.yml.