maximaster/alterator

替代迭代器。

v1.0.0 2024-08-23 12:28 UTC

This package is auto-updated.

Last update: 2024-09-23 12:38:57 UTC


README

替代迭代器。

composer require maximaster/alterator

示例

想象你有一个名为 "Document (5)" 的对象,用户决定复制它。你需要为这个副本生成一个新的名称。

以下是使用此库执行此操作的示例

// create the library classes manually or get them from your DI container.
$unusedSeeker = new AlteratorUnsusedSeeker(new PostfixIndexAlterator());

$copyName = $unusedSeeker->suggest(
    // Old name.
    'Document (5)',
    // Your strategy to ensure that the suggested name is not already used.
    static fn (string $alternativeName): bool => $database->exists('
        SELECT 1 FROM documents WHERE NAME = ?
    ', [$alternativeName])
);

// This would be "Document (6)" unless your strategy found it already used.
return $copyName;

spec 文件夹中查看其他示例。

开发

devbox run lint
devbox run test