martindilling/basicvalueobjects
Composer 安装命令:
composer require martindilling/basicvalueobjects
包简介
A collection of basic value objects.
README 文档
README
A small collection of the most basic value objects. These can help make your code more expressive, and save some manual validation.
Install
All the available versions is visible on Packagist.
Via Composer
$ composer require martindilling/basicvalueobjects
Usage
Using these value objects you can type-hint method arguments to make it more sure the arguments will be given in the right format.
In this example the fields will hold instances of the value objects.
use BasicValueObjects\String; use BasicValueObjects\Integer; use BasicValueObjects\Boolean; class CrewMember { /** @var \BasicValueObjects\String */ private $firstname; /** @var \BasicValueObjects\String */ private $lastname; /** @var \BasicValueObjects\Integer */ private $age; /** @var \BasicValueObjects\Boolean */ private $captain; function __construct(String $firstname, String $lastname, Integer $age, Boolean $captain) { $this->firstname = $firstname; $this->lastname = $lastname; $this->age = $age; $this->captain = $captain; } } $person = new CrewMember( new String('Malcolm'), new String('Reynolds'), new Integer(49), Boolean::true() );
If you don't want the fields on the object to hold the instances but want the type-hinting, you can just assign the native value of the value object to the fields:
use BasicValueObjects\String; use BasicValueObjects\Integer; use BasicValueObjects\Boolean; class CrewMember { /** @var string */ private $firstname; /** @var string */ private $lastname; /** @var int */ private $age; /** @var bool */ private $captain; function __construct(String $firstname, String $lastname, Integer $age, Boolean $captain) { $this->firstname = $firstname->native(); $this->lastname = $lastname->native(); $this->age = $age->native(); $this->captain = $captain->native(); } } $person = new CrewMember( new String('River'), new String('Tam'), new Integer('28'), Boolean::false() );
Demonstration of how to work with the value objects:
// String $shiny = new String("Everything's shiny, Cap'n. Not to fret."); $fool = new String("Oh, she'll fool ya."); $shiny->native(); // (string) Everything's shiny, Cap'n. Not to fret. $fool->__toString(); // (string) Oh, she'll fool ya. $shiny->equals($fool); // (bool) false // Integer $integer1 = new Integer(42); $integer2 = new Integer(37); $integer1->native(); // (integer) 42 $integer2->__toString(); // (string) 37 $integer1->equals($integer2); // (bool) false // Boolean $boolean1 = new Boolean(true); $boolean2 = new Boolean(Boolean::TRUE); $boolean3 = Boolean::false(); $boolean1->native(); // (bool) true $boolean2->__toString(); // (string) true $boolean1->equals($boolean2); // (bool) true $boolean1->equals($boolean3); // (bool) false
Testing
$ phpunit
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email martindilling@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
martindilling/basicvalueobjects 适用场景与选型建议
martindilling/basicvalueobjects 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 19 次下载、GitHub Stars 达 1, 最近一次更新时间为 2015 年 02 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「string」 「ddd」 「value objects」 「integer」 「boolean」 「float」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 martindilling/basicvalueobjects 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 martindilling/basicvalueobjects 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 martindilling/basicvalueobjects 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A set of useful PHP classes.
Runn Me! Value Objects Library
Encode integer IDs using a preset or customized symbol set
base62 encoder and decoder also for big numbers with Laravel integration
MaxAl Subscriptions is a flexible plans and subscription management system for Laravel, with the required tools to run your SAAS like services efficiently. It's simple architecture, accompanied by powerful underlying to afford solid platform for your business.
PHP string processing library.
统计信息
- 总下载量: 19
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 22
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-02-10