PHP Library providing an easy way to spellcheck multiple sources of text by many spellcheckers
PHP Library providing an easy way to spellcheck multiple sources of text by many spellcheckers
PHP-Spellchecker
Check misspellings from any text source with the most popular PHP spellchecker.
PHP-Spellchecker is a spellchecker abstraction library for PHP. By providing a unified interface for many different spellcheckers, you’re able to swap out spellcheckers without extensive rewrites.
Using PHP-Spellchecker can eliminate vendor lock-in, reduce technical debt, and improve the testability of your code.
PHP-Spellchecker is a welcoming project for new contributors.
Want to make your first open source contribution? Check the roadmap, pick one task, open an issue and we'll help you go through it
Via Composer
composer require tigitz/php-spellcheckerCheck out the documentation and examples
You can check misspellings directly from a PhpSpellcheck\Spellchecker class and process them on your own.
check('mispell', ['en_US'], ['from_example']);
foreach ($misspellings as $misspelling) {
$misspelling->getWord(); // 'mispell'
$misspelling->getLineNumber(); // '1'
$misspelling->getOffset(); // '0'
$misspelling->getSuggestions(); // ['misspell', ...]
$misspelling->getContext(); // ['from_example']
}MisspellingFinder orchestratorYou can also use an opinionated MisspellingFinder class to orchestrate your spellchecking flow:
Following the well-known Unix philosophy:
Write programs that do one thing and do it well. Write programs to work together. Write programs to handle text streams, because that is a universal interface.
…The project is still in its initial phase, requiring more real-life usage to stabilize its final 1.0.0 API.
vendor/bin/php-spellchecker "misspell" Languagetools EchoHandler --lang=en_USLanguageTools).strtok instead of explode to parse lines of text, for performance.MutableMisspelling for performance comparison.Webmozart/Assert library exceptions to throw PHP-Spellchecker custom exceptions instead.Makefile.SourceInterface class that's able to have an effect on the used spellchecker configuration.League/Flysystem source.Symfony/Finder source.We follow SemVer v2.0.0.
There still are many design decisions that should be confronted with real-world usage before thinking about a v1.0.0 stable release:
TextInterface and MisspellingInterface really useful?Spell checkers come in many different forms, from HTTP API to command line tools. PHP-Spellchecker wants to ensure real-world usage is OK, so it contains integration tests. To run these, spellcheckers need to all be available during tests execution.
The most convenient way to do it is by using Docker and avoid polluting your local machine.
Requires docker and docker-compose to be installed (tested on Linux).
$ make build # build container images
$ make setup # start spellcheckers container
$ make tests-doxYou can also specify PHP version, dependency version target and if you want coverage.
$ PHP_VERSION=8.2 DEPS=LOWEST WITH_COVERAGE="true" make tests-doxRun make help to list all available tasks.
If spellcheckers execution paths are different than their default values (e.g., docker exec -ti myispell instead of ispell) you can override the path used in tests by redefining environment variables in the PHPUnit config file.
Please see CONTRIBUTING.
The MIT License (MIT). Please see license file for more information.
Logo: Elements taken for the final rendering are Designed by rawpixel.com / Freepik.
No open issues yet, or sync has not completed.