dereuromark / cakephp-dto
CakePHP DTO Plugin
Installs: 62 886
Dependents: 3
Suggesters: 0
Security: 0
Stars: 24
Watchers: 5
Forks: 6
Open Issues: 5
Type:cakephp-plugin
Requires
- php: >=8.1
- ext-json: *
- cakephp/cakephp: ^5.0.3
- cakephp/twig-view: ^2.0.1
- sebastian/diff: ^5.0.0 || ^6.0.0
Requires (Dev)
- ext-dom: *
- ext-libxml: *
- fig-r/psr2r-sniffer: dev-master
- nette/neon: ^2.4 || ^3.2
- phpunit/phpunit: ^10.2
Suggests
- nette/neon: If you want to add a NEON file engine instead of XML.
This package is auto-updated.
Last update: 2024-11-18 13:42:14 UTC
README
A Data Transfer Object (DTO) is an object used to pass typed data between layers in your application, similar in concept to Structs in C, Martin Fowler's Transfer Objects, or Value Objects.
The goal of this package is to structure "unstructured data", replacing simple (associative) arrays with a more speaking solution.
- By making all fields typeable, we can be sure that their values are never something we didn't expect. Especially with modern PHP and more strict typehinting moving forward this is rather important to detect and fail early.
- We can have full IDE autocomplete and typehinting.
- We can use tools like PHPStan to statically analyze the code (more strictly).
- We can simplify the logic where required fields will now just throw a meaningful exception.
- We can work with different inflections of field names more easily.
- Easy way of immutable DTOs with required fields, to trust them in following code.
- Works out of the box with any value object that is serializable (either as array or string).
For more see Motivation and Background.
This plugin will provide you with a tool to quickly generate custom and optimized DTOs for your special use cases.
This branch is for use with CakePHP 5.0+. For details see version map.
Examples
Live examples in the Sandbox: Github Demo.
See Examples for basic, immutable and complex entity use cases. The generated demo DTOs of those are in tests/test_app/src/Dto/.
Note: Param/return types are enabled and strict types disabled by default.
Installation
You can install this plugin into your CakePHP application using Composer.
composer require dereuromark/cakephp-dto
Then load the plugin with the following command:
bin/cake plugin load CakeDto
Usage
See Docs for details.