laragrad / codifier
v1.2.2
2021-09-11 13:17 UTC
Requires
- php: ^7.2|^8.0
README
本软件包提供了一个服务,可以将任何项目的配置数据作为代码字典使用,支持多语言和缓存。
安装
在控制台运行以下命令
composer require laragrad/codifier
将以下行添加到您的 config/app.php
$providers => [
...
\Laragrad\Codifier\CodifierServiceProvider::class,
],
$aliases => [
...
'Codifier' => \Laragrad\Codifier\CodifierServiceFacade::class,
],
在控制台运行以下命令
php artisan vendor:publish
并输入选择号码以发布 \Laragrad\Codifier\CodifierServiceProvider
以下文件将被发布
/config/laragrad/codifier/config.php
- 软件包配置/config/laragrad/codifier/example.php
- 示例codifier数据/resources/lang/vendor/laragrad/codifier/en/messages.php
- 软件包消息/resources/lang/vendor/laragrad/codifier/en/example.php
- 示例codifier翻译
配置
请参阅文件 /config/laragrad/codifier/config.php
中的软件包配置示例。
有两个根元素
- use_cache - 启用或禁用缓存使用的布尔选项。
- sections - codifier部分配置的数组。
部分配置
部分配置必须包含以下选项
- data_path - 组成部分数据的配置路径
- trans_base_path - 语言翻译资源的基础路径
- handler - 处理器类名
Codifier门面方法
get()
返回部分元素或完整数据。
get(string $section, string|null $path, string|null $locale) : array
参数
- $section - 部分名称。
- $path - 部分元素的路径。如果它是 NULL,则返回完整的部分数据。
- $locale - 区域代码。如果它是 NULL,则当前区域。
getSection()
返回一个部分数据。
getSection(string $section, string|null $locale) : array
参数
- $section - 部分名称。
- $locale - 区域代码。如果它是 NULL,则当前区域。
getSections()
返回所有部分的数组。
getSections(array|null $sections, string|null $locale) : array
参数
- $sections - 部分名称的数组。如果它是 NULL,则所有配置的部分。
- $locale - 区域代码。如果它是 NULL,则当前区域。
cache()
如果配置中启用了缓存使用,则预热缓存键。
cache(array|string|null $sections, array|string|null $locales) : array
参数
- $sections - 一个部分名称或部分名称的数组。如果它是 NULL,则所有配置的部分。
- $locales - 一个区域代码或区域代码的数组。如果它是 NULL,则所有配置的区域。
返回消息列表。
clear()
如果配置中启用了缓存使用,则清除缓存键。
clear(array|string|null $sections, array|string|null $locales) : array
参数
- $sections - 一个部分名称或部分名称的数组。如果它是 NULL,则所有配置的部分。
- $locales - 一个区域代码或区域代码的数组。如果它是 NULL,则所有配置的区域。
返回消息列表。