create-iterator

为 PHP 8.4 生成迭代器模式实现。目的是在不暴露底层表示的情况下,提供对聚合元素的顺序访问,包含迭代器接口和可迭代集合的代码实现,并附带单元测试。

仓库最近推送
GitHub Stars
109
Forks
26
Issues / PRs
1

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "create-iterator":https://skillpi.com/zh/skills/deepskill-b709c1e857257ba6de3d3b181e6c52383923750702b87f023a77d178a260028b。安装前核对上游来源和版本:https://github.com/dykyi-roman/awesome-claude-code。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

为 PHP 8.4 生成迭代器模式实现。目的是在不暴露底层表示的情况下,提供对聚合元素的顺序访问,包含迭代器接口和可迭代集合的代码实现,并附带单元测试。

0 下载

介绍来源: third_party · dykyi-roman · 0.0.1 参考来源

SkillPi 解读

能完成的任务
翻译待完成,请参阅来源文档。
适合谁
翻译待完成,请参阅来源文档。
实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: create-iterator
description: Generates Iterator pattern for PHP 8.4. Creates sequential access to aggregate elements without exposing underlying representation, with iterator interface and iterable collections. Includes unit tests.

Iterator Pattern Generator

Creates Iterator pattern infrastructure for sequential access to collection elements.

When to Use

Scenario Example
Traverse collections Order items, user lists, product catalog
Multiple traversal algorithms Forward, backward, filtered iteration
Unified collection interface Standardize iteration across different types
Hide collection structure Encapsulate internal representation

Component Characteristics

Iterator Interface

  • Extends \Iterator or \IteratorAggregate
  • Provides current(), next(), key(), valid()
  • Enables foreach compatibility
  • Type-safe element access

Concrete Iterator

  • Implements traversal algorithm
  • Maintains iteration state
  • Provides filtering/transformation
  • Resets to beginning via rewind()

Iterable Collection

  • Implements \IteratorAggregate
  • Returns iterator via getIterator()
  • Encapsulates collection data
  • Supports type-safe operations

Generation Process

Step 1: Generate Iterator Interface (Optional)

Path: src/Domain/{BoundedContext}/Iterator/

  1. {Name}IteratorInterface.php — Custom iterator contract (extends \Iterator)

Step 2: Generate Concrete Iterator

Path: src/Domain/{BoundedContext}/Iterator/

  1. {Name}Iterator.php — Iterator implementation with traversal logic
  2. Filtered{Name}Iterator.php — Filtered variant (optional)

Step 3: Generate Iterable Collection

Path: src/Domain/{BoundedContext}/Collection/

  1. {Name}Collection.php — Collection implementing \IteratorAggregate

Step 4: Generate Value Objects (Optional)

Path: src/Domain/{BoundedContext}/ValueObject/

  1. {Element}.php — Collection element type

Step 5: Generate Tests

  1. {Name}IteratorTest.php — Iterator behavior tests
  2. {Name}CollectionTest.php — Collection tests

File Placement

Component Path
Iterator Interface src/Domain/{BoundedContext}/Iterator/
Concrete Iterator src/Domain/{BoundedContext}/Iterator/
Collection src/Domain/{BoundedContext}/Collection/
Value Objects src/Domain/{BoundedContext}/ValueObject/
Unit Tests tests/Unit/Domain/{BoundedContext}/

Naming Conventions

Component Pattern Example
Iterator Interface {Name}IteratorInterface OrderIteratorInterface
Concrete Iterator {Name}Iterator OrderIterator
Filtered Iterator Filtered{Name}Iterator FilteredUserIterator
Collection {Name}Collection OrderCollection
Test {ClassName}Test OrderIteratorTest

Quick Template Reference

Iterator (using \Iterator)

final class {Name}Iterator implements \Iterator
{
    private int $position = 0;

    public function __construct(
        private readonly array $items
    ) {}

    public function current(): {ElementType}
    {
        return $this->items[$this->position];
    }

    public function next(): void
    {
        ++$this->position;
    }

    public function key(): int
    {
        return $this->position;
    }

    public function valid(): bool
    {
        return isset($this->items[$this->position]);
    }

    public function rewind(): void
    {
        $this->position = 0;
    }
}

Iterable Collection (using \IteratorAggregate)

final readonly class {Name}Collection implements \IteratorAggregate, \Countable
{
    /**
     * @param array<{ElementType}> $items
     */
    public function __construct(
        private array $items = []
    ) {}

    public function getIterator(): \Traversable
    {
        return new {Name}Iterator($this->items);
    }

    public function count(): int
    {
        return count($this->items);
    }
}

Usage Example

// Create collection
$orders = new OrderCollection([
    new Order(id: '1', total: 100),
    new Order(id: '2', total: 200),
    new Order(id: '3', total: 50),
]);

// Iterate with foreach
foreach ($orders as $order) {
    echo $order->total();
}

// Filtered iteration
$filtered = new FilteredOrderIterator(
    orders: $orders,
    filter: fn(Order $o) => $o->total() > 100
);

foreach ($filtered as $order) {
    // Only orders with total > 100
}

Common Iterator Patterns

Domain Iterators
Collections OrderCollection, UserCollection, ProductCollection
Filtering ActiveUserIterator, PendingOrderIterator
Pagination PaginatedResultIterator, PageIterator
Tree Structures DepthFirstIterator, BreadthFirstIterator
Composite RecursiveIterator, FlatteningIterator

Anti-patterns to Avoid

Anti-pattern Problem Solution
Mutable iterator state leak External modification Use readonly collections
Breaking foreach contract Invalid implementation Implement all \Iterator methods
Expensive current() Performance issues Cache current element
Missing rewind() Can't iterate twice Implement proper rewind()
Violating LSP Inconsistent behavior Follow SPL iterator contracts

References

For complete PHP templates and examples, see:

  • references/templates.md — Iterator, IteratorAggregate, Filtered Iterator templates
  • references/examples.md — OrderCollection, UserIterator, Pagination with tests

当前收录版本

0.0.1

核对来源版本 ↗

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值85/100

亮点

  • 提供 PHP 8.4 迭代器模式的完整生成方案,覆盖接口、实现、集合、测试等全流程
  • 适用于广泛的 PHP 开发场景,能显著提升开发效率和代码规范性
触发精准90/100

亮点

  • description 明确描述了核心功能(为 PHP 8.4 生成迭代器模式)
  • 包含关键触发词如 Iterator pattern、sequential access、unit tests,边界清晰
结构规范95/100

亮点

  • 文档结构完整,包含使用场景、组件特性、生成步骤、文件位置、命名规范、模板参考、示例、常见模式和反模式
  • 分步骤清晰,有端到端示例,frontmatter 完整,符合规范
执行可靠90/100

亮点

  • 提供了完整的代码模板和使用示例,组件职责明确
  • 遵循 PHP SPL 标准,无明显执行漏洞,可靠性高
证据可验 (前四项均值)90/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。