定制 dshafik/bag 二次开发

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

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

dshafik/bag

最新稳定版本:2.6.2

Composer 安装命令:

composer require dshafik/bag

包简介

A comprehensive immutable value objects implementation

README 文档

README

Bag

Coverage Quality Gate Status

Bag

Immutable Value Objects for PHP 8.3+ inspired by spatie/laravel-data, created by Davey Shafik.

Introduction

Bag helps you create immutable value objects. It's a great way to encapsulate data within your application.

Bag prioritizes immutability and type safety with built-in validation and data casting.

When to use Value Objects

Value objects should be used in place of regular arrays, allowing you enforce type safety and immutability.

Features

  • Immutable & Strongly typed
  • Value casting — both input and output
  • Collection support
  • Composable — nest Bag value objects and collections
  • Built-in validation

Note

Bag is framework-agnostic, but it works great with Laravel. Bag uses standard Laravel Collections and Validation. In addition, it will automatically inject Bag\Bag value objects into your controllers with validation.

Requirements

Bag requires PHP 8.3+, and supports Laravel 11.x.

Installation

You can install the package via composer:

composer require dshafik/bag

Usage

Creating a Value Object

To create a basic Value Object, extend the Bag\Bag class and define your properties in the constructor:

use Bag\Bag;

readonly class MyValue extends Bag {
    public function __construct(
        public string $name,
        public int $age,
    ) {
    }
}

Instantiating a Value Object

To create a new instance of your Value Object, call the ::from() method:

$value = MyValue::from([
    'name' => 'Davey Shafik',
    'age' => 40,
]);

Documentation

Full documentation can be found here.

统计信息

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

GitHub 信息

  • Stars: 174
  • Watchers: 4
  • Forks: 9
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 未知

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固