rnr1721/le7-messages
Composer 安装命令:
composer require rnr1721/le7-messages
包简介
Messages for le7 PHP MVC framework
README 文档
README
This package is probably easy and convenient to implement flash messages using cookies or session or use without storage as message collection.
It is also possible to make simple, standardized messages for a web page or API response. Messages can be grouped by source and type. It is possible to apply your own set of sources or types.
This package use only one dependency - rnr1721/le7-cookie-wrapper for managing sessions and cookies
Message types (can not set own):
- info
- error
- question
- alert
- warning
predefined sources (can set own):
- core
- application
- user
- event
- system
Requirements
- PHP 8.1 or higher.
- Composer 2.0 or higher.
What it can?
- Add new messages to collection
- get messages by source or type
- get messages in full formar (with type and source or as plain array)
- Store messages in session or cookies or get it from these sources
Installation
composer require rnr1721/le7-messages
Testing
composer test
How use?
use Core\Session\SessionNative; use Core\Cookies\CookiesNative; use Core\Messages\MessageFactoryGeneric; $session = new SessionNative(); $cookies = new CookiesNative(); $factory = new MessageFactoryGeneric($cookies, $session); $messages = $factory->getMessagesSession(); // $messages = $factory->getMessagesCookie(); // If need cookies storage // $messages = $factory->getMessageCollection(); // if no need storage $messages->alert("Alert message"); $messages->info("Info message"); $messages->warning("Warning messages"); $messages->question("Question message"); $messages->error("error message"); // And when we need to output all: $message->getAll(); //return messages array $messages->getErrors(); // Get all errors $messages->getErrors(true); // Get all errors as plain array $messages->getAlerts(); // Get all alerts $messages->getWarnings(); $messages->getQuestions(); $messages->getInfos(); $messages->getErrors(); // You can use a message contexts. // For example: $messages->alert('My message','application'); $messages->warning('my message','core'); $messages->error('error message','core'); $messages->getBySource('core'); // Get all with core context $messages->getBySource('core', true); // Plain output // Put messages to session or to cookies $messages->putToDestination(); // Get messages from session or from cookies as array $messages->getFromSource; // Load messages from session or from cookies $messages->loadMessages(); // Clear all messages $messages->clear(); // Return if empty messages $messages->isEmpty();
What implemented?
<?php namespace Core\Interfaces; interface MessageCollection { /** * Create message of something type * @param string $message Message text * @param string $status Message status * @param string $source Message source * @return self */ public function newMsg(string $message, string $status = 'info', string $source = 'application'): self; /** * Get all messages as array * @param bool $plain For plain - simple array $key=>$value * @return array */ public function getAll(bool $plain = false): array; /** * Get info messages as array * @param bool $plain For plain - simple array $key=>$value * @return array */ public function getInfos(bool $plain = false): array; /** * Get warning messages as array * @param bool $plain For plain - simple array $key=>$value * @return array */ public function getWarnings(bool $plain = false): array; /** * Get question messages as array * @param bool $plain For plain - simple array $key=>$value * @return array */ public function getQuestions(bool $plain = false): array; /** * Get alert messages as array * @param bool $plain For plain - simple array $key=>$value * @return array */ public function getAlerts(bool $plain = false): array; /** * Get error messages as array * @param bool $plain For plain - simple array $key=>$value * @return array */ public function getErrors(bool $plain = false): array; /** * Get messages by source * @param string $source Actual source from sources * @return array */ public function getBySource(string $source, bool $plain = false): array; /** * Emit alert message * @param string $message Message text * @param string $source Source * @return MessageCollection */ public function alert(string $message, string $source = "application"): self; /** * Emit warning message * @param string $message Message text * @param string $source Source * @return MessageCollection */ public function warning(string $message, string $source = "application"): self; /** * Emit question message * @param string $message Message text * @param string $source Source * @return MessageCollection */ public function question(string $message, string $source = "application"): self; /** * Emit info message * @param string $message Message text * @param string $source Source * @return MessageCollection */ public function info(string $message, string $source = "application"): self; /** * Emit error message * @param string $message Message text * @param string $source Source * @return MessageCollection */ public function error(string $message, string $source = "application"): self; /** * Get messages somewhere * @param MessageGet|null $getMethod Instance of messageGet interface * @param string $type Type of messages or all * @return array */ public function getFromSource(?MessageGet $getMethod = null, string $type = 'all'): array; /** * Some as getMessages, but messages load to current messages list * @param MessageGet|null $getMethod Interface to load * @param string $type Message type * @return bool */ public function loadMessages(?MessageGet $getMethod = null, string $type = 'all'): bool; /** * Clear all messages * @return void */ public function clear(): void; /** * Messages empty? bool. * @return bool */ public function isEmpty(): bool; }
<?php namespace Core\Interfaces; interface MessageCollectionFlash extends MessageCollection { /** * Put messages to somewhere using interface * @param MessagePut|null $putMethod Instance of MessagePut interface * @param string $type Type of messages or all * @return bool */ public function putToDestination(?MessagePut $putMethod = null, string $type = 'all'): bool; }
rnr1721/le7-messages 适用场景与选型建议
rnr1721/le7-messages 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 85 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 03 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「component」 「messages」 「le7」 「le7-framework」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 rnr1721/le7-messages 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rnr1721/le7-messages 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 rnr1721/le7-messages 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
FSi DataSource Component
Priveate for SkeekS CMS
Class Log libraries
Element Messages for CraftCMS
A Laravel package made for displaying flashes messages in a conveniant way
统计信息
- 总下载量: 85
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 8
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-03-27