PHPackages                             zhangshize/slim-facades - 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. zhangshize/slim-facades

ActiveLibrary

zhangshize/slim-facades
=======================

Facades for Slim 3 &amp; 4.

1.1.6(6y ago)137.3k↓37.5%21Apache License Version 2.0PHPPHP &gt;=5.5.0

Since Dec 30Pushed 2y ago1 watchersCompare

[ Source](https://github.com/zhshize/slim-facades)[ Packagist](https://packagist.org/packages/zhangshize/slim-facades)[ Docs](https://github.com/zhangshize/slim-facades)[ RSS](/packages/zhangshize-slim-facades/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (1)Versions (6)Used By (1)

Slim Facades
============

[](#slim-facades)

Introduction
------------

[](#introduction)

SlimFacades is a package to provide facades for [Slim PHP framework](https://www.slimframework.com).

Facades is a noun from [Laravel](https://laravel.com)(also a PHP Framework). Facades provide a "static" interface to classes that are available in the application's service container.

Laravel facades serve as "static proxies" to underlying classes in the service container, providing the benefit of a terse, expressive syntax while maintaining more testability and flexibility than traditional static methods, so does Slim-Facades.

Requirement
-----------

[](#requirement)

- PHP &gt;= 5.5.0
- Slim &gt;= 3.0

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

[](#installation)

Using [composer](https://getcomposer.org/):
`composer require zhangshize/slim-facades`

Usage
-----

[](#usage)

After the installation, you can update your code like this:

```
    //... Something not important ...
    use SlimFacades\Facade;
    use SlimFacades\Route;
    use SlimFacades\App;

    $app = new \Slim\App(/*...*/);
    // initialize the Facade class
    Facade::setFacadeApplication($app);

    Route::get('/', function (Request $req, Response $res) {
        $res->getBody()->write("Hello");
        return $res;
    });

    App::run();
```

Default Facades
---------------

[](#default-facades)

The following facades are provided by Slim-Facades:

### App

[](#app)

Use it just like using $app!

```
    App::run();
```

### Container

[](#container)

Use it just like using $container!

```
    Container::hasService('view');
```

### Route

[](#route)

```
    Route::get('/', function (Request $req, Response $res) {
        $res->getBody()->write("Hello");
        return $res;
    });
```

### Request

[](#request)

```
    $method = Request::getMethod();
```

### Response

[](#response)

```
    Response::withStatus(302);
```

### Setting

[](#setting)

There are some special method is the following:

#### get($key = null)

[](#getkey--null)

```
    /**
     * Get the settings value.
     * If $key = null, this function returns settings.
     * @param string|null $key
     * @return mixed
     */
    public static function get($key = null)
    {
        // ...
    }
```

##### Usage

[](#usage-1)

```
    Settings::get()['db'];
    Settings::get('db');
    //The same result.
```

#### set($key, $value)

[](#setkey-value)

```
    /**
     * Set the settings value.
     * When $key is an array, it will be viewed to a list of keys.
     * For Example:
     * $key = ['a','b'];
     * The function will set the value of $container->settions['a']['b'].
     * @param array|string $key
     * @param mixed $value
     */
    public static function set($key, $value)
    {
        // ...
    }
```

##### Usage

[](#usage-2)

```
    $container['settings']['db']['host'] = 'localhost';
    Settings::set(['db', 'host'], 'localhost');
    //The same result.
```

### View and Log

[](#view-and-log)

If you want to use them, you should set 'view' and 'logger' services in the container or change the value which returned by `getFacadeAccessor()`.

Custom Facades
--------------

[](#custom-facades)

The code for creating a custom facades for a service in the container is the following:

```
using SlimFacades\Facade;
class CustomFacade extends Facade
{
    protected static function getFacadeAccessor()
    {
        //Change 'serviceName' to you want.
        return 'serviceName';
    }
}
```

The code for creating a custom facades for an instance is the following:

```
using SlimFacades\Facade;
class CustomFacade extends Facade
{
    public static function self()
    {
        //Change the returned value to you want.
        return self::$app->getContainer()->get('myservice');
    }
}
```

Licence
-------

[](#licence)

[Apache License Version 2.0.](LICENSE)

Copyright \[2016\] \[zhangshize\]

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

```
http://www.apache.org/licenses/LICENSE-2.0

```

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~304 days

Total

5

Last Release

2202d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5f580a2f0ef8040ad545f64df17b86aa54d1bbd0efd4bf542738f0cf633b5ba5?d=identicon)[zhangshize](/maintainers/zhangshize)

---

Top Contributors

[![zhshize](https://avatars.githubusercontent.com/u/23548371?v=4)](https://github.com/zhshize "zhshize (33 commits)")

---

Tags

slimfacades

### Embed Badge

![Health badge](/badges/zhangshize-slim-facades/health.svg)

```
[![Health](https://phpackages.com/badges/zhangshize-slim-facades/health.svg)](https://phpackages.com/packages/zhangshize-slim-facades)
```

###  Alternatives

[slim/twig-view

Slim Framework 4 view helper built on top of the Twig 3 templating component

3708.0M210](/packages/slim-twig-view)[bryanjhv/slim-session

Session middleware and helper for Slim framework 4.

233961.5k16](/packages/bryanjhv-slim-session)[palanik/corsslim

Cross-origin resource sharing (CORS) middleware for PHP Slim.

94375.3k3](/packages/palanik-corsslim)[itsgoingd/slim-facades

"Static" interface for various Slim features

7651.4k5](/packages/itsgoingd-slim-facades)[docler-labs/codeception-slim-module

Codeception Module for Slim framework.

13178.0k1](/packages/docler-labs-codeception-slim-module)[mathmarques/smarty-view

Slim Framework 4 view helper built on top of the Smarty templating component

24134.7k1](/packages/mathmarques-smarty-view)

PHPackages © 2026

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