PHPackages                             ytubes/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. ytubes/facades

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

ytubes/facades
==============

Laravel like facades support for Yii 2 application components

0.0.3(8y ago)04MITPHP

Since Jul 4Pushed 8y agoCompare

[ Source](https://github.com/ytubes/facades)[ Packagist](https://packagist.org/packages/ytubes/facades)[ Docs](https://github.com/sergeymakinen/yii2-facades)[ RSS](/packages/ytubes-facades/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

Facades for Yii 2
=================

[](#facades-for-yii-2)

Laravel like facades support for Yii 2 application components. Just what you want: simple, extensive and with an IDE auto completion support via [PHPDoc](https://www.phpdoc.org) so you won't be disappointed.

[![Code Quality](https://camo.githubusercontent.com/2c8f2178af28e56db2e7c57d0393de1d336c4ec3ac98b0d47549974af1709689/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7365726765796d616b696e656e2f796969322d666163616465732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/sergeymakinen/yii2-facades) [![Build Status](https://camo.githubusercontent.com/370901307cb4172890e1c6862a02b0de367a03fd8bfba0c5a485027267ed284b/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7365726765796d616b696e656e2f796969322d666163616465732e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/sergeymakinen/yii2-facades) [![Code Coverage](https://camo.githubusercontent.com/68f6c0dd7834aab15871322e2de0627b2cc30a43298e915d682fc0161674fc5b/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f7365726765796d616b696e656e2f796969322d666163616465732e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/gh/sergeymakinen/yii2-facades) [![SensioLabsInsight](https://camo.githubusercontent.com/a832cf5d2e41ef15ac5eb5195b086c800ac32349d344b2ef385cb5a01bd2637c/68747470733a2f2f696d672e736869656c64732e696f2f73656e73696f6c6162732f692f33643666386166612d346261662d343064662d393932332d3230353365636535396237632e7376673f7374796c653d666c61742d737175617265)](https://insight.sensiolabs.com/projects/3d6f8afa-4baf-40df-9923-2053ece59b7c)

[![Packagist Version](https://camo.githubusercontent.com/f20906284aaf019388480da3faf22f988a71637e6869dd7bc3ede7ffbf745d12/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7365726765796d616b696e656e2f796969322d666163616465732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sergeymakinen/yii2-facades) [![Total Downloads](https://camo.githubusercontent.com/93f39cb9edfcac2938281fd7c0a50cff77767a81417acecb1aca965de3c51c8b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7365726765796d616b696e656e2f796969322d666163616465732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sergeymakinen/yii2-facades) [![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)

Table of contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Usage](#usage)
    - [Generate random string](#generate-random-string)
    - [Fetch all users (just an example!)](#fetch-all-users-just-an-example)
    - [Format currency](#format-currency)
- [Access properties](#access-properties)
- [Available facades](#available-facades)
- [Helpers](#helpers)
    - [Cache](#cache)
        - [cache](#cache)
        - [get](#get)
    - [Response](#response)
        - [bare](#bare)
        - [html](#html)
        - [json](#json)
        - [jsonp](#jsonp)
        - [raw](#raw)
        - [xml](#xml)
- [Extending](#extending)

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

[](#installation)

The preferred way to install this extension is through [composer](https://getcomposer.org/download/).

Either run

```
composer require "ytubes/facades:>=0.0.1"
```

or add

```
"ytubes/facades": ">=0.0.1"
```

to the require section of your `composer.json` file.

Usage
-----

[](#usage)

Basically you install the extension and start using it like you do with all normal Yii 2 application components but with a shorter simpler syntax, let's take a look (in case you wonder, all default facades, including an abstract base `Facade` reside under a `sergeymakinen\facades` namespace):

### Generate random string

[](#generate-random-string)

Before:

```
$random = Yii::$app->security->generateRandomString(128);
```

After:

```
$random = Security::generateRandomString(128);
```

### Fetch all users (just an example!)

[](#fetch-all-users-just-an-example)

Before:

```
$users = Yii::$app->db->createCommand('SELECT * FROM users;')->queryAll();
```

After:

```
$users = Db::createCommand('SELECT * FROM users;')->queryAll();
```

### Format currency

[](#format-currency)

Before:

```
$price = Yii::$app->formatter->asCurrency(123456.78, 'USD');
```

After:

```
$price = Formatter::asCurrency(123456.78, 'USD');
```

Access properties
-----------------

[](#access-properties)

Any class public property `$foo` can be got via an accessor:

```
$value = YourFacadeName::getFoo()
```

And set:

```
YourFacadeName::setFoo($value)
```

Available facades
-----------------

[](#available-facades)

NameFacaded component aliasComponent/interface`Asset``Yii::$app->assetManager``yii\web\AssetManager``Auth``Yii::$app->auth``yii\rbac\ManagerInterface``Cache``Yii::$app->cache``yii\caching\Cache``Db``Yii::$app->db``yii\db\Connection``Error``Yii::$app->errorHandler``yii\console\ErrorHandler``yii\web\ErrorHandler``Formatter``Yii::$app->formatter``yii\i18n\Formatter``Http``Yii::$app->httpClient``yii\httpclient\Client``I18n``Yii::$app->i18n``yii\i18n\I18N``Log``Yii::$app->log``yii\log\Dispatcher``Mailer``Yii::$app->mailer``yii\swiftmailer\Mailer``Redis``Yii::$app->redis``yii\redis\Connection``Request``Yii::$app->request``yii\console\Request``yii\web\Request``Response``Yii::$app->response``yii\console\Response``yii\web\Response``Router``Yii::$app->urlManager``yii\web\UrlManager``Security``Yii::$app->security``yii\base\Security``Session``Yii::$app->session``yii\web\Session``Url``Yii::$app->urlManager``yii\web\UrlManager``User``Yii::$app->user``yii\web\User``View``Yii::$app->view``yii\web\View`Helpers
-------

[](#helpers)

Some facades also contain useful helpers to make a development more quick and elegant.

### Cache

[](#cache)

#### cache

[](#cache-1)

```
public static function cache($key, $default, $duration = 0, $dependency = null)
```

Retrieves a value using the provided key or the specified default value if the value is not cached. If the value is not in the cache, it will be cached. The default value can also be a closure:

```
$users = Cache::cache('users', function () {
    return app\models\Users::findAll();
}, 3600);
```

#### get

[](#get)

```
public static function get($key, $default = false)
```

Retrieves a value using the provided key and returns it or the specified default value which can also be a closure:

```
$options = Cache::get('options', function () {
    return [
        'option1' => false,
        'option2' => true
    ];
});
```

### Response

[](#response)

#### bare

[](#bare)

```
public static function bare($statusCode = 204, array $headers = [])
```

Returns an empty response with optional headers:

```
public function actionCreate()
{
    // ...
    return Response::bare(201);
}
```

#### html

[](#html)

```
public static function html($data, array $headers = [])
```

Returns a HTML response with optional headers:

```
public function actionIndex()
{
    // ...
    return Response::html($this->render('index'), [
        'Cache-Control' => 'no-cache'
    ]);
}
```

#### json

[](#json)

```
public static function json($data, array $headers = [])
```

Returns a JSON response with optional headers:

```
public function actionList()
{
    // ...
    return Response::json(Db::createCommand('SELECT * FROM users')->all());
}
```

#### jsonp

[](#jsonp)

```
public static function jsonp($data, $callback = 'callback', array $headers = [])
```

Returns a JSONP response with optional headers:

```
public function actionApi($callback)
{
    // ...
    return Response::jsonp([
        'success' => true,
        'response' => $data
    ], $callback);
}
```

#### raw

[](#raw)

```
public static function raw($data, array $headers = [])
```

Returns a response with data "as is" with optional headers:

```
public function actionCreate()
{
    // ...
    return Response::raw($binary, [
        'Content-Type' => 'application/octet-stream'
    ]);
}
```

#### xml

[](#xml)

```
public static function xml($data, array $headers = [])
```

Returns a XML response with optional headers:

```
public function actionCreate()
{
    // ...
    return Response::xml([
        'success' => true,
        'response' => $data
    ]);
}
```

Extending
---------

[](#extending)

If you want a new facade, it's fast and easy, imagine you want to bring a `YourFacadeName` facade:

```
class YourFacadeName extends Facade
{
    /**
     * @inheritdoc
     */
    public static function getFacadeComponentId()
    {
        return 'yourFacadeComponentName'; // Yii::$app->yourFacadeComponentName
    }
}
```

Then whenever you call

```
YourFacadeName::hello('world');
```

it will be executed as

```
Yii::$app->get('yourFacadeComponentName')->hello('world');
```

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 52.6% 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 ~0 days

Total

3

Last Release

3282d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/309d3bbc61cda9dee096a722d5e252501bbed565f7bbed1605fb8d7355df4c84?d=identicon)[ytubes](/maintainers/ytubes)

---

Top Contributors

[![sergeymakinen](https://avatars.githubusercontent.com/u/983964?v=4)](https://github.com/sergeymakinen "sergeymakinen (51 commits)")[![ytubes](https://avatars.githubusercontent.com/u/29330950?v=4)](https://github.com/ytubes "ytubes (46 commits)")

---

Tags

laravelfacadeyii2yiifacadesyii2-facades

### Embed Badge

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

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

PHPackages © 2026

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