maximaster / alterator
替代迭代器。
v1.0.0
2024-08-23 12:28 UTC
Requires
- php: ^7.4
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.62
- kahlan/kahlan: ^5.1
- vimeo/psalm: ^5.25
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