承接 gajus/paddy 相关项目开发

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

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

gajus/paddy

Composer 安装命令:

composer require gajus/paddy

包简介

Session based (flash) messaging utility.

README 文档

README

Build Status Coverage Status Latest Stable Version

Messenger is used to carry (flash) messages between page requests using session.

/**
 * @param string $namespace Namespace is used if more than one application is using Messenger. Defaults to the SERVER_NAME or "default".
 */
$messenger = new \Gajus\Paddy\Messenger();

/**
 * @param string $message
 * @param string $namespace Message namespace (success, error or notice).
 * @return $this
 */
$messenger->send('Loaded to the Gunwales!');

Sending a Message

Message is sent using send method. The second parameter is used to put message under a namespace.

$messenger->send('There is more grog on the deck!', 'success');

Namespace values are limited to "error", "notice" and "success". Limit is imposed to avoid accidental (and hard to catch) typos. If you would like to change this behaviour, raise an issue including an example use case for an alternative or a variable namespace.

Getting Messages

To get all messages nested under the respective namespace, use getMessages method:

/**
 * Return all messages nested under the respective message namespace.
 * 
 * @return array
 */
$messenger->getMessages();

To check if there are messages under a specific namespace, use has method:

/**
 * Check if there are messages under the specified message namespace.
 * 
 * @param string $namespace
 * @return boolean
 */
$messenger->has('error');

Message Holder

Use the message holder when you intend to display messages to the end user:

$messenger->send('a');
$messenger->send('b', 'success');

echo $messenger->getMessageHolder();
<ul class="paddy-messenger with-messages">
    <li class="error">a</li>
    <li class="success">b</li>
</ul>

When there are no messages, getMessageHolder will produce:

<ul class="paddy-messenger no-messages"></ul>

The empty tag is used for interoperability with the frontend script.

Proposed stylesheet:

.paddy-messenger {
    display: none;

    li {
        display: block; padding: 20px; color: #fff;

        &.error {
            background: #E74C3C;
        }

        &.notice {
            background: #F1C40F;
        }

        &.important {
            background: #3498DB;
        }

        &.success {
            background: #27AE60;
        }
    }

    &.with-messages {
        display: block;
    }
}

Shorthand

/**
 * Shorthand method to send message under "error" namespace.
 *
 * @param string $message
 * @return $this
 */
public function error ($message) {
    return $this->send($message, 'error');
}

/**
 * Shorthand method to send message under "success" namespace.
 *
 * @param string $message
 * @return $this
 */
public function success ($message) {
    return $this->send($message, 'success');
}

/**
 * Shorthand method to send message under "notice" namespace.
 *
 * @param string $message
 * @return $this
 */
public function notice ($message) {
    return $this->notice($message, 'notice');
}

Quasi-Persistency

Messages are carried across pages using $_SESSION variable. This requires that you start session before using Paddy.

// Page 1
$messenger->error('foo');

Response that has "location" header continue to persist message data:

// Page 2
header('Location: Page 3');

Messages are discarded after the first page is displayed:

// Page 3
var_dump($messenger->has('error'));
array(1) {
  [0]=>
  bool(true)
}

Name

Named after pigeon number NPS.43.9451, Paddy.

Logging

Implements PSR-3 LoggerAwareInterface.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2014-04-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固