Download the PHP package tenqz/lingua without Composer
On this page you can find all versions of the php package tenqz/lingua. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package lingua
Short Description A comprehensive PHP library for advanced text processing using Chain of Responsibility pattern
License MIT
Homepage https://github.com/tenqz/lingua
Informations about the package lingua
Lingua v2.1.1
Lingua is a comprehensive PHP library designed for advanced text processing. It implements the Chain of Responsibility pattern to provide flexible and extensible text processing capabilities.
Note: This library is currently under active development. The current version may not reflect the final quality and API stability. Breaking changes may occur in future releases.
Features
- Chain of Responsibility pattern for text processing
- Flexible scenario-based processing
- Easy to extend with custom handlers
- PHP 8.1+ support
Available Handlers
The library provides several built-in text processing handlers:
SpecialCharsHandler
Removes special characters from text while preserving words and spaces. This handler:
- Removes all special characters (punctuation marks, symbols, etc.)
- Replaces newlines with spaces
- Preserves spaces between words
Example:
NormalizeSpacesHandler
Normalizes whitespace in text. This handler:
- Replaces multiple spaces, tabs, and newlines with a single space
- Preserves leading and trailing whitespace
Example:
TrimHandler
Removes whitespace from the beginning and end of text. This handler:
- Removes spaces, tabs, and newlines from the beginning and end of text
- Preserves whitespace between words
Example:
HtmlTagsHandler
Removes HTML tags from text while preserving the content between them. This handler:
- Removes all HTML tags using PHP's
strip_tags
function - Preserves HTML entities
- Normalizes multiple spaces into single spaces
- Trims spaces from the beginning and end of text
Example:
Installation
Basic Usage
Chain of Handlers Example
You can combine multiple handlers to create a processing pipeline:
Architecture
The library consists of the following main components:
TextHandlerInterface
Interface that defines the contract for all text processing handlers:
AbstractTextHandler
Abstract base class that implements the Chain of Responsibility pattern:
TextProcessor
Facade class for managing text processing chains:
Creating Custom Handlers
To create a custom handler, extend the AbstractTextHandler
class and implement the process
method:
Error Handling
The library throws the following exceptions:
NotFoundHandlerException
: Thrown when attempting to process text with no registered handlers
Testing
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
License
This project is licensed under the MIT License