marvin255/value-object-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

marvin255/value-object-bundle

最新稳定版本:v0.2.0

Composer 安装命令:

composer require marvin255/value-object-bundle

包简介

Set of value objects for Dotrine in Symfony.

README 文档

README

Latest Stable Version Total Downloads License Build Status

Symfony bundle that provides Doctrine types for common value objects such as Email, Uri, String, Integer, and FileInfo.

Installation

Install the package via Composer:

composer require marvin255/value-object-bundle

Configuration

Add the bundle to your config/bundles.php (if not done automatically):

return [
    // ...
    Marvin255\ValueObjectBundle\Marvin255ValueObjectBundle::class => ['all' => true],
];

Usage

The bundle provides Doctrine DBAL types that automatically convert database values to value objects and vice versa.

Supported Value Object Types

  • marvin255_string - StringValueObject
  • marvin255_non_empty_string - StringNonEmptyValueObject
  • marvin255_email - EmailValueObject
  • marvin255_uri - UriValueObject
  • marvin255_file_info - FileInfoValueObject
  • marvin255_integer - IntValueObject
  • marvin255_positive_integer - IntPositiveValueObject
  • marvin255_negative_integer - IntNegativeValueObject
  • marvin255_non_negative_integer - IntNonNegativeValueObject
  • marvin255_non_positive_integer - IntNonPositiveValueObject
  • marvin255_float - FloatValueObject
  • marvin255_percentage - PercentageValueObject
  • marvin255_bc_math_number - BcMathNumberValueObject (requires bcmath PHP extension)

Optional Types

Some types are only available when their corresponding PHP extensions are installed:

BcMath Type (marvin255_bc_math_number)

The BcMathNumberValueObject type provides arbitrary-precision decimal arithmetic using PHP's bcmath extension. It's automatically registered only if the bcmath extension is enabled.

To enable bcmath on your PHP installation, ensure it's installed and uncommented in php.ini:

extension=bcmath

If the extension is not available, the type will not be registered but the rest of the bundle will continue to function normally.

Define Entity Properties

Use the Doctrine types in your entity mapping:

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Marvin255\ValueObject\EmailValueObject;
use Marvin255\ValueObject\StringValueObject;

#[ORM\Entity]
class User
{
    #[ORM\Column(type: 'marvin255_string')]
    private ?StringValueObject $name = null;

    #[ORM\Column(type: 'marvin255_email')]
    private EmailValueObject $email;

    public function setEmail(EmailValueObject $email): void
    {
        $this->email = $email;
    }

    public function getEmail(): EmailValueObject
    {
        return $this->email;
    }
}

Working with Value Objects

Create and work with value objects naturally in your code:

use Marvin255\ValueObject\EmailValueObject;
use Marvin255\ValueObject\StringValueObject;

$email = new EmailValueObject('user@example.com');
$name = new StringValueObject('John Doe');

$user->setEmail($email);
$user->setName($name);

$repository->save($user);

The bundle automatically handles conversion between value objects and their database representations.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-31

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固