PHPackages                             faz-b/configuration-silex-provider - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. faz-b/configuration-silex-provider

ActiveLibrary

faz-b/configuration-silex-provider
==================================

A Simple configuration service provider for Silex

1.1.0(9y ago)057MITPHPPHP &gt;=5.3.0

Since Apr 20Pushed 9y ago1 watchersCompare

[ Source](https://github.com/faz-b/configuration-silex-provider)[ Packagist](https://packagist.org/packages/faz-b/configuration-silex-provider)[ RSS](/packages/faz-b-configuration-silex-provider/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (1)Versions (4)Used By (0)

Simple configuration for Silex App
==================================

[](#simple-configuration-for-silex-app)

*Rapid routing, view and global parameters definition through a human readable structured config file.*

Once you choose your preferred parsable data format, register the **ConfigurationServiceProvider**.

```
# src/app.php

# $configuration = json_decode(file_get_contents(__DIR__ . '/Site/Resource/config/config.json'), true);
$configuration = Yaml::parse(file_get_contents(__DIR__ . '/Site/Resources/config/config.yml'));
$app->register(new ConfigurationServiceProvider(), array('site.config' => $configuration));

```

The `settings` key
------------------

[](#the-settings-key)

Allows to define your routes and view variables. The first key, under the `settings` key is your route name. All routes defined here are registered with the `Silex\ControllerCollection`.

```
# src/Site/Resources/config/config.yml

settings:
    homepage:
        route:
            controller:     default.controller:indexAction
            pattern:        /
            # other Silex route parameters...
        view:
            title:          homepage.title
            metas:
                keywords:  "keyword, keyword, keyword"
    contact:
        route:
            pattern:        /contact
            method:         GET|POST
        view:
            template:       page/contact.html
            title:          contact.title

```

When no controller is given (eg: contact route), a default closure will be generated, returning the given template.

The configuration can be accessed in your twig template through the following syntax :

```
{{ app.config.get('homepage.view.title')|trans }}

```

As a convenience, you can use the `current` shortcut to access the settings for the current matched route

```
{{ app.config.current('view.title')|trans }}

{# equivalent #}

{{ app.config.settings('homepage.view.title')|trans }}

```

The same applies inside a controller

```
public function indexAction(Request $request)
{
    $title = $this->container['config']->current('view.title', 'Default title');

    return $this->container['twig']->render('@site/Default/index.html');
}

```

The `global` key
----------------

[](#the-global-key)

It is just a convention for settings your others application parameters.

```
# src/Site/Resources/config/config.yml
global:
    email:                  contact@localhost
    domain:                 localhost
    brand:                  brandname
    analytics_id:           UA-xxxxx
    facebook_url:           https://www.facebook.com/xxx
    linkedin_url:           https://www.linkedin.com/pub/xxx
    view:
        title:              " - default title suffix"
        metas:
            description:    "Silex app"

```

In a twig template:

```
# index.html

{% block title %}{{ app.config.current('view.title') }}{% endblock %}{{ app.config.global('view.title')}}

...

email me

```

*the **settings** and **global** keys are reserved*

A `navigation` section example
------------------------------

[](#a-navigation-section-example)

```
settings:
...

navigation:
    homepage:
        label:              homepage.label
        childs:
            contact:
                label:      contact.label

```

In a twig template:

```
{{ app.config.navigation('current.label') }}

```

### Typical usecase using the bootstrap framework

[](#typical-usecase-using-the-bootstrap-framework)

```
{% import "@site/macro/navigation.html" as macros %}

        {{ app.config.global('brand')|trans }}

        {{ macros.menu(app.config.navigation('homepage.childs')) }}

      {% if app.locales %}

        {% for locale in app.locales %}

          {{locale|upper}}

        {% endfor %}

      {% endif %}

```

Full config.yml example
-----------------------

[](#full-configyml-example)

```
global:
    email:                  contact@localhost
    domain:                 localhost
    brand:                  brand.name
    analytics_id:           UA-xxxxx
    facebook_url:           https://www.facebook.com/xxx
    linkedin_url:           https://www.linkedin.com/pub/xxx
    view:
        title:              view.title
        suffix:             view.title.suffix
        metas:
            description:    view.metas.description
settings:
    homepage:
        route:
            controller: default.controller:indexAction
            pattern:    /
        view:
            title:      home.title
            metas:
                keywords:    ~
                description: ~
    contact:
        route:
            controller: default.controller:contactAction
            pattern:    /contact
        view:
            title:      contact.title
    test:
        route:
            pattern:    /test
            i18n:       false
        view:
            template:   '@site/Default/test.html'

navigation:
    homepage:
        label:          home.label
        childs:
            contact:
                label:  contact.label
            test:
                label:  test.label

```

---

F/\\Z-B 2014

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity60

Established project with proven stability

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~158 days

Total

3

Last Release

3357d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/013b803b7e41815124d2556db99199b4664c62a2f9fdb66f4b9f04f856697fa5?d=identicon)[r1K0](/maintainers/r1K0)

---

Tags

phpconfigurationsilex

### Embed Badge

![Health badge](/badges/faz-b-configuration-silex-provider/health.svg)

```
[![Health](https://phpackages.com/badges/faz-b-configuration-silex-provider/health.svg)](https://phpackages.com/packages/faz-b-configuration-silex-provider)
```

###  Alternatives

[m1/vars

Vars is a simple to use and easily extendable configuration loader with in built loaders for ini, json, PHP, toml, XML and yaml/yml file types. It also comes with in built support for Silex and more frameworks to come soon.

69124.2k1](/packages/m1-vars)[eole/sandstone

Silex RestApi with Websockets.

1115.2k1](/packages/eole-sandstone)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
