PHPackages                             lastzero/symlex-core - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. lastzero/symlex-core

ActiveLibrary[HTTP &amp; Networking](/categories/http)

lastzero/symlex-core
====================

Minimalistic Kernel and Routers based on Symfony Components

v4.4.1(3y ago)119.5k3MITPHPPHP &gt;=7.3CI failing

Since Aug 24Pushed 3y ago2 watchersCompare

[ Source](https://github.com/symlex/symlex-core)[ Packagist](https://packagist.org/packages/lastzero/symlex-core)[ Docs](https://github.com/symlex/symlex-core)[ RSS](/packages/lastzero-symlex-core/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (5)Versions (40)Used By (0)

Minimalistic Kernel and Routers based on Symfony Components
===========================================================

[](#minimalistic-kernel-and-routers-based-on-symfony-components)

[![Latest Stable Version](https://camo.githubusercontent.com/e5d332434fee9537c343e2d9746c0e036e64d1e95883de9e3912bcbbd53d5173/68747470733a2f2f706f7365722e707567782e6f72672f73796d6c65782f73796d6c65782d636f72652f762f737461626c652e737667)](https://packagist.org/packages/symlex/symlex-core)[![License](https://camo.githubusercontent.com/5630f46c7ecfde8a85e6ea55d24b97f9b6db0b715eaebc65e37ef9da0f5cbdd3/68747470733a2f2f706f7365722e707567782e6f72672f73796d6c65782f73796d6c65782d636f72652f6c6963656e73652e737667)](https://packagist.org/packages/symlex/symlex-core)[![Test Coverage](https://camo.githubusercontent.com/e77782f694fe65ea109be36a4afe9fdd7a6dad465b5aeeb595225412982f376c/68747470733a2f2f636f6465636f762e696f2f67682f73796d6c65782f73796d6c65782d636f72652f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/symlex/symlex-core)[![Build Status](https://camo.githubusercontent.com/89ad54ec431a4f86713ee3694f43286fc4e104505a2c33127820e91e3ec1e0cd/68747470733a2f2f7472617669732d63692e6f72672f73796d6c65782f73796d6c65782d636f72652e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/symlex/symlex-core)[![Documentation](https://camo.githubusercontent.com/84e7e669c9ae017b0fad97fbe04fe187e788bc569eabc772c41e9a2ec33e2708/68747470733a2f2f72656164746865646f63732e6f72672f70726f6a656374732f73796d6c65782d646f63732f62616467652f3f76657273696f6e3d6c6174657374267374796c653d666c6174)](https://docs.symlex.org/en/latest/)[![Community Chat](https://camo.githubusercontent.com/bf8ea831b14602e140cc1b36ea5c1979dc72055a61475a804d68ca875bdaa52d/68747470733a2f2f6261646765732e6769747465722e696d2f73796d6c65782f636f6d6d756e6974792e706e67)](https://gitter.im/symlex/community)

*Note: This repository contains the kernel and routers as reusable components. For more information and a complete framework based on symlex-core please see *

As published by [phpbenchmarks.com](http://www.phpbenchmarks.com/en/benchmark/apache-bench/php-7.3/symlex-4.1.html), Symlex adds [significantly less overhead](https://github.com/symlex/symlex/blob/master/README.md#performance) to REST requests than other common PHP frameworks:

[![](https://camo.githubusercontent.com/73262d13efc8557e22e51f5157373d97fddd87ff761e4e8799bdff0b62640b85/68747470733a2f2f73796d6c65782e6f72672f696d616765732f706572666f726d616e63652d6c617267652e737667)](https://camo.githubusercontent.com/73262d13efc8557e22e51f5157373d97fddd87ff761e4e8799bdff0b62640b85/68747470733a2f2f73796d6c65782e6f72672f696d616765732f706572666f726d616e63652d6c617267652e737667)

Our complete framework documentation can be found on [docs.symlex.org](https://docs.symlex.org/en/latest/). [Tuzi Liu](https://github.com/tuzimoe) maintains a [Chinese translation](https://docs.symlex.org/zh/latest/) for us.

Kernel
------

[](#kernel)

The light-weight Symlex kernel can bootstrap almost any application. It is based on our [di-microkernel](https://github.com/symlex/di-microkernel) library. The kernel itself is just a few lines to set environment parameters, initialize the Symfony service container and then start the app by calling `run()`.

YAML files located in `config/` configure the application and all of it's dependencies as a service. The filename matches the application's environment name (e.g. `config/console.yml`). The configuration can additionally be modified for sub environments such as local or production by providing a matching config file like `config/console.local.yml`(see `app.sub_environment` parameter). These files are in the same [well documented](https://symfony.com/doc/current/components/dependency_injection.html)format you might know from Symfony:

```
parameters:
    app.name: 'My App'
    app.version: '1.0'

services:
    doctrine.migrations.migrate:
        class: Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand

    app:
        class: Symfony\Component\Console\Application
        arguments: [%app.name%, %app.version%]
        public: true
        calls:
            - [ add, [ "@doctrine.migrations.migrate" ] ]
```

This provides a uniform approach for bootstrapping Web applications such as `Symlex\Application\Web` or command-line applications like `Symfony\Component\Console\Application` (wrapped in `Symlex\Application\Console`) using the same kernel. The result is much cleaner and leaner than the usual bootstrap and configuration madness you know from many frameworks.

### Disable Caching

[](#disable-caching)

If debug mode is turned off, the service container configuration is cached by the kernel in the directory set as cache path. You have to delete all cache files after updating the configuration. To disable caching completely, add `container.cache: false` to your config parameters:

```
parameters:
    container.cache: false
```

Routers
-------

[](#routers)

There are three router classes included in this library. They configure the Symfony router component to perform the actual routing, so you can expect the same high performance. After routing a request to the appropriate controller action, the router subsequently renders the response to ease controller testing (actions never directly return JSON or HTML):

- `Symlex\Router\Web\RestRouter` handles REST requests (JSON)
- `Symlex\Router\Web\ErrorRouter` renders exceptions as error messages (HTML or JSON)
- `Symlex\Router\Web\TwigRouter` renders regular Web pages via Twig (HTML)
- `Symlex\Router\Web\TwigDefaultRouter` is like TwigRouter but sends all requests to a default controller action (required for client-side routing e.g. with Vue.js)

It's easy to create your own custom routing/rendering based on the existing examples.

The application's HTTP kernel class initializes the routers that were configured in the service container:

```
