sorciulus/simple-factory
Composer 安装命令:
composer require sorciulus/simple-factory
包简介
This library generate object from class name
README 文档
README
This library has been designed to make it easy to generate value objects. You can set the parameters of the object without knowing in what order it is passed to the constructor. This library will be useful if you have so many parameters to pass to the constructor. By default all parameter will be set to null. If parameter is class (dependency injection) this library will attempt to create an empty object and pass it as a parameter.
Installation
Via Composer:
composer require sorciulus/simple-factory
Usage
<?php require_once 'vendor/autoload.php'; use SimpleFactory\SimpleFactory; class Publisher { /** * The name of publisher * * @var string */ private $name; /** * The city of publisher * * @var string|null */ private $city; /** * @param string $name */ public function __construct(string $name, ?string $city) { $this->name = $name; } /** * Get the name of publisher * * @return string */ public function getName() : string { return $this->name; } /** * Get the city of publisher * * @return string|null */ public function getCity() :?string { return $this->city; } } $factory = new SimpleFactory(Publisher::class); $publisher = $factory->setName('MyPublisher')->setCity('London')->make();
You can factory object by the same initialized object, all property setter will be set at new factory object
$otherFactory = new SimpleFactory(Publisher::class); $newPublisher = $otherFactory->with($publisher)->make();
If you want to set all the missing parameters to null, pass as a true parameter in the constructor
$otherFactory = new SimpleFactory(Publisher::class, true); $newPublisher = $otherFactory->make();
In alternative you can create a factory object from static method create
$newPublisher = SimpleFactory::create(Publisher::class)->setName('MyPublisher')->setCity('London')->make();
License
This Library is released under the MIT License. Please see License File for more information.
sorciulus/simple-factory 适用场景与选型建议
sorciulus/simple-factory 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.92k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 05 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「object」 「factory」 「value」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sorciulus/simple-factory 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sorciulus/simple-factory 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sorciulus/simple-factory 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A set of useful PHP classes.
Testing object factory for PHP
Testing object factory for PHP
Runn Me! Value Objects Library
Laravel 5 Model Factory Generator.
Laravel SDK mapping data in object
统计信息
- 总下载量: 4.92k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-05-01