PHPackages                             nyholm/symfony-runtime - 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. nyholm/symfony-runtime

ActiveComposer-plugin

nyholm/symfony-runtime
======================

Enables decoupling PHP apps from global state

69PHPCI failing

Since Jul 22Pushed 5y ago2 watchersCompare

[ Source](https://github.com/Nyholm/symfony-runtime)[ Packagist](https://packagist.org/packages/nyholm/symfony-runtime)[ RSS](/packages/nyholm-symfony-runtime/feed)WikiDiscussions master Synced 5d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Runtime Component
=================

[](#runtime-component)

> This repository is a mirror of [symfony/symfony#36652](https://github.com/symfony/symfony/pull/36652)

Symfony Runtime enables decoupling apps from global state.

Getting Started
---------------

[](#getting-started)

```
$ composer require nyholm/symfony-runtime

```

RuntimeInterface
----------------

[](#runtimeinterface)

The core of this component is the `RuntimeInterface` which describes a high-order runtime logic.

It is designed to be totally generic and able to run any application outside of the global state in 6 steps:

1. your front-controller returns a closure that wraps your app;
2. the arguments of this closure are resolved by `RuntimeInterface::resolve()`which returns a `ResolvedAppInterface`. This is an invokable with zero arguments that returns whatever object of yours represents your app (e.g a Symfony kernel or response, a console application or command);
3. this invokable is called and returns this object that represents your app;
4. your app object is passed to `RuntimeInterface::start()`, which returns a `StartedAppInterface`: an invokable that knows how to "run" your app;
5. that invokable is called and returns the exit status code as int;
6. the PHP engine is exited with this status code.

This process is extremely flexible as it allows implementations of `RuntimeInterface` to hook into any critical steps.

Autoloading
-----------

[](#autoloading)

This package registers itself as a Composer plugin to generate a `vendor/autoload_runtime.php` file. You need to require it instead of the usual `vendor/autoload.php` in front-controllers that leverage this component and return a closure.

Before requiring the `vendor/autoload_runtime.php` file, you can set the `$_SERVER['APP_RUNTIME']` variable to a class that implements `RuntimeInterface`and that should be used to run the app.

A `SymfonyRuntime` is used by default. It knows the conventions to run Symfony and native PHP apps.

Examples
--------

[](#examples)

This `public/index.php` is a "Hello World" that handles a "name" query parameter:

```
