11# Zerotoprod\DataModelHelper
22
3- ![ ] ( . /logo.png)
3+ ![ ] ( art /logo.png)
44
55[ ![ Repo] ( https://img.shields.io/badge/github-gray?logo=github )] ( https://github.com/zero-to-prod/data-model-helper )
66[ ![ GitHub Actions Workflow Status] ( https://img.shields.io/github/actions/workflow/status/zero-to-prod/data-model-helper/test.yml?label=tests )] ( https://github.com/zero-to-prod/data-model-helper/actions )
1111[ ![ wakatime] ( https://wakatime.com/badge/github/zero-to-prod/data-model-helper.svg )] ( https://wakatime.com/badge/github/zero-to-prod/data-model-helper )
1212[ ![ Hits-of-Code] ( https://hitsofcode.com/github/zero-to-prod/data-model-helper?branch=main )] ( https://hitsofcode.com/github/zero-to-prod/data-model-helper/view?branch=main )
1313
14+ ## Contents
15+
16+ - [ Introduction] ( #introduction )
17+ - [ Requirements] ( #requirements )
18+ - [ Installation] ( #installation )
19+ - [ Usage] ( #usage )
20+ - [ Including the Trait] ( #including-the-trait )
21+ - [ Helper Methods] ( #helper-methods )
22+ - [ when] ( #when ) : Create a map of any type by using
23+ - [ mapOf] ( #mapof ) : Create a map of any type by using
24+ - [ pregReplace] ( #pregreplace ) : Perform a regular expression search and replace.
25+ - [ pregMatch] ( #pregmatch ) : Perform a regular expression match.
26+ - [ isUrl] ( #isurl ) : Validates a url.
27+ - [ isEmail] ( #isemail ) : Validates an email.
28+ - [ isMultiple] ( #ismultiple ) : Validate a value is a multiple of another.
29+ - [ Local Development] ( #local-development )
30+ - [ Prerequisites] ( #prerequisites )
31+ - [ Initializing] ( #initializing )
32+ - [ Testing] ( #testing )
33+ - [ Configuration] ( #configuration )
34+ - [ Contributing] ( #contributing )
35+
36+ ## Introduction
37+
1438Utilities for casting values using the [ DataModel] ( https://github.com/zero-to-prod/data-model ) package.
1539
40+ ## Requirements
41+
42+ - PHP 8.1 or higher.
43+ - The [ DataModel] ( https://github.com/zero-to-prod/data-model ) Composer package
44+
1645## Installation
1746
18- Install the package via Composer:
47+ Install ` Zerotoprod\DataModelHelper ` via [ Composer] ( https://getcomposer.org/ ) :
1948
2049``` bash
2150composer require zero-to-prod/data-model-helper
2251```
2352
53+ This will add the package to your project’s dependencies and create an autoloader entry for it.
54+
2455## Usage
2556
2657### Including the Trait
@@ -36,14 +67,6 @@ class DataModelHelper
3667
3768## Helper Methods
3869
39- - [ when] ( #when ) : Create a map of any type by using
40- - [ mapOf] ( #mapof ) : Create a map of any type by using
41- - [ pregReplace] ( #pregreplace ) : Perform a regular expression search and replace.
42- - [ pregMatch] ( #pregmatch ) : Perform a regular expression match.
43- - [ isUrl] ( #isurl ) : Validates a url.
44- - [ isEmail] ( #isemail ) : Validates an email.
45- - [ isMultiple] ( #ismultiple ) : Validate a value is a multiple of another.
46-
4770### ` when `
4871
4972Use ` when ` to call a function based on a condition.
@@ -364,11 +387,13 @@ echo $User->Aliases[0][1]->name; // Outputs: John Smith
364387```
365388
366389#### KeyBy
390+
367391Key an array by an element value by using the ` key_by ` argument.
368392
369393This also supports deep mapping.
370394
371395Note: this only applies to arrays.
396+
372397``` php
373398class User
374399{
@@ -411,9 +436,11 @@ echo $User->Aliases['js1']->name); // 'John Smith'
411436```
412437
413438#### Map
439+
414440Call a function for that value.
415441
416442Note: This does not work with arrays.
443+
417444``` php
418445class User
419446{
@@ -571,4 +598,66 @@ class User
571598 ])]
572599 public string $url;
573600}
574- ```
601+ ```
602+
603+ ## Local Development
604+
605+ This project provides a convenient [ dock] ( https://github.com/zero-to-prod/dock ) script to simplify local development workflows within Docker
606+ containers.
607+
608+ You can use this script to initialize the project, manage Composer dependencies, and run tests in a consistent PHP environment.
609+
610+ ### Prerequisites
611+
612+ - Docker installed and running
613+ - A ` .env ` file (created automatically via the ` dock init ` z command, if it doesn’t already exist)
614+
615+ ### Initializing
616+
617+ Use the following commands to set up the project:
618+
619+ ``` shell
620+ sh dock init
621+ sh dock composer update
622+ ```
623+
624+ ### Testing
625+
626+ This command runs PHPUnit inside the Docker container, using the PHP version specified in your ` .env ` file.
627+ You can modify or extend this script to include additional tests or commands as needed.
628+
629+ ``` shell
630+ sh dock test
631+ ```
632+
633+ Run the test suite with all versions of php:
634+
635+ ``` shell
636+ sh test.sh
637+ ```
638+
639+ ### Configuration
640+
641+ Before starting development, verify that your ` .env ` file contains the correct settings.
642+
643+ You can specify which PHP version to use for local development, debugging, and Composer operations by updating these variables in your ` .env ` file:
644+
645+ ``` dotenv
646+ PHP_VERSION=8.1
647+ PHP_DEBUG=8.1
648+ PHP_COMPOSER=8.1
649+ ```
650+
651+ Make sure these values reflect the PHP versions you intend to use.
652+ If the ` .env ` file does not exist, run the ` sh dock init ` command to create one from the ` .env.example ` template.
653+
654+ ## Contributing
655+
656+ Contributions, issues, and feature requests are welcome!
657+ Feel free to check the [ issues] ( https://github.com/zero-to-prod/data-model-helper/issues ) page if you want to contribute.
658+
659+ 1 . Fork the repository.
660+ 2 . Create a new branch (` git checkout -b feature-branch ` ).
661+ 3 . Commit changes (` git commit -m 'Add some feature' ` ).
662+ 4 . Push to the branch (` git push origin feature-branch ` ).
663+ 5 . Create a new Pull Request.
0 commit comments