Download the PHP package concept-labs/expression without Composer
On this page you can find all versions of the php package concept-labs/expression. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download concept-labs/expression
More information about concept-labs/expression
Files in concept-labs/expression
Package expression
Short Description (C)oncept-Labs Expression
License Apache-2.0
Informations about the package expression
Expression
A flexible and powerful PHP library for building and composing expressions with decorators. Build SQL queries, HTML/XML, JSON/API responses, CLI commands, configuration files, code generators, and any text-based output with elegant, fluent syntax.
More than a query builder - Expression is a universal text composition framework that makes complex string building simple, maintainable, and beautiful.
Features
- ๐ง Fluent API - Chain methods for clean, readable code
- ๐จ Decorator Pattern - Transform expressions with decorators
- ๐๏ธ Composable - Nest expressions within expressions
- ๐ Immutable Context - Safe context interpolation
- ๐งฉ Extensible - Easy to extend with custom decorators
- โจ Type Safe - Full PHP 8.2+ type hints
- ๐งช Well Tested - Comprehensive test coverage with PHPUnit and Pest
- ๐ Universal - Build SQL, HTML, JSON, CLI commands, configs, and more
Why Expression?
Traditional string building is error-prone, hard to read, and difficult to maintain:
Expression makes it elegant, composable, and maintainable:
Installation
Install via Composer:
Quick Start
๐ Power Showcase
Syntax Sugar - The Magic of __invoke()
Expressions are callable, enabling ultra-concise syntax:
Decorator Stacking - Progressive Transformations
Chain decorators for powerful, layered transformations:
Beyond SQL - Universal Text Building
HTML Component Builder
CLI Command Builder
JSON API Response Builder
Configuration File Generator
Context Interpolation - Reusable Templates
Composition - Expressions Within Expressions
Basic Usage
Creating Expressions
Using __invoke() for Concise Syntax
Nested Expressions
Using Decorators
Wrap Expressions
Wrap Items
Custom Decorators
Context Interpolation
Clone and Prototype
Reset
Advanced Usage
Building Complex SQL Queries
Multiple Decorator Layers
API Reference
For detailed API documentation, see docs/api-reference.md.
Main Classes
- Expression - Main expression class
- ExpressionInterface - Interface for expressions
- DecoratorManager - Manages decorators for expressions
- Decorator - Static helper methods for common decorators
Key Methods
Expression Methods
__invoke(...$expressions)- Add expressions (alias for push, enables callable syntax)push(...$expressions)- Add expressions to the endunshift(...$expressions)- Add expressions to the beginningwrap($left, $right = null)- Wrap the entire expressionwrapItem($left, $right = null)- Wrap each itemjoin($separator)- Set the join separatordecorate(callable ...$decorator)- Add expression decoratordecorateItem(callable ...$decorator)- Add item decoratordecorateJoin(callable $decorator)- Set join decoratorwithContext(array $context)- Create new expression with contextreset()- Reset the expressiontype(string $type)- Set expression typeisEmpty()- Check if expression is emptyprototype()- Create a clone
More Examples
๐ Markdown Table Generator
๐จ ASCII Art Generator
๐ Log Formatter
๐ง Git Command Builder
๐ ENV File Builder
For more advanced examples including:
- ๐๏ธ HTML/XML Builders
- ๐ GraphQL Query Builders
- ๐ณ Docker Command Composers
- ๐ป PHP Code Generators
- ๐ YAML Configuration Builders
- ๐งช Test Data Builders
- ๐ฏ DSL Creation
- ๐จ Creative Use Cases
See the comprehensive Advanced Examples Guide!
Testing
The package includes comprehensive tests using both PHPUnit and Pest.
Contributing
Contributions are welcome! Please see docs/contributing.md for details.
License
This package is licensed under the Apache License 2.0. See LICENSE file for details.
Credits
- Viktor Halytskyi - Original author
- Part of the Concept Labs ecosystem
Links
- Extended Documentation
- Architecture Overview
- Examples
- ๐ Advanced Examples - NEW! Showcase of powerful use cases
- API Reference