{"id":14966467,"url":"https://github.com/xepozz/shortcut","last_synced_at":"2026-01-21T13:33:23.373Z","repository":{"id":183278618,"uuid":"669875326","full_name":"xepozz/shortcut","owner":"xepozz","description":"Sets of helper functions for rapid development of Yii 3 applications.","archived":false,"fork":false,"pushed_at":"2023-07-29T13:08:03.000Z","size":49,"stargazers_count":2,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-14T05:44:43.250Z","etag":null,"topics":["rapid","rapid-development","shortcut","shortcuts","yii","yii3"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xepozz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-23T17:59:52.000Z","updated_at":"2025-01-23T12:22:04.000Z","dependencies_parsed_at":"2024-09-14T02:54:23.123Z","dependency_job_id":null,"html_url":"https://github.com/xepozz/shortcut","commit_stats":{"total_commits":15,"total_committers":1,"mean_commits":15.0,"dds":0.0,"last_synced_commit":"5d575bace87e6ce345a23326c3ae1b8fc656fb37"},"previous_names":["xepozz/yii-short","xepozz/shortcut"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/xepozz/shortcut","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xepozz%2Fshortcut","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xepozz%2Fshortcut/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xepozz%2Fshortcut/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xepozz%2Fshortcut/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xepozz","download_url":"https://codeload.github.com/xepozz/shortcut/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xepozz%2Fshortcut/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28633763,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-21T04:47:28.174Z","status":"ssl_error","status_checked_at":"2026-01-21T04:47:22.943Z","response_time":86,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["rapid","rapid-development","shortcut","shortcuts","yii","yii3"],"created_at":"2024-09-24T13:36:25.621Z","updated_at":"2026-01-21T13:33:23.358Z","avatar_url":"https://github.com/xepozz.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Shortcut\n\nSets of helper functions for rapid development of Yii 3 applications.\n\n[![Latest Stable Version](https://poser.pugx.org/xepozz/shortcut/v/stable.svg)](https://packagist.org/packages/xepozz/shortcut)\n[![Total Downloads](https://poser.pugx.org/xepozz/shortcut/downloads.svg)](https://packagist.org/packages/xepozz/shortcut)\n[![phpunit](https://github.com/xepozz/shortcut/workflows/PHPUnit/badge.svg)](https://github.com/xepozz/shortcut/actions)\n[![codecov](https://codecov.io/gh/xepozz/shortcut/branch/master/graph/badge.svg?token=UREXAOUHTJ)](https://codecov.io/gh/xepozz/shortcut)\n[![type-coverage](https://shepherd.dev/github/xepozz/shortcut/coverage.svg)](https://shepherd.dev/github/xepozz/shortcut)\n\n## About\n\nThe library provides a set of helper functions for rapid development of Yii 3 applications.\n\n\n## Installation\n\n```bash\ncomposer req xepozz/shortcut\n```\n\n## Shortcuts\n\n### Table of contents\n\n- [container](#item-container)\n  - Accessing the PSR-11 container \n- [route](#item-route)\n  - Generating a route URL \n- [view](#item-view)\n  - Rendering a view file to a response object\n- [response](#item-response)\n  - Creating a response object\n- [redirect](#item-redirect)\n  - Creating a redirect response object \n- [alias](#item-alias)\n  - Getting an alias \n- [aliases](#item-aliases)\n  - Getting multiple aliases at once \n- [translate](#item-translate)\n  - Translating a message \n- [validate](#item-validate)\n  - Validating a data \n- [log](#item-log)\n  - Logging a message with PSR-3 logger \n- [cache](#item-cache)\n  - Accessing the PSR-6 cache \n\n### Functions\n\u003ca id=\"item-container\"\u003e\u003c/a\u003e\n#### `container(string $id, bool $optional = false): mixed`\n\n- `$id` is a container id\n- `$optional` is a flag to return `null` if the `$id` is not found in the container\n\n```php\ncontainer(\\App\\MyService::class); // =\u003e \\App\\MyService instance\ncontainer('not-exist'); // =\u003e throws \\Psr\\Container\\NotFoundExceptionInterface\ncontainer('not-exist', true); // =\u003e null\n```\n\n\u003ca id=\"item-route\"\u003e\u003c/a\u003e\n#### `route(string $name, array $params = [], array $query = []): string`\n\n- `$name` is a route name\n- `$params` is a route params\n- `$query` is a query params\n\n```php\nroute('site/index'); // =\u003e '/index'\nroute('user/view', ['id' =\u003e 1]); // =\u003e '/user/1'\nroute('site/index', [], ['page' =\u003e 2]); // =\u003e '/index?page=2'\n```\n\n\u003ca id=\"item-view\"\u003e\u003c/a\u003e\n#### `view(string $view, array $params = [], null|string|object $controller = null): \\Yiisoft\\DataResponse\\DataResponse`\n\n- `$view` is a view name\n- `$params` is a view params\n- `$controller` is a controller instance or a path to views directory. Used to bind views to the specific directory.\n\n```php\nview('site/index'); // =\u003e A response object with content of file '/views/site/index.php'\nview('site/index', ['page' =\u003e 2]); // =\u003e A response object with content of file '/views/site/index.php' and params ['page' =\u003e 2]\nview('index', ['page' =\u003e 2], new MyController()); // =\u003e A response object with content of file '/views/my/index.php' and params ['page' =\u003e 2]\nview('index', ['user' =\u003e $user], 'module/user'); // =\u003e A response object with content of file '/views/module/user/index.php' and params ['user' =\u003e $user]\n\nclass SiteController \n{\n    public function actionIndex()\n    {\n        return view('index', [], $this);  // =\u003e A response object with content of file '/views/site/index.php'\n    }\n}\n```\n\n\u003ca id=\"item-response\"\u003e\u003c/a\u003e\n#### `response(int|null|string|array|StreamInterface $body = null, int $code = 200, string $status = 'OK', array $headers = []): \\Psr\\Http\\Message\\ResponseInterface`\n\n- `$body` is a response body\n- `$code` is a response code\n- `$status` is a response status\n- `$headers` is a response headers\n\n```php\nresponse('Hello world'); // =\u003e A response object with body 'Hello world'\nresponse('Hello world', 201); // =\u003e A response object with body 'Hello world' and code 201\nresponse('Hello world', 201, 'Created'); // =\u003e A response object with body 'Hello world', code 201 and status 'Created'\nresponse('Hello world', 201, 'Created', ['X-My-Header' =\u003e 'My value']); // =\u003e A response object with body 'Hello world', code 201, status 'Created' and header 'X-My-Header' with value 'My value'\n\nresponse(['message' =\u003e 'Hello world']); // =\u003e A response object with body '{\"message\":\"Hello world\"}' and header 'Content-Type' with value 'application/json'\n```\n\n\u003ca id=\"item-redirect\"\u003e\u003c/a\u003e\n#### `redirect(string $name, array $parameters = [], array $query = [], int $code = Status::TEMPORARY_REDIRECT, bool $absolute = false): \\Psr\\Http\\Message\\ResponseInterface`\n\n- `$name` is a route name or an absolute url if `$absolute` is `true`\n- `$parameters` is a route parameters. Used only if `$absolute` is `false`\n- `$query` is a query parameters\n- `$code` is a response code\n- `$absolute` is a flag to generate absolute url, default is `false`\n\n```php\n// Route name 'site/index' is bound to '/index'\nredirect('site/index'); // =\u003e A response object with code 307 and header 'Location' with value '/index'\nredirect('site/index', ['page' =\u003e 2]); // =\u003e A response object with code 307 and header 'Location' with value '/index/2'\nredirect('site/index', [], ['page' =\u003e 2]); // =\u003e A response object with code 307 and header 'Location' with value '/index?page=2'\nredirect('site/index', [], ['page' =\u003e 2], Status::PERMANENT_REDIRECT); // =\u003e A response object with code 308 and header 'Location' with value '/index?page=2'\n\n// Generating absolute url\nredirect('/path/to/redirect', [], ['page' =\u003e 2], Status::PERMANENT_REDIRECT, true); // =\u003e A response object with code 308 and header 'Location' with value 'http://localhost/path/to/redirect?page=2'\n```\n\n\u003ca id=\"item-alias\"\u003e\u003c/a\u003e\n#### `alias(string $path): string`\n\n- `$path` is an alias name\n\n```php\nalias('@runtime'); // =\u003e '/path/to/runtime'\n```\n\n\u003ca id=\"item-aliases\"\u003e\u003c/a\u003e\n#### `aliases(string ...$paths): array`\n\n- `$paths` is alias names\n\n```php\naliases('@runtime', '@webroot'); // =\u003e ['/path/to/runtime', '/path/to/webroot']\n```\n\n\u003ca id=\"item-translate\"\u003e\u003c/a\u003e\n#### `translate(string $message, array $params = [], string $category = 'app', string $language = null): string`\n\n- `$message` is a translation message\n- `$params` is a translation params\n- `$category` is a translation category\n- `$language` is a translation language\n\n```php\ntranslate('main.hello'); // =\u003e 'Hello world'\ntranslate('error.message', ['message' =\u003e 'Something went wrong']); // =\u003e 'Error: \"Something went wrong\".'\ntranslate('error.message', ['message' =\u003e 'Something went wrong'], 'modules'); // =\u003e 'Error from a module: \"Something went wrong\".'\ntranslate('error.message', ['message' =\u003e 'Something went wrong'], 'modules', 'ru'); // =\u003e 'Ошибка из модуля: \"Something went wrong\".'\n```\n\n\u003ca id=\"item-validate\"\u003e\u003c/a\u003e\n#### `validate(mixed $data, callable|iterable|object|string|null $rules = null, ?ValidationContext $context = null): Result`\n\n- `$data` is a data to validate\n- `$rules` is a validation rules\n- `$context` is a validation context\n\n```php\nvalidate(\n    ['name' =\u003e 'John'],\n    ['name' =\u003e [new Required()]],\n);\n```\n\nSee more about validator rules in [yiisoft/validator](https://github.com/yiisoft/validator)\n\n\u003ca id=\"item-log\"\u003e\u003c/a\u003e\n#### `log_message(string $level, string|stringable $message, array $context = []): void`\n\n- `$level` is a log level. Available levels: `emergency`, `alert`, `critical`, `error`, `warning`, `notice`, `info`, `debug`.\n  - You can use `\\Psr\\Log\\LogLevel` constants: \n    - `\\Psr\\Log\\LogLevel::EMERGENCY`\n    - `\\Psr\\Log\\LogLevel::ALERT`\n    - `\\Psr\\Log\\LogLevel::CRITICAL`\n    - `\\Psr\\Log\\LogLevel::ERROR`\n    - `\\Psr\\Log\\LogLevel::WARNING`\n    - `\\Psr\\Log\\LogLevel::NOTICE`\n    - `\\Psr\\Log\\LogLevel::INFO`\n    - `\\Psr\\Log\\LogLevel::DEBUG`.\n- `$message` is a log message\n- `$context` is a log context\n\nAlso, you can use already level-specific functions:\n- `log_emergency(string|Stringable $message, array $context = []): void`\n- `log_alert(string|Stringable $message, array $context = []): void`\n- `log_critical(string|Stringable $message, array $context = []): void`\n- `log_error(string|Stringable $message, array $context = []): void`\n- `log_warning(string|Stringable $message, array $context = []): void`\n- `log_notice(string|Stringable $message, array $context = []): void`\n- `log_info(string|Stringable $message, array $context = []): void`\n- `log_debug(string|Stringable $message, array $context = []): void`\n\n```php\nlog_message('info', 'Some info message');\nlog_message('error', 'Could not authenticate user with ID {user_id}', ['user_id' =\u003e $userId]);\n\nlog_info('Info message');\nlog_error('Error message');\nlog_warning('Warning message');\nlog_notice('Notice message');\nlog_debug('Debug message');\nlog_critical('Critical message');\nlog_alert('Alert message');\nlog_emergency('Emergency message');\n```\n\n\u003ca id=\"item-cache\"\u003e\u003c/a\u003e\n#### `cache(string|int|Stringable|array $key, mixed $value = null, int|DateInterval|null $ttl = null): mixed`\n\n- `$key` is a cache key\n- `$value` is a cache value\n- `$ttl` is a cache TTL\n\n```php\ncache('key', 'value'); // returns \"value\" and sets cache with key \"key\" if it does not exist\n\ncache('key', 'value', 3600); // sets cache with key \"key\" and value \"value\" for 1 hour\ncache('key', 'value', new DateInterval('PT1H')); // also TTL can be an instance of DateInterval\n\ncache('key', fn () =\u003e 'value'); // $value can be a closure. It will be executed only if cache with key \"key\" does not exist\n\ncache(new StringableClass('key'), fn () =\u003e 'value'); // $key can be an instance of Stringable\ncache(12345, fn () =\u003e 'value'); // $key can be an integer\ncache(['key' =\u003e 'value', '!@#$%^\u0026*()_+`' =\u003e '_)(*\u0026^%$#@!~`'], fn () =\u003e 'value'); // $key can be an array. It will be serialized to a JSON and the following characters will be replaced to \"_\": {}()/\\@:\n```\n\n## Looking for more modules?\n\n- [Unique ID](https://github.com/xepozz/unique-id) - Allows you to track the unique user in the application.\n- [Request ID](https://github.com/xepozz/request-id) - A simple library to generate both unique request and response IDs for tracing purposes.\n- [AB](https://github.com/xepozz/ab) - A simple library to enable A/B testing based on a set of rules.\n- [Feature Flag](https://github.com/xepozz/feature-flag) - A simple library to enable/disable features based on a set of rules.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxepozz%2Fshortcut","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxepozz%2Fshortcut","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxepozz%2Fshortcut/lists"}