Download the PHP package rkt/magento-data without Composer
On this page you can find all versions of the php package rkt/magento-data. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rkt/magento-data
More information about rkt/magento-data
Files in rkt/magento-data
Package magento-data
Short Description Data Object & Data Transfer Objects for Magento 2
License BSD-3-Clause
Informations about the package magento-data
Rkt_MageData
A powerful, lightweight Data Object & DTO (Data Transfer Object) system for Magento 2 β supporting smart instantiation, validation, and serialization.
π Installation
β¨ Features Overview
1. β Easy Data Object Instantiation
Use the static from() or create() methods to easily instantiate data objects.
Example
You can instantiate it like this:
Or using create():
2. π‘ Validation Built In
This module includes built-in validation using somnambulist/validation.
πΉ Basic Validation
Just define a rules() method in your data object:
You can validate array elements (like
street.0) using dot notation.
πΉ Custom Validation Messages
Override messages():
πΉ Custom Field Aliases
Override aliases():
In error messages, email will now appear as "Email Address".
3. π§© Nested Object Validation
Nested and recursive validation works out of the box:
β In this setup:
fatherandmotherare required and must passPersonvalidation.childrencan be a list ofPerson, and theyβll be validated too (if provided).
4. πΉ Custom Validation Rules via customRules()
You can define reusable or inline validation rules using customRules(). The package supports closure and class-based custom rules, and can also provide built-in reusable rules.
β 1. Closure-Based Rules
Use closures for simple, inline validation logic.
βΉοΈ The closure is automatically registered using the
callbackrule provided bysomnambulist/validation.
β 2. Custom Rule Class
For more reusable or complex logic, use a rule class. The given rule must be in compliance with somnambulist/validation.
Basically the rule class must extend Somnambulist\Components\Validation\Rule.
β You can also return an instantiated object if needed β it will be registered directly.
πΉ Built-in Custom Rules
Rkt_MageData also contains reusable custom rules that you can register in customRules().
Current built-in rules:
form_keyβRkt\MageData\Model\Validation\Rule\FormKeyRule
Example:
If you think that any other custom rules should be part of the package, then feel free to create an issue for it.
5. π§΅ Event-Driven Rule Customization
You can dynamically modify validation rules/messages/aliases using Magento events.
πΉ Example
πΈ Event Name
When validate() is called, the event rkt_example_data_mydata_validate_before is dispatched.
πΉ Observer Configuration (events.xml)
πΉ Sample Observer
β
Now your validation dynamically adds the email rule and alias based on observer logic.
6. π Serialization Support
Convert data objects to array or JSON easily:
7. Fetch validations rules applicable to the data
You can get the validation rules applicable for a payload like this.
Now if you call
Will provide you below result:
π Notes
- This module is under active development β more features and integrations are coming soon!
- Built for flexibility, testability, and ease of use in Magento 2 backend and frontend service layers.
π¬ Stay Connected
Got feedback or feature requests? PRs and ideas are welcome!