maximaster / alterator
Alternatives iterator.
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-10-23 12:46:10 UTC
README
Alternatives iterator.
composer require maximaster/alterator
Example
Imagine you have an object with the name "Document (5)" and a user decides to copy it. You need to generate a new name for this copy.
Here's how you can do it using the library:
// 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;
See other examples in spec folder.
Development
devbox run lint
devbox run test