PHPackages                             xepozz/yii-short - 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. xepozz/yii-short

Abandoned → [xepozz/shortcut](/?search=xepozz%2Fshortcut)Library[Framework](/categories/framework)

xepozz/yii-short
================

A set of shortcuts for the Yii framework

21[2 issues](https://github.com/xepozz/shortcut/issues)PHP

Since Jul 29Pushed 2y ago1 watchersCompare

[ Source](https://github.com/xepozz/shortcut)[ Packagist](https://packagist.org/packages/xepozz/yii-short)[ RSS](/packages/xepozz-yii-short/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Shortcut
========

[](#shortcut)

Sets of helper functions for rapid development of Yii 3 applications.

[![Latest Stable Version](https://camo.githubusercontent.com/480f399fb6404ddef5b6f59b957325b70f506f8cd95f5d8fb2324204096b73c8/68747470733a2f2f706f7365722e707567782e6f72672f7865706f7a7a2f73686f72746375742f762f737461626c652e737667)](https://packagist.org/packages/xepozz/shortcut)[![Total Downloads](https://camo.githubusercontent.com/a53116a80e948ad25d1662c9e7a36d61ef210c40aa11a20b754b6914005deda8/68747470733a2f2f706f7365722e707567782e6f72672f7865706f7a7a2f73686f72746375742f646f776e6c6f6164732e737667)](https://packagist.org/packages/xepozz/shortcut)[![phpunit](https://github.com/xepozz/shortcut/workflows/PHPUnit/badge.svg)](https://github.com/xepozz/shortcut/actions)[![codecov](https://camo.githubusercontent.com/9ee84c478bd809aca8ad85b102f260a05743abb7a725ee48eed5f06ded086103/68747470733a2f2f636f6465636f762e696f2f67682f7865706f7a7a2f73686f72746375742f6272616e63682f6d61737465722f67726170682f62616467652e7376673f746f6b656e3d55524558414f5548544a)](https://codecov.io/gh/xepozz/shortcut)[![type-coverage](https://camo.githubusercontent.com/08a95f88c919be2fd4bd65685fb4a920b5e5afaee9044f0a62bfd68e04ba3c40/68747470733a2f2f73686570686572642e6465762f6769746875622f7865706f7a7a2f73686f72746375742f636f7665726167652e737667)](https://shepherd.dev/github/xepozz/shortcut)

About
-----

[](#about)

The library provides a set of helper functions for rapid development of Yii 3 applications.

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

[](#installation)

```
composer req xepozz/shortcut
```

Shortcuts
---------

[](#shortcuts)

### Table of contents

[](#table-of-contents)

- [container](#item-container)
    - Accessing the PSR-11 container
- [route](#item-route)
    - Generating a route URL
- [view](#item-view)
    - Rendering a view file to a response object
- [response](#item-response)
    - Creating a response object
- [redirect](#item-redirect)
    - Creating a redirect response object
- [alias](#item-alias)
    - Getting an alias
- [aliases](#item-aliases)
    - Getting multiple aliases at once
- [translate](#item-translate)
    - Translating a message
- [validate](#item-validate)
    - Validating a data
- [log](#item-log)
    - Logging a message with PSR-3 logger
- [cache](#item-cache)
    - Accessing the PSR-6 cache

### Functions

[](#functions)

#### `container(string $id, bool $optional = false): mixed`

[](#containerstring-id-bool-optional--false-mixed)

- `$id` is a container id
- `$optional` is a flag to return `null` if the `$id` is not found in the container

```
container(\App\MyService::class); // => \App\MyService instance
container('not-exist'); // => throws \Psr\Container\NotFoundExceptionInterface
container('not-exist', true); // => null
```

#### `route(string $name, array $params = [], array $query = []): string`

[](#routestring-name-array-params---array-query---string)

- `$name` is a route name
- `$params` is a route params
- `$query` is a query params

```
route('site/index'); // => '/index'
route('user/view', ['id' => 1]); // => '/user/1'
route('site/index', [], ['page' => 2]); // => '/index?page=2'
```

#### `view(string $view, array $params = [], null|string|object $controller = null): \Yiisoft\DataResponse\DataResponse`

[](#viewstring-view-array-params---nullstringobject-controller--null-yiisoftdataresponsedataresponse)

- `$view` is a view name
- `$params` is a view params
- `$controller` is a controller instance or a path to views directory. Used to bind views to the specific directory.

```
view('site/index'); // => A response object with content of file '/views/site/index.php'
view('site/index', ['page' => 2]); // => A response object with content of file '/views/site/index.php' and params ['page' => 2]
view('index', ['page' => 2], new MyController()); // => A response object with content of file '/views/my/index.php' and params ['page' => 2]
view('index', ['user' => $user], 'module/user'); // => A response object with content of file '/views/module/user/index.php' and params ['user' => $user]

class SiteController
{
    public function actionIndex()
    {
        return view('index', [], $this);  // => A response object with content of file '/views/site/index.php'
    }
}
```

#### `response(int|null|string|array|StreamInterface $body = null, int $code = 200, string $status = 'OK', array $headers = []): \Psr\Http\Message\ResponseInterface`

[](#responseintnullstringarraystreaminterface-body--null-int-code--200-string-status--ok-array-headers---psrhttpmessageresponseinterface)

- `$body` is a response body
- `$code` is a response code
- `$status` is a response status
- `$headers` is a response headers

```
response('Hello world'); // => A response object with body 'Hello world'
response('Hello world', 201); // => A response object with body 'Hello world' and code 201
response('Hello world', 201, 'Created'); // => A response object with body 'Hello world', code 201 and status 'Created'
response('Hello world', 201, 'Created', ['X-My-Header' => 'My value']); // => A response object with body 'Hello world', code 201, status 'Created' and header 'X-My-Header' with value 'My value'

response(['message' => 'Hello world']); // => A response object with body '{"message":"Hello world"}' and header 'Content-Type' with value 'application/json'
```

#### `redirect(string $name, array $parameters = [], array $query = [], int $code = Status::TEMPORARY_REDIRECT, bool $absolute = false): \Psr\Http\Message\ResponseInterface`

[](#redirectstring-name-array-parameters---array-query---int-code--statustemporary_redirect-bool-absolute--false-psrhttpmessageresponseinterface)

- `$name` is a route name or an absolute url if `$absolute` is `true`
- `$parameters` is a route parameters. Used only if `$absolute` is `false`
- `$query` is a query parameters
- `$code` is a response code
- `$absolute` is a flag to generate absolute url, default is `false`

```
// Route name 'site/index' is bound to '/index'
redirect('site/index'); // => A response object with code 307 and header 'Location' with value '/index'
redirect('site/index', ['page' => 2]); // => A response object with code 307 and header 'Location' with value '/index/2'
redirect('site/index', [], ['page' => 2]); // => A response object with code 307 and header 'Location' with value '/index?page=2'
redirect('site/index', [], ['page' => 2], Status::PERMANENT_REDIRECT); // => A response object with code 308 and header 'Location' with value '/index?page=2'

// Generating absolute url
redirect('/path/to/redirect', [], ['page' => 2], Status::PERMANENT_REDIRECT, true); // => A response object with code 308 and header 'Location' with value 'http://localhost/path/to/redirect?page=2'
```

#### `alias(string $path): string`

[](#aliasstring-path-string)

- `$path` is an alias name

```
alias('@runtime'); // => '/path/to/runtime'
```

#### `aliases(string ...$paths): array`

[](#aliasesstring-paths-array)

- `$paths` is alias names

```
aliases('@runtime', '@webroot'); // => ['/path/to/runtime', '/path/to/webroot']
```

#### `translate(string $message, array $params = [], string $category = 'app', string $language = null): string`

[](#translatestring-message-array-params---string-category--app-string-language--null-string)

- `$message` is a translation message
- `$params` is a translation params
- `$category` is a translation category
- `$language` is a translation language

```
translate('main.hello'); // => 'Hello world'
translate('error.message', ['message' => 'Something went wrong']); // => 'Error: "Something went wrong".'
translate('error.message', ['message' => 'Something went wrong'], 'modules'); // => 'Error from a module: "Something went wrong".'
translate('error.message', ['message' => 'Something went wrong'], 'modules', 'ru'); // => 'Ошибка из модуля: "Something went wrong".'
```

#### `validate(mixed $data, callable|iterable|object|string|null $rules = null, ?ValidationContext $context = null): Result`

[](#validatemixed-data-callableiterableobjectstringnull-rules--null-validationcontext-context--null-result)

- `$data` is a data to validate
- `$rules` is a validation rules
- `$context` is a validation context

```
validate(
    ['name' => 'John'],
    ['name' => [new Required()]],
);
```

See more about validator rules in [yiisoft/validator](https://github.com/yiisoft/validator)

#### `log_message(string $level, string|stringable $message, array $context = []): void`

[](#log_messagestring-level-stringstringable-message-array-context---void)

- `$level` is a log level. Available levels: `emergency`, `alert`, `critical`, `error`, `warning`, `notice`, `info`, `debug`.
    - You can use `\Psr\Log\LogLevel` constants:
        - `\Psr\Log\LogLevel::EMERGENCY`
        - `\Psr\Log\LogLevel::ALERT`
        - `\Psr\Log\LogLevel::CRITICAL`
        - `\Psr\Log\LogLevel::ERROR`
        - `\Psr\Log\LogLevel::WARNING`
        - `\Psr\Log\LogLevel::NOTICE`
        - `\Psr\Log\LogLevel::INFO`
        - `\Psr\Log\LogLevel::DEBUG`.
- `$message` is a log message
- `$context` is a log context

Also, you can use already level-specific functions:

- `log_emergency(string|Stringable $message, array $context = []): void`
- `log_alert(string|Stringable $message, array $context = []): void`
- `log_critical(string|Stringable $message, array $context = []): void`
- `log_error(string|Stringable $message, array $context = []): void`
- `log_warning(string|Stringable $message, array $context = []): void`
- `log_notice(string|Stringable $message, array $context = []): void`
- `log_info(string|Stringable $message, array $context = []): void`
- `log_debug(string|Stringable $message, array $context = []): void`

```
log_message('info', 'Some info message');
log_message('error', 'Could not authenticate user with ID {user_id}', ['user_id' => $userId]);

log_info('Info message');
log_error('Error message');
log_warning('Warning message');
log_notice('Notice message');
log_debug('Debug message');
log_critical('Critical message');
log_alert('Alert message');
log_emergency('Emergency message');
```

#### `cache(string|int|Stringable|array $key, mixed $value = null, int|DateInterval|null $ttl = null): mixed`

[](#cachestringintstringablearray-key-mixed-value--null-intdateintervalnull-ttl--null-mixed)

- `$key` is a cache key
- `$value` is a cache value
- `$ttl` is a cache TTL

```
cache('key', 'value'); // returns "value" and sets cache with key "key" if it does not exist

cache('key', 'value', 3600); // sets cache with key "key" and value "value" for 1 hour
cache('key', 'value', new DateInterval('PT1H')); // also TTL can be an instance of DateInterval

cache('key', fn () => 'value'); // $value can be a closure. It will be executed only if cache with key "key" does not exist

cache(new StringableClass('key'), fn () => 'value'); // $key can be an instance of Stringable
cache(12345, fn () => 'value'); // $key can be an integer
cache(['key' => 'value', '!@#$%^&*()_+`' => '_)(*&^%$#@!~`'], fn () => 'value'); // $key can be an array. It will be serialized to a JSON and the following characters will be replaced to "_": {}()/\@:
```

Looking for more modules?
-------------------------

[](#looking-for-more-modules)

- [Unique ID](https://github.com/xepozz/unique-id) - Allows you to track the unique user in the application.
- [Request ID](https://github.com/xepozz/request-id) - A simple library to generate both unique request and response IDs for tracing purposes.
- [AB](https://github.com/xepozz/ab) - A simple library to enable A/B testing based on a set of rules.
- [Feature Flag](https://github.com/xepozz/feature-flag) - A simple library to enable/disable features based on a set of rules.

###  Health Score

9

—

LowBetter than 0% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity21

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/c66e7a3533aa307583d595d0f42c70047d45a59768f474e75c190af10534da26?d=identicon)[xepozz](/maintainers/xepozz)

---

Top Contributors

[![xepozz](https://avatars.githubusercontent.com/u/6815714?v=4)](https://github.com/xepozz "xepozz (15 commits)")

---

Tags

rapidrapid-developmentshortcutshortcutsyiiyii3

### Embed Badge

![Health badge](/badges/xepozz-yii-short/health.svg)

```
[![Health](https://phpackages.com/badges/xepozz-yii-short/health.svg)](https://phpackages.com/packages/xepozz-yii-short)
```

###  Alternatives

[laravel/telescope

An elegant debug assistant for the Laravel framework.

5.2k67.8M192](/packages/laravel-telescope)[spiral/roadrunner

RoadRunner: High-performance PHP application server and process manager written in Go and powered with plugins

8.4k12.2M84](/packages/spiral-roadrunner)[nolimits4web/swiper

Most modern mobile touch slider and framework with hardware accelerated transitions

41.8k177.2k1](/packages/nolimits4web-swiper)[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k36.7M259](/packages/laravel-dusk)[laravel/prompts

Add beautiful and user-friendly forms to your command-line applications.

708181.8M596](/packages/laravel-prompts)[cakephp/chronos

A simple API extension for DateTime.

1.4k47.7M121](/packages/cakephp-chronos)

PHPackages © 2026

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