sorciulus/simple-factory 问题修复 & 功能扩展

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

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

sorciulus/simple-factory

最新稳定版本:2.1.8

Composer 安装命令:

composer require sorciulus/simple-factory

包简介

This library generate object from class name

README 文档

README

Packagist Scrutinizer Code Quality Code Intelligence Status Maintainability Software License Build Status

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.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-05-01

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固