Download the PHP package kariricode/transformer without Composer
On this page you can find all versions of the php package kariricode/transformer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kariricode/transformer
More information about kariricode/transformer
Files in kariricode/transformer
Package transformer
Short Description A powerful and flexible data transformation component for PHP, part of the KaririCode Framework. It provides configurable processors for seamless manipulation and formatting of data attributes, offering a streamlined pipeline system for efficient data handling
License MIT
Homepage https://kariricode.org
Informations about the package transformer
KaririCode Framework: Transformer Component
A powerful and flexible data transformation component for PHP, part of the KaririCode Framework. It uses attribute-based transformation with configurable processors to ensure consistent data transformation and formatting in your applications.
Table of Contents
- Features
- Installation
- Usage
- Basic Usage
- Advanced Usage: Data Formatting
- Available Transformers
- String Transformers
- Data Transformers
- Array Transformers
- Composite Transformers
- Configuration
- Integration with Other KaririCode Components
- Development and Testing
- Contributing
- License
- Support and Community
Features
- Attribute-based transformation for object properties
- Comprehensive set of built-in transformers for common use cases
- Easy integration with other KaririCode components
- Configurable processors for customized transformation logic
- Extensible architecture allowing custom transformers
- Robust error handling and reporting
- Chainable transformation pipelines for complex data transformation
- Built-in support for multiple transformation scenarios
- Type-safe transformation with PHP 8.3 features
- Preservation of original data types
- Flexible formatting options for various data types
Installation
You can install the Transformer component via Composer:
Requirements
- PHP 8.3 or higher
- Composer
- Extensions:
ext-mbstring
,ext-json
Usage
Basic Usage
-
Define your data class with transformation attributes:
- Set up the transformer and use it:
Advanced Usage: Data Formatting
Here's an example of how to use the KaririCode Transformer in a real-world scenario, demonstrating various transformation capabilities:
Available Transformers
String Transformers
-
CaseTransformer: Transforms string case (camel, snake, pascal, kebab).
- Configuration Options:
case
: Target case format (lower, upper, title, sentence, camel, pascal, snake, kebab)preserveNumbers
: Whether to preserve numbers in transformation
-
MaskTransformer: Applies masks to strings (phone, CPF, CNPJ, etc.).
- Configuration Options:
mask
: Custom mask patterntype
: Predefined mask typeplaceholder
: Mask placeholder character
-
SlugTransformer: Generates URL-friendly slugs.
- Configuration Options:
separator
: Separator characterlowercase
: Convert to lowercasereplacements
: Custom character replacements
- TemplateTransformer: Processes templates with variable substitution.
- Configuration Options:
template
: Template stringremoveUnmatchedTags
: Remove unmatched placeholderspreserveData
: Keep original data in result
Data Transformers
-
DateTransformer: Converts between date formats.
- Configuration Options:
inputFormat
: Input date formatoutputFormat
: Output date formatinputTimezone
: Input timezoneoutputTimezone
: Output timezone
-
NumberTransformer: Formats numbers with locale-specific settings.
- Configuration Options:
decimals
: Number of decimal placesdecimalPoint
: Decimal separatorthousandsSeparator
: Thousands separatorroundUp
: Round up decimals
- JsonTransformer: Handles JSON encoding/decoding.
- Configuration Options:
encodeOptions
: JSON encoding optionspreserveType
: Keep original data typeassoc
: Use associative arrays
Array Transformers
-
ArrayFlattenTransformer: Flattens nested arrays.
- Configuration Options:
depth
: Maximum depth to flattenseparator
: Key separator for flattened structure
-
ArrayGroupTransformer: Groups array elements by key.
- Configuration Options:
groupBy
: Key to group bypreserveKeys
: Maintain original keys
-
ArrayKeyTransformer: Transforms array keys.
- Configuration Options:
case
: Target case for keysrecursive
: Apply to nested arrays
- ArrayMapTransformer: Maps array keys to new structure.
- Configuration Options:
mapping
: Key mapping configurationremoveUnmapped
: Remove unmapped keysrecursive
: Apply to nested arrays
Composite Transformers
-
ChainTransformer: Executes multiple transformers in sequence.
- Configuration Options:
transformers
: Array of transformers to executestopOnError
: Stop chain on first error
- ConditionalTransformer: Applies transformations based on conditions.
- Configuration Options:
condition
: Condition callbacktransformer
: Transformer to applydefaultValue
: Value when condition fails
Configuration
Transformers can be configured globally or per-instance. Example of configuring the NumberTransformer:
Integration with Other KaririCode Components
The Transformer component integrates with:
- KaririCode\Contract: Provides interfaces for component integration
- KaririCode\ProcessorPipeline: Used for transformation pipelines
- KaririCode\PropertyInspector: Processes transformation attributes
Registry Example
Complete registry setup example:
Development and Testing
Similar development setup as the Validator component, using Docker and Make commands.
Available Make Commands
make up
: Start servicesmake down
: Stop servicesmake test
: Run testsmake coverage
: Generate coverage reportmake cs-fix
: Fix code stylemake quality
: Run quality checks
Contributing
Contributions are welcome! Please see our Contributing Guide.
License
MIT License - see LICENSE file.
Support and Community
- Documentation: https://kariricode.org/docs/transformer
- Issues: GitHub Issues
- Forum: KaririCode Club Community
- Stack Overflow: Tag with
kariricode-transformer
Built with ❤️ by the KaririCode team. Transforming data with elegance and precision.
All versions of transformer with dependencies
kariricode/contract Version ^2.7
kariricode/processor-pipeline Version ^1.1
kariricode/property-inspector Version ^1.0
kariricode/exception Version ^1.0