PHPackages                             oasis/slimapp - 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. oasis/slimapp

ActiveLibrary[Framework](/categories/framework)

oasis/slimapp
=============

slim app framework

v3.2.1(1mo ago)212.4k[4 PRs](https://github.com/oasmobile/php-slimapp/pulls)MITHTMLPHP &gt;=8.5CI passing

Since Jan 9Pushed 3w ago3 watchersCompare

[ Source](https://github.com/oasmobile/php-slimapp)[ Packagist](https://packagist.org/packages/oasis/slimapp)[ RSS](/packages/oasis-slimapp/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (28)Versions (108)Used By (0)

SlimApp
=======

[](#slimapp)

The Slim Application Framework (SlimApp) is an all-in-one framework aiming to make development of PHP project, either web or console, faster and easier.

- [Installation &amp; Setup](#installation-setup)
- [Directory structure](#directory-structure)
- [Configuration](#configuration)
- [Bootstrap](#bootstrap)
- [Refer to Config Value](#refer-to-config-value)
    - [get value by *config key*:](#get-value-by-config-key)
    - [get value by *parameter key*:](#get-value-by-parameter-key)
- [Service Container](#service-container)
- [Service Description](#service-description)
    - [The Construction Phase](#the-construction-phase)
    - [The Setting Phase](#the-setting-phase)
    - [The decoration phase:](#the-decoration-phase)
- [Define the "@app" service](#define-the-app-service)
- [Logging](#logging)
- [HTTP Kernel](#http-kernel)
- [Command Line Interface](#command-line-interface)
    - [Writing Your Own Command](#writing-your-own-command)
    - [Using Input Argument](#using-input-argument)
    - [Using Input Option](#using-input-option)
- [The Daemon Sentinel](#the-daemon-sentinel)

### Installation &amp; Setup

[](#installation--setup)

**Requirements**: PHP &gt;= 8.5

**Key Dependencies**: Symfony ^8.0, oasis/http ^3.2 (MicroKernel), oasis/logging ^3.0, PHPUnit ^13 (dev), PHPStan ^2.1 level 8 (dev)

The framework includes a list of useful PHP components. This makes it easy when setting up a new project: you would only need to use composer to require the project itself, and then run the project setup command.

Run the following command under a new project root directory to install the project:

```
composer require oasis/slimapp
```

After installation, you may initialize your project by running:

```
./vendor/bin/slimapp slimapp:project:init
```

Follow on screen prompts to provide necessary information, and your project directory structure will be automatically created.

Below is a list of explanations about information asked during project initialization:

NameExplanation*vendor*owner of this project, all lowercase alphabets/numbers, connected by hyphen '-'*project*name of the project, all lowercase alphabets/numbers, connected by hyphen '-'*root namespace*root namespace for all project specific classes*source directory*as the name implies, source code directory, except unit testing source code and configuration files*database support*Doctrine ORM support integration*logging directory*directory to store logs (slimapp supports auto-configured file logging)*data directory*directory where you store project data to local filesystem*cache directory*directory to store cache files for configuration, container, routing and templates*template directory*base directory to search for Twig template filesIn the rest part of this document, we assume the project is called *test-project* and the vendor is *minhao*. All other settings will retain their default values.

### Directory structure

[](#directory-structure)

An automatically initialized project will have a directory structure like below:

```
+ PROJECT_DIR/
    + assets/                            # static assets directory
    + bin/                               # executable directory
        - test-project.php               # auto-generated project CLI entry point (executable)
    + cache/                             # default cache directory
    + config/                            # config file direcotry
        - cli-config.php                 # auto-generated Doctrine CLI config file
        - config.yml                     # auto-generated configuration YAML file
        - routes.yml                     # auto-generated routing YAML file
        - services.yml                   # auto-generated service container (to be parsed by symfony/di)
    + src/                               # default source code (class files) directory
        + Controllers/                   # namespace for controller classes
            - DemoController.php         # as the name tells, a demo controller
        + Database/                      # namespace for db classes
            - TestProjectDatabase.php    # class which provides access to EntityManager and DBAL connection
        - TestProject.php                # base class for the project, extending SlimApp class
        - TestProjectConfiguration.php   # configuration definition class for config/config.yml
    + templates/                         # default Twig template base directory
    + vendor/                            # composer components directory
    + web/                               # web entry directory
        - front.php                      # entry file for HTTP Kernel
    - bootstrap.php                      # bootstrap file
    - composer.json                      # composer config file
    - composer.lock                      # composer lock file

```

### Configuration

[](#configuration)

The fundamental configuration file for SlimApp is `config.yml` and it is located under the `config` directory. This is a YAML file which can be interpreted as an array in PHP. Below is the default content of an auto-generated config file:

```
# config.yml

is_debug: true                          # is application in debug mode
dir:                                    # directory settings
    log: /data/logs/test-project        # logging dir
    data: /data/test-project            # data dir
    cache: /project-root/cache          # cache dir
    template: /project-root/templates   # template dir
db:                                     # database settings
    host: localhost                     # db host
    port: 3306                          # db port
    user: test_project                  # db user
    password: test-project              # db user password
    dbname: test_project                # db name
memcached:                              # cache settings
    host: localhost                     # memcached host
    port: 11211                         # memcached port
```

The `config.yml` file is strictly parsed, which means that all values defined in this file should meet a configuration definition. SlimApp utilizes [symfony/config](http://symfony.com/doc/master//components/config/index.html) to support configuration definition and parsing of the configuration file. There is an auto-generated config definition class under `src/` directory.

### Bootstrap

[](#bootstrap)

To begin with using a SlimApp enabled app, let's first have a look at the `bootstrap.php` file, under **PROJECT\_DIR**:

```
