PHPackages                             mksec/silex-base - 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. [Framework](/categories/framework)
4. /
5. mksec/silex-base

AbandonedArchivedLibrary[Framework](/categories/framework)

mksec/silex-base
================

Base classes for creating Silex applications

v1.4.1(8y ago)022MITPHPPHP ~7.0

Since Oct 30Pushed 8y ago1 watchersCompare

[ Source](https://github.com/mksec/silex-base)[ Packagist](https://packagist.org/packages/mksec/silex-base)[ Docs](https://github.com/mksec/silex-base)[ RSS](/packages/mksec-silex-base/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (8)Versions (9)Used By (0)

Silex Base-Application
======================

[](#silex-base-application)

[![](https://camo.githubusercontent.com/08cceb73a3f11476c7ca138a548c7f3837e9205f536b84dbfd07c70c28e76e59/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6d6b7365632f73696c65782d626173652f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/mksec/silex-base)[![](https://camo.githubusercontent.com/995f854c6c8cf09bd5acdca0d6cd9d177e4f19b6734f04b3cc7672a99d5aafa5/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f6d6b7365632f73696c65782d626173652e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/github/mksec/silex-base?branch=master)[![](https://camo.githubusercontent.com/8a9929992af4822e9759e6ba28322deac7f70ee30eae3c1b9bf04d95f0186db7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d7261772f6d6b7365632f73696c65782d626173652e7376673f7374796c653d666c61742d737175617265)](https://github.com/mksec/silex-base/issues)[![](https://camo.githubusercontent.com/5eecf396a62aa09bbd78445f729e9e5377a75a1e3cade2c8164d61c0a4cee90c/687474703a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e7376673f7374796c653d666c61742d737175617265)](LICENSE)

Basic [Silex](http://silex.sensiolabs.org/) application, configured to use common providers.

About
-----

[](#about)

Most of the applications developed by mksec use the same common infrastructure with Silex: There's a class inherited from the Silex Application class, which configures the error- and exception handlers. Although the providers depend on the individual applications, some of them are common for all of them.

This repository provides some classes providing the basic infrastructure, that may be used as base classes for the applications to build, making them more simple, as common code doesn't need to be repeated.

Installation
------------

[](#installation)

Simply add `mksec/silex-base` as a dependency for your project with composer:

```
composer require mksec/silex-base

```

Usage
-----

[](#usage)

Using the basic application classes is pretty easy: Just use one of the classes below instead of `\Silex\Application` and you are done. For specialized applications you may want to implement a class inheriting from one of the base classes.

#### Classes

[](#classes)

- `BaseApplication`

    The `BaseApplication` class is a simple Silex Application with the Error- and ExceptionHandler registered. It may be used for simple applications without an UI (e.g. APIs).

    **Notice:** The exception handler of Silex will catch all exceptions while handling a request. In addition, the `ErrorHandler` will convert any errors and warnings (e.g. reading from a non-existing file) to exceptions, that will be handled by the same exception handler of Silex. However, Silex doesn't catch fatal exceptions (e.g. `ClassNotFoundException`) or exceptions thrown outside a running controller. You can access the Error- and ExceptionHandler with the `core.error_handler` and `core.exception_handler` keys, e.g. to set a custom exception handler returning the error 500 page.

    You can use the `catchAllExceptions()` method to tell the `ExceptionHandler`to route exception events to the Silex event handlers. Please read the docs before using this method!
- `BaseUiApplication`

    The `BaseUiApplication` extends the `BaseApplication` with the Twig and Asset serivce-providers registered. It also uses the `CacheTrait` to use an application-wide cache path, which may be set in the `app.cache` path.

    To use this class, you'll need to add additional dependencies:

    ```
    composer require symfony/asset symfony/twig-bridge twig/twig

    ```

    The [Web Profiler](https://github.com/silexphp/Silex-WebProfiler) may be activated with the `enableProfiler()` method **after** the other providers have been registered. You'll also need to add additional development dependencies:

    ```
    composer require --dev 'silex/web-profiler:^2.0'

    ```

    *Additional dependencies may be required depending on other providers you're using. See the [README](https://github.com/silexphp/Silex-WebProfiler) for the Silex Web Profiler for further information.*

There could be a lot more of sub-classes for any kind of Applications. However, this might be inefficient, as there're too many combinations of services for higher classes:

- There're situtions to use the `MonologServiceProvider` in any kind of application, so there's no sense to add extra classes just do get monolog in all of them. It is easier to just register the `MonologServiceProvider` if needed.
- The same goes for the security components (`SecurityServiceProvider`, `RememberMeServiceProvider`, `SessionServiceProvider`): Imagine an application with stateless authentication - there's no sense to use the latter two here.
- Interactive applications might use the `CsrfServiceProvider` and `FormServiceProvider`. However, their dependencies highly depend on the final application, i.e. if the default form templates will be used, the `TranslationServiceProvider` is required, but for custom templates it might be superfluous.

#### Providers

[](#providers)

- `ThemeServiceProvider`

    The `ThemeServiceProvider` may be used to dynamically determine the paths for Twig views and assets. Although it is meant to be used with the `BaseUiApplication`, it is compatible with a plain Silex Application.

    A theme *may* have a file named `assets.php` in its root to return an array of named packages used (e.g. Bootstrap, jQuery, ...) in the template. One may change this list easily by extending the `assets.named_packages` key of the `$app` e.g. to switch the used CDN:

    ```
