承接 alcamo/decorator 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

alcamo/decorator

最新稳定版本:0.2.0

Composer 安装命令:

composer require alcamo/decorator

包简介

Base trait and class to create decorators

关键字:

README 文档

README

use alcamo\decorator\Decorator;
use Ds\Set;

class SetWithSum extends Decorator implements \Countable, \IteratorAggregate
{
    public function __construct($values)
    {
        parent::__construct(new Set($values));
    }

    public function getSum(): int
    {
        $result = 0;

        foreach ($this as $value) {
            $result += $value;
        }

        return $result;
    }
}

$set = new SetWithSum([ 42, 42, 7]);

echo "Count: " . count($set) . "\n";

echo "Sum: " . $set->getSum() . "\n";

This will output:

Count: 2
Sum: 49

Overview

The trait DecoratorTrait implements the Decorator pattern for an arbitrary object. The class Decorator uses this trait.

As in the example above, this can be used to create a class that adds functionality to a class when creating a derived class is not possible.

All functionality of the enclosed object is exposed by the decorator so that the decorator behaves just as the enclosed object, supporting, for instance, the Countable, Iterator or ArrayAccess interface.

The trait MultiDecoratedTrait offers a means to add multiple decorators to an object, indexed by their class nane. MultiDecoratedArrayAccessTrait is buil on top of this and allows to access the decorators via ArrayAccess methods.

See the doxygen documentation for details.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2025-10-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固