Skip to content

Commit 3117b3c

Browse files
authored
Add documentation publishing script and fix null value handling (#30)
* Fix null value handling in `DataModelHelper.php` * Add documentation publishing script and related composer configuration
1 parent 691d8d9 commit 3117b3c

File tree

4 files changed

+125
-55
lines changed

4 files changed

+125
-55
lines changed

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
- [Introduction](#introduction)
1818
- [Requirements](#requirements)
1919
- [Installation](#installation)
20+
- [Documentation Publishing](#documentation-publishing)
21+
- [Automatic Documentation Publishing](#automatic-documentation-publishing)
2022
- [Usage](#usage)
2123
- [Including the Trait](#including-the-trait)
2224
- [Helper Methods](#helper-methods)
@@ -49,6 +51,39 @@ composer require zero-to-prod/data-model-helper
4951

5052
This will add the package to your project’s dependencies and create an autoloader entry for it.
5153

54+
## Documentation Publishing
55+
56+
You can publish this README to your local documentation directory.
57+
58+
This can be useful for providing documentation for AI agents.
59+
60+
This can be done using the included script:
61+
62+
```bash
63+
# Publish to default location (./docs/zero-to-prod/data-model-helper)
64+
vendor/bin/zero-to-prod-data-model-helper
65+
66+
# Publish to custom directory
67+
vendor/bin/zero-to-prod-data-model-helper /path/to/your/docs
68+
```
69+
70+
#### Automatic Documentation Publishing
71+
72+
You can automatically publish documentation by adding the following to your `composer.json`:
73+
74+
```json
75+
{
76+
"scripts": {
77+
"post-install-cmd": [
78+
"zero-to-prod-data-model-helper"
79+
],
80+
"post-update-cmd": [
81+
"zero-to-prod-data-model-helper"
82+
]
83+
}
84+
}
85+
```
86+
5287
## Usage
5388

5489
### Including the Trait
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
/**
5+
* Zero-to-Prod Factory Documentation Publisher
6+
*
7+
* Publishes the README.md file to the user's documentation directory.
8+
*/
9+
10+
require getcwd().'/vendor/autoload.php';
11+
12+
use Zerotoprod\PackageHelper\PackageHelper;
13+
14+
$target_path = getcwd().'/docs/zero-to-prod/data-model-helper/';
15+
if (isset($argv[1])) {
16+
$target_path = rtrim($argv[1], '/').'/';
17+
}
18+
19+
$source_file = __DIR__.'/../README.md';
20+
21+
if (!file_exists($source_file)) {
22+
fwrite(STDERR, "Error: Not found $source_file\n");
23+
exit(1);
24+
}
25+
26+
try {
27+
PackageHelper::copy($source_file, $target_path);
28+
exit(0);
29+
} catch (RuntimeException $e) {
30+
fwrite(STDERR, "Error: ".$e->getMessage()."\n");
31+
exit(1);
32+
}

composer.json

Lines changed: 57 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,60 @@
11
{
2-
"type": "library",
3-
"name": "zero-to-prod/data-model-helper",
4-
"description": "Helpers for a DataModel.",
5-
"keywords": [
6-
"zero-to-prod",
7-
"data-model-helper"
8-
],
9-
"homepage": "https://github.com/zero-to-prod/data-model-helper",
10-
"support": {
11-
"email": "dave0016@gmail.com",
12-
"issues": "https://github.com/zero-to-prod/data-model-helper/issues",
13-
"source": "https://github.com/zero-to-prod/data-model-helper",
14-
"docs": "https://zero-to-prod.github.io/data-model-helper",
15-
"security": "https://github.com/zero-to-prod/data-model-helper/blob/main/SECURITY.md"
16-
},
17-
"license": "MIT",
18-
"readme": "./README.md",
19-
"authors": [
20-
{
21-
"name": "David Smith",
22-
"email": "dave0016@gmail.com",
23-
"homepage": "https://davidsmith.blog/",
24-
"role": "maintainer"
2+
"type": "library",
3+
"name": "zero-to-prod/data-model-helper",
4+
"description": "Helpers for a DataModel.",
5+
"keywords": [
6+
"zero-to-prod",
7+
"data-model-helper"
8+
],
9+
"homepage": "https://github.com/zero-to-prod/data-model-helper",
10+
"support": {
11+
"email": "dave0016@gmail.com",
12+
"issues": "https://github.com/zero-to-prod/data-model-helper/issues",
13+
"source": "https://github.com/zero-to-prod/data-model-helper",
14+
"docs": "https://zero-to-prod.github.io/data-model-helper",
15+
"security": "https://github.com/zero-to-prod/data-model-helper/blob/main/SECURITY.md"
16+
},
17+
"license": "MIT",
18+
"readme": "./README.md",
19+
"authors": [
20+
{
21+
"name": "David Smith",
22+
"email": "dave0016@gmail.com",
23+
"homepage": "https://davidsmith.blog/",
24+
"role": "maintainer"
25+
}
26+
],
27+
"funding": [
28+
{
29+
"type": "GitHub",
30+
"url": "https://github.com/sponsors/zero-to-prod"
31+
}
32+
],
33+
"require": {
34+
"php": ">=8.1.0",
35+
"zero-to-prod/data-model": "^v81.0.0",
36+
"zero-to-prod/validate-url": "^71.0",
37+
"zero-to-prod/validate-email": "^71.0",
38+
"zero-to-prod/package-helper": "^1.1.3"
39+
},
40+
"autoload": {
41+
"psr-4": {
42+
"Zerotoprod\\DataModelHelper\\": "src/"
43+
}
44+
},
45+
"autoload-dev": {
46+
"psr-4": {
47+
"Tests\\": "tests/"
48+
}
49+
},
50+
"require-dev": {
51+
"phpunit/phpunit": "<12.0"
52+
},
53+
"bin": [
54+
"bin/zero-to-prod-data-model-factory"
55+
],
56+
"suggest": {
57+
"zero-to-prod/transformable": "Transform a class into different types.",
58+
"zero-to-prod/data-model-factory": "Factories for a DataModel."
2559
}
26-
],
27-
"funding": [
28-
{
29-
"type": "GitHub",
30-
"url": "https://github.com/sponsors/zero-to-prod"
31-
}
32-
],
33-
"require": {
34-
"php": ">=8.1.0",
35-
"zero-to-prod/data-model": "^v81.0.0",
36-
"zero-to-prod/validate-url": "^71.0",
37-
"zero-to-prod/validate-email": "^71.0",
38-
"zero-to-prod/package-helper": "^1.1.3"
39-
},
40-
"autoload": {
41-
"psr-4": {
42-
"Zerotoprod\\DataModelHelper\\": "src/"
43-
}
44-
},
45-
"autoload-dev": {
46-
"psr-4": {
47-
"Tests\\": "tests/"
48-
}
49-
},
50-
"require-dev": {
51-
"phpunit/phpunit": "<12.0"
52-
},
53-
"suggest": {
54-
"zero-to-prod/transformable": "Transform a class into different types.",
55-
"zero-to-prod/data-model-factory": "Factories for a DataModel."
56-
}
5760
}

src/DataModelHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public static function mapOf(mixed $value, array $context, ?ReflectionAttribute
9696
);
9797
};
9898

99-
return $mapper($value, $args['level'] ?? 1);
99+
return $mapper($value ?? [], $args['level'] ?? 1);
100100
}
101101

102102
/**

0 commit comments

Comments
 (0)