定制 edydeyemi/session-messages 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

edydeyemi/session-messages

Composer 安装命令:

composer require edydeyemi/session-messages

包简介

Simple-to-use Session-based FlashMessages Library for PHP with support for Boostrap 4 and Boostrap 5. A fork of Plasticbrain's session-based FlashMessages

README 文档

README

Keep messages in session data until they are retrieved. Supports Bootstrap 4 or Bootstrap 5.

Notice

This is a forked version of new version of PlasticBrain's PHPFlashMessages - https://github.com/plasticbrain/PhpFlashMessages. This forked version has support for both Bootstrap V4 and Bootstrap V5

Features

  • Namespaced
  • PSR-4 autoload compliant
  • Installable with composer
  • Works with Bootstrap4 or Bootstrap 5
  • Fully customizable messages
  • URL redirects

Installation

With Composer

composer require Edydeyemi/session-messages

Without composer

Download SessionMessages.php and save it to your project directory.

Import the file:

require '/path/to/SessionMessages.php';

Basic Usage

Default theme is Bootstrap V5. Pass 4 into the contructor to switch to Bootstrap V4.

// Start a Session
if (!session_id()) @session_start();
	
// Instantiate the class
$msg = new \Edydeyemi\SessionMessages\SessionMessages(); 
    or  
$msg = new \Edydeyemi\SessionMessages\SessionMessages(4); 

// Add messages
$msg->info('This is an info message');
$msg->success('This is a success message');
$msg->warning('This is a warning message');
$msg->error('This is an error message');


// If you need to check for errors (eg: when validating a form) you can:
if ($msg->hasErrors()) {
	// There ARE errors
} else {
  // There are NOT any errors
}
	
// Wherever you want to display the messages simply call:
$msg->display();

Message Type Constants

Each message type can be referred to by its constant: INFO, SUCCESS, WARNING, ERROR. For example:

$msg::INFO
$msg::SUCCESS
$msg::WARNING
$msg::ERROR

Redirects

It's possible to redirect to a different URL before displaying a message. For example, redirecting back to a form (and displaying an error message) so a user can correct an error.

The preferred method of doing this is by passing the URL as the 2nd parameter:

$msg->error('This is an error message', 'http://yoursite.com/another-page');

A redirect is executed as soon as the message it's attached to is queued. As such, if you need multiple messages AND need to redirect then include the URL with the last message:

$msg->success('This is a success message');
$msg->success('This is another success message');
$msg->error('This is an error message', 'http://redirect-url.com');   

Helper Methods

hasErrors()

Check to see if there are any queued ERROR messages.

if ($msg->hasErrors()) {
    // There are errors, so do something like redirect
}

hasMessages ( [string $type] )

Check to see if there are any specific message types (or any messages at all) queued.

// Check if there are any INFO messages
if ($msg->hasMessages($msg::INFO)) {
    ...
}

// Check if there are any SUCCESS messages
if ($msg->hasMessages($msg::SUCCESS)) {
    ...
}

// Check if there are any WARNING messages
if ($msg->hasMessages($msg::WARNING)) {
    ...
}

// Check if there are any ERROR messages
if ($msg->hasMessages($msg::ERROR)) {
    ...
}

// See if there are *any* messages queued at all
if ($msg->hasMessages()) {
    ...
}

setCloseBtn ( string $html )

Sets the HTML for the close button that's displayed on (non-sticky) messages.

$msg->setCloseBtn('<button type="button" class="close" 
                        data-dismiss="alert" 
                        aria-label="Close">
                        <span aria-hidden="true">&amp;times;</span>
                    </button>')

setCssClassMap ( array $cssClassMap )

Sets the CSS classes that are used for each specific message type.

$msg->setCssClassMap([
    $msg::INFO    => 'alert-info',
    $msg::SUCCESS => 'alert-success',
    $msg::WARNING => 'alert-warning',
    $msg::ERROR   => 'alert-danger',
]);

setMsgAfter ( string $msgAfter )

Add a string of text (HTML or otherwise) after the message (but inside of the wrapper.)

For example, wrap a message in <p> tags:

$msg->setMsgAfter('</p>')

setMsgBefore ( string $msgBefore )

Add a string of text (HTML or otherwise) before the message (but inside of the wrapper.)

For example, wrap a message in <p> tags:

$msg->setMsgBefore('<p>')

setMsgCssClass ( [string $cssClass] )

Sets the CSS class that is applied to all messages, regardless of their type.

$msg->setMsgCssClass('alert')

setMsgWrapper ( string $html )

Sets the HTML that wraps each message. HTML should include two placeholders (%s) for the CSS class and message text.

$msg->setMsgWrapper("<div class='%s'>%s</div>")

License

The MIT License (MIT)

Copyright (c) 2023 Edydeyemi && SoftMage Solutions

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

License

The MIT License (MIT)

Copyright (c) 2015 Mike Everhart & PlasticBrain Media LLC

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

edydeyemi/session-messages 适用场景与选型建议

edydeyemi/session-messages 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 359 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 12 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「session」 「flash」 「messages」 「flash messages」 「session messages」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 edydeyemi/session-messages 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 edydeyemi/session-messages 我们能提供哪些服务?
定制开发 / 二次开发

基于 edydeyemi/session-messages 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 359
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 26
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-12-07