tobento/app-message

应用消息管理器。

1.0.0 2024-03-01 18:31 UTC

This package is auto-updated.

Last update: 2024-09-30 19:43:18 UTC


README

消息 管理器用于应用。

目录

入门

运行以下命令添加应用消息项目的最新版本。

composer require tobento/app-message

需求

  • PHP 8.0 或更高版本

文档

应用

如果您正在使用骨架,请查看 App Skeleton

您还可以查看 应用 以了解有关应用的一般信息。

消息引导

消息引导执行以下操作:

  • 配置消息工厂
use Tobento\App\AppFactory;
use Tobento\Service\Message\MessagesFactoryInterface;

// Create the app
$app = (new AppFactory())->createApp();

// Add directories:
$app->dirs()
    ->dir(realpath(__DIR__.'/../'), 'root')
    ->dir(realpath(__DIR__.'/../app/'), 'app')
    ->dir($app->dir('app').'config', 'config', group: 'config')
    ->dir($app->dir('root').'public', 'public')
    ->dir($app->dir('root').'vendor', 'vendor');

// Adding boots
$app->boot(\Tobento\App\Message\Boot\Message::class);
$app->booting();

// Implemented interfaces:
$messagesFactory = $app->get(MessagesFactoryInterface::class);

// Run the app
$app->run();

创建消息

查看 消息服务 - 消息工厂 部分以了解更多有关创建消息的信息。

翻译消息

简单地安装 App Translation 包并引导 \Tobento\App\Translation\Boot\Translation::class

composer require tobento/app-translation
use Tobento\App\AppFactory;

// Create the app
$app = (new AppFactory())->createApp();

// Add directories:
$app->dirs()
    ->dir(realpath(__DIR__.'/../'), 'root')
    ->dir(realpath(__DIR__.'/../app/'), 'app')
    ->dir($app->dir('app').'config', 'config', group: 'config')
    ->dir($app->dir('root').'public', 'public')
    ->dir($app->dir('root').'vendor', 'vendor');
    
// Adding boots
$app->boot(\Tobento\App\Translation\Boot\Translation::class);
$app->boot(\Tobento\App\Message\Boot\Message::class);

// Run the app
$app->run();

消息将根据 配置的翻译器区域 进行翻译。

配置的 消息翻译器修饰符 使用 * 作为资源名称。查看 翻译资源翻译文件资源 以了解更多信息。

查看 添加翻译迁移翻译 部分,了解如何添加或迁移翻译。

记录消息

简单地安装 App Logging 包并引导 \Tobento\App\Logging\Boot\Logging::class

composer require tobento/app-translation
use Tobento\App\AppFactory;

// Create the app
$app = (new AppFactory())->createApp();

// Add directories:
$app->dirs()
    ->dir(realpath(__DIR__.'/../'), 'root')
    ->dir(realpath(__DIR__.'/../app/'), 'app')
    ->dir($app->dir('app').'config', 'config', group: 'config')
    ->dir($app->dir('root').'public', 'public')
    ->dir($app->dir('root').'vendor', 'vendor');
    
// Adding boots
$app->boot(\Tobento\App\Logging\Boot\Logging::class);
$app->boot(\Tobento\App\Message\Boot\Message::class);

// Run the app
$app->run();

App Logging 配置 文件中定义用于消息的记录器

/*
|--------------------------------------------------------------------------
| Aliases
|--------------------------------------------------------------------------
*/

'aliases' => [
    'messages' => 'daily',
],

鸣谢