Download the PHP package ray/input-query without Composer
On this page you can find all versions of the php package ray/input-query. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package input-query
Ray.InputQuery
Convert HTTP query parameters into hierarchical PHP objects automatically.
Quick Example
Key Point: addressStreet
and addressCity
automatically compose the AddressInput
object.
Overview
Ray.InputQuery transforms flat HTTP data into structured PHP objects through explicit type declarations. Using the #[Input]
attribute, you declare which parameters come from query data, while other parameters are resolved via dependency injection.
Core Features:
- Automatic Nesting - Prefix-based parameters create hierarchical objects
- Type Safety - Leverages PHP's type system for automatic conversion
- DI Integration - Mix query parameters with dependency injection
- Validation - Type constraints ensure data integrity
Installation
Optional: File Upload Support
For file upload functionality, also install:
Documentation
Comprehensive documentation including design philosophy, AI prompts for development assistance, and sample data examples can be found in the docs/ directory.
Framework Integration
For framework-specific integration examples, see the Framework Integration Guide which covers:
- Laravel, Symfony, CakePHP, Yii Framework 1.x, BEAR.Sunday, and Slim Framework
- Three usage patterns (Reflection, Direct Object Creation, Spread Operator)
- Testing examples and best practices
Usage
Ray.InputQuery converts flat query data into typed PHP objects automatically.
Basic Usage
Define your input class with the #[Input]
attribute on parameters that come from query data:
Create input objects from query data:
Nested Objects
Ray.InputQuery automatically creates nested objects from flat query data:
Array Support
Ray.InputQuery supports arrays and ArrayObject collections with the item
parameter:
Query data format for arrays
Arrays should be submitted as indexed arrays. Here's how to structure HTML forms and the resulting data:
This will be received as:
Simple array values (e.g., checkboxes)
For simple arrays like checkboxes or multi-select:
This will be received as:
Note: For non-array parameters, use flat naming without brackets:
ArrayObject Inheritance Support
Custom ArrayObject subclasses are also supported:
Mixed with Dependency Injection
Parameters without the #[Input]
attribute are resolved via dependency injection:
Key Normalization
All query keys are normalized to camelCase:
user_name
→userName
user-name
→userName
UserName
→userName
File Upload Integration
Ray.InputQuery provides comprehensive file upload support through integration with Koriym.FileUpload:
When using file upload features, instantiate InputQuery with FileUploadFactory:
Using #[InputFile] Attribute
For file uploads, use the dedicated #[InputFile]
attribute which provides validation options:
// Method usage example - Direct attribute approach
Test-Friendly Design
File upload handling is designed to be test-friendly:
- Production - FileUpload library handles file uploads automatically
- Testing - Direct FileUpload object injection for easy mocking
Multiple File Uploads
Support for multiple file uploads using array types with validation:
Converting Objects to Arrays
Ray.InputQuery provides the ToArray
functionality to convert objects with #[Input]
parameters into flat associative arrays, primarily for SQL parameter binding with libraries like Aura.Sql:
Basic ToArray Usage
SQL Param¥¥eter Binding
The flattened arrays work seamlessly with Aura.Sql and other SQL libraries:
Property Name Conflicts
When flattened properties have the same name, later values overwrite earlier ones:
Key Features
- Recursive Flattening: Nested objects with
#[Input]
parameters are automatically flattened - Array Preservation: Arrays remain intact for SQL IN clauses (Aura.Sql compatible)
- Property Conflicts: Later properties overwrite earlier ones
- Public Properties Only: Private/protected properties are ignored
- Type Safety: Maintains type information through transformation
Complex Example
Demo
Web Demo
To see file upload integration in action:
Then visit http://localhost:8080 in your browser.
Console Demos
Run various examples from the command line: