diff --git a/README.md b/README.md index d526aba..34dbe60 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,28 @@ Laravel like facades support for Yii 2 application components. Just what you wan [![Code Quality](https://img.shields.io/scrutinizer/g/sergeymakinen/yii2-facades.svg?style=flat-square)](https://scrutinizer-ci.com/g/sergeymakinen/yii2-facades) [![Packagist Version](https://img.shields.io/packagist/v/sergeymakinen/yii2-facades.svg?style=flat-square)](https://packagist.org/packages/sergeymakinen/yii2-facades) [![Total Downloads](https://img.shields.io/packagist/dt/sergeymakinen/yii2-facades.svg?style=flat-square)](https://packagist.org/packages/sergeymakinen/yii2-facades) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE) +## 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-1) + * [get](#get) + * [Response](#response) + * [bare](#bare) + * [html](#html) + * [json](#json) + * [jsonp](#jsonp) + * [raw](#raw) + * [xml](#xml) +* [Extending](#extending) + ## Installation The preferred way to install this extension is through [composer](https://getcomposer.org/download/). @@ -68,7 +90,7 @@ After: $price = Formatter::asCurrency(123456.78, 'USD'); ``` -## Accessing properties +## Access properties Any class public property `$foo` can be got via an accessor: @@ -80,6 +102,121 @@ And set: ```php YourFacadeName::setFoo($value) ``` +## Available facades + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameFacaded component aliasComponent/interface
AssetYii::$app->assetManageryii\web\AssetManager
AuthYii::$app->authyii\rbac\ManagerInterface
CacheYii::$app->cacheyii\caching\Cache
DbYii::$app->dbyii\db\Connection
ErrorYii::$app->errorHandleryii\console\ErrorHandler
yii\web\ErrorHandler
FormatterYii::$app->formatteryii\i18n\Formatter
HttpYii::$app->httpClientyii\httpclient\Client
I18nYii::$app->i18nyii\i18n\I18N
LogYii::$app->logyii\log\Dispatcher
MailerYii::$app->maileryii\swiftmailer\Mailer
RedisYii::$app->redisyii\redis\Connection
RequestYii::$app->requestyii\console\Request
yii\web\Request
ResponseYii::$app->responseyii\console\Response
yii\web\Response
RouterYii::$app->urlManageryii\web\UrlManager
SecurityYii::$app->securityyii\base\Security
SessionYii::$app->sessionyii\web\Session
UrlYii::$app->urlManageryii\web\UrlManager
UserYii::$app->useryii\web\User
ViewYii::$app->viewyii\web\View
## Helpers @@ -87,6 +224,22 @@ Some facades also contain useful helpers to make a development more quick and el ### Cache +#### cache + +Alias: `getOrSet` + +```php +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: + +```php +$users = Cache::cache('users', function () { + return app\models\Users::findAll(); +}, 3600); +``` + #### get ```php @@ -104,20 +257,6 @@ $options = Cache::get('options', function () { }); ``` -#### getOrSet - -```php -public static function getOrSet($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: - -```php -$users = Cache::getOrSet('users', function () { - return app\models\Users::findAll(); -}, 3600); -``` - ### Response #### bare