emeraldinspirations/lib-objectdesignpattern-immutable

不可变对象中常见的函数

2.2.0 2017-08-29 15:31 UTC

This package is not auto-updated.

Last update: 2024-09-29 05:07:53 UTC


README

emeraldinspirations logo

lib-objectdesignpattern-immutable

emeraldinspiration 库中的 emeraldinspiration 的对象设计模式支持类。

不可变对象中常见的函数

安装 / 入门

此项目没有依赖项,因此可以直接从 git 仓库 克隆或使用 Composer 需要。

使用 Composer 需要

composer require emeraldinspirations/lib-objectdesignpattern-immutable

示例

<?php

use emeraldinspirations\library\objectDesignPattern\immutable\ImmutableTrait;

class ExampleImmutableObject
{
    use ImmutableTrait;

    protected $Property;

    /**
     * Return value of Property
     *
     * @return \stdclass
     */
    public function getProperty() : \stdclass
    {
        return $this->Property;
    }

    /**
     * Create new instance with new Property value
     *
     * @param \stdclass $Property New value
     *
     * @return self
     */
    public function withProperty(\stdclass $Property) : self {
        return $this->with(__FUNCTION__, $Property);
    }

    /**
     * Clone all specified properties are cloned as necessary
     *
     * @return void
     */
    public function __clone()
    {

        // Create an array of references to properties to clone
        $PropertiesToByCloned = [
            &$this->Property,
        //  ^ - IMPORTANT: Be sure to pass by reference
        ];

        self::cloneArrayRecursively($PropertiesToByCloned);

    }

}

贡献

如果您想贡献,请分支仓库并使用功能分支。

我也乐于接受关于我如何遵守标准和“最佳实践”的反馈。我已经独立编写软件多年,并试图学习如何更好地与他人合作。

许可

此项目的代码在 MIT 许可证 下授权。