承接 tamtamchik/simple-flash 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

tamtamchik/simple-flash

Composer 安装命令:

composer require tamtamchik/simple-flash

包简介

Easy, framework agnostic flash notifications for PHP.

README 文档

README

Latest Version on Packagist PHP Total Downloads Software License Build Status Coverage Status Quality Score

SensioLabsInsight

Easy, framework-agnostic flash notifications for PHP. Inspired by laracasts/flash and plasticbrain/PHP-Flash-Messages. It supports multiple CSS frameworks out of the box:

simple-flash

Note

The documentation below is for version 4.x! If you are looking for the documentation for version 3.x look here. If you are looking for the documentation for version 2.x look here. If you are looking for the documentation for version 1.x look here.

Upgrading from 3.x

The set of bundled templates has been rotated — stalled frameworks were dropped and a new set of actively maintained ones added. The new templates are not drop-in replacements; pick whichever fits your project.

Removed in 4.0:

  • Templates::SEMANTIC / flash()->displaySemantic()
  • Templates::SPECTRE / flash()->displaySpectre()
  • Templates::HALFMOON / flash()->displayHalfmoon()
  • Templates::MATERIALIZE / flash()->displayMaterialize()

Added in 4.0:

  • Templates::FOMANTIC / flash()->displayFomantic()Fomantic UI, the community fork of Semantic UI.
  • Templates::CIRRUS / flash()->displayCirrus()Cirrus CSS.
  • Templates::VANILLA / flash()->displayVanilla()Vanilla Framework.
  • Templates::BEERCSS / flash()->displayBeercss()Beer CSS.

If a removed framework is critical to your project, pin to ^3.0 until you migrate, or write your own template (see Creating templates).

Install

Via Composer.

$ composer require tamtamchik/simple-flash

Inside your project make sure to start a session and load Composer autoload to make everything work.

<?php
// Start a Session
if( !session_id() ) {
    session_start();
}

// Initialize Composer Autoload
require_once 'vendor/autoload.php';

Usage

There are 3 ways to use library:

use \Tamtamchik\SimpleFlash\Flash;
use function Tamtamchik\SimpleFlash\flash;

// Instance
$flash = new Flash();
$flash->message('Tea.');

// Static
Flash::message('Earl Gray.');

// Function
flash()->message('Hot!');

Messages added by calling message($message, $type = 'info') method. In case of calling a function flash() you can pass $message, $type just to function like so: flash('resistance is futile').

Because any of creation types return \Tamtamchik\SimpleFlash\Flash instance, so you can always use chaining to add multiple messages. Shortcuts available for all types of base message types, also you can pass arrays as $message.

use function Tamtamchik\SimpleFlash\flash;

flash()->error(['Invalid email!', 'Invalid username!'])
       ->warning('Warning message.')
       ->info('Info message.')
       ->success('Success message!');

Out of the box library support 4 different types of messages: error, warning, info, success.

<div class="alert alert-danger" role="alert">
  <p>Invalid email!</p>
  <p>Invalid username!</p>
</div>
<div class="alert alert-warning" role="alert"><p>Warning message.</p></div>
<div class="alert alert-info" role="alert"><p>Info message.</p></div>
<div class="alert alert-success" role="alert"><p>Success message!</p></div>

Rendering is simple:

use function Tamtamchik\SimpleFlash\flash;

// Rendering specific type
$output = flash()->display('error');

// Rendering all flash
$output = flash()->display();

// Also rendering possible when you just read instance of \Tamtamchik\SimpleFlash\Flash object as a string
(string) flash();

// or ... it's totally just for display, never do this in real life...
<?php
// ... some code
$flash = new Flash();
$flash->warning('It is totally just for display, never do this in real life...');
// ... some other code
?>
<!-- ... some html -->
<div class="flashes">
  <?= $flash; ?>
</div>
<!-- ... some other html -->

Templates

Using templates you can customize how flash messages will be rendered. Package comes with a set of templates for most popular CSS frameworks:

Templates::BASE; // Same as Templates::BOOTSTRAP
Templates::BOOTSTRAP;   // https://getbootstrap.com
Templates::FOUNDATION;  // https://get.foundation
Templates::BULMA;       // https://bulma.io
Templates::TAILWIND;    // https://tailwindcss.com
Templates::PRIMER;      // https://primer.style
Templates::UIKIT;       // https://getuikit.com
Templates::FOMANTIC;    // https://fomantic-ui.com
Templates::CIRRUS;      // https://cirrus-ui.com
Templates::VANILLA;     // https://vanillaframework.io
Templates::BEERCSS;     // https://www.beercss.com

Shortcuts

You cah pass template name as a second argument to display() function:

use function Tamtamchik\SimpleFlash\flash;

flash()->success('Success message!');
...
// rendering with Fomantic template using Templates::FOMANTIC as a shortcut
echo flash()->display('success', Templates::FOMANTIC);

Or you can use descriptive display functions:

use function Tamtamchik\SimpleFlash\flash;

flash()->success('Success message!');
...
echo flash()->displayBootstrap();
echo flash()->displayFoundation();
echo flash()->displayBulma();
echo flash()->displayTailwind();
echo flash()->displayPrimer();
echo flash()->displayUiKit();
echo flash()->displayFomantic();
echo flash()->displayCirrus();
echo flash()->displayVanilla();
echo flash()->displayBeercss();

Factory

Package comes with a set of templates for most popular CSS frameworks:

This templates can be created using TemplateFactory that comes with package. All templates have aliases defined in Templates.

use Tamtamchik\SimpleFlash\Flash;
use Tamtamchik\SimpleFlash\TemplateFactory;
use Tamtamchik\SimpleFlash\Templates;

// get template from factory, e.g. template for Foundation
$template = TemplateFactory::create(Templates::FOUNDATION);

// passing template via function
flash('Info message using Foundation 6 template!', 'info', $template);

// passing to constructor
$flash = new Flash($template);

// using setTemplate function
$flash->setTemplate($template);

Creating templates

Template is basically any class that implements TemplateInterface. But to make it easy you can extend BaseTemplate, it already contains most of the functions.

Defining and using this sample class as template:

use Tamtamchik\SimpleFlash\BaseTemplate;
use Tamtamchik\SimpleFlash\TemplateInterface;
use function Tamtamchik\SimpleFlash\flash;

class CustomTemplate extends BaseTemplate implements TemplateInterface
{
    protected $prefix  = '<li>'; // every line prefix
    protected $postfix = '</li>'; // every line postfix
    protected $wrapper = '<ul class="alert-%s">%s</ul>'; // wrapper over messages of same type

    /**
     * @param $messages - message text
     * @param $type     - message type: success, info, warning, error
     *
     * @return string
     */
    public function wrapMessages($messages, $type)
    {
        return sprintf($this->getWrapper(), $type, $messages);
    }
}

flash()
    ->setTemplate(new CustomTemplate)
    ->error(['Invalid email!', 'Invalid username!'])
    ->warning('Warning message.')
    ->info('Info message.')
    ->success('Success message!')
    ->display();

Will output following:

<ul class="alert-error">
    <li>Invalid email!</li>
    <li>Invalid username!</li>
</ul>
<ul class="alert-warning">
    <li>Warning message.</li>
</ul>
<ul class="alert-info">
    <li>Info message.</li>
</ul>
<ul class="alert-success">
    <li>Success message!</li>
</ul>

Interface

Package provides TemplateInterface for Simple Flash templates.

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer tests

Examples

$ composer examples

And then just visit http://localhost:8000

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Security

If you discover any security related issues, please email yuri.tam.tkachenko@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Buy Me A Coffee

tamtamchik/simple-flash 适用场景与选型建议

tamtamchik/simple-flash 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 113.66k 次下载、GitHub Stars 达 106, 最近一次更新时间为 2015 年 05 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 tamtamchik/simple-flash 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 113.66k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 127
  • 点击次数: 19
  • 依赖项目数: 6
  • 推荐数: 0

GitHub 信息

  • Stars: 106
  • Watchers: 4
  • Forks: 15
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-05-26