定制 bloise/flunt-php 二次开发

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

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

bloise/flunt-php

Composer 安装命令:

composer require bloise/flunt-php

包简介

Library for notifications and validations

README 文档

README

PHP implementation of Domain Notification Pattern based in Flunt (.NET) developed by @andrebaltieri

Flunt

Flunt is a fluent way to use Notification Pattern with your entities, concentrating every change you made and easy accessing it when you need.

check our Wiki for more details and samples of how to use Flunt in your applications.

Dependencies

Package Version
PHP >=8.1

Instalation

This package is available through Packagist

Composer

composer require bloise/flunt

How to use

final class CPF extends Notifiable
{
  ...
}

$cpf = new CPF('012.345.678-90');
$cpf->addNotification("CPF", "Invalid document");

if($cpf->isValid())
  ...

Specified contract

final class CPF extends Notifiable
{
    private readonly string $document;

    public function __construct(string $document)
    {
        $this->setDocument($document);
        $this->addNotifications(
            (new CPFContract)
                ->hasMinLen($this->document, 'CPF', 'Invalid length')
                ->validFormat($this->document, 'CPF', 'Invalid format')
                ->validDocument($this->document, 'CPF', 'Invalid document')
        );
    }
}

final class CPFContract extends Contract
{
    public function hasMinLen(string $cpf, string $property, string $message): self {
        if (strlen($cpf) != 11) {
            $this->notifications[$property][] = $message;
        }
    }

    public function validFormat(string $cpf, string $property, string $message): self {...}

    public function validDocument(string $cpf, string $property, string $message): self {...}
}

Fluent Methods

$cpf->isValid();
$cpf->getMessages();
$cpf->filterByMessage('Invalid length');

Designed for modern architectures approaches

If you are building an application with clean architecture approaches you can consider use this project, cause it's totally free of external dependencies, feel free to implement a Port/Adapter linking the dependencie with your code base, this one is for those who are more conceptual =)

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-05-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固