Skip to content

Commit fd0e520

Browse files
authored
Merge pull request #124 from Grazulex/transfert-to-wiki
πŸ“š Restructure documentation: Move to Wiki for better organization
2 parents 328d3ad + 3ca5b5d commit fd0e520

File tree

2 files changed

+40
-292
lines changed

2 files changed

+40
-292
lines changed

β€ŽREADME.mdβ€Ž

Lines changed: 39 additions & 292 deletions
Original file line numberDiff line numberDiff line change
@@ -12,345 +12,92 @@ Generate modern, type-safe Data Transfer Objects (DTOs) in Laravel from clean YA
1212
[![Tests](https://img.shields.io/github/actions/workflow/status/grazulex/laravel-arc/tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/Grazulex/laravel-arc/actions)
1313
[![Code Style](https://img.shields.io/badge/code%20style-pint-000000?style=flat-square&logo=laravel)](https://github.com/laravel/pint)
1414

15-
## πŸ“– Table of Contents
16-
17-
- [Overview](#overview)
18-
- [✨ Features](#-features)
19-
- [πŸ“¦ Installation](#-installation)
20-
- [πŸš€ Quick Start](#-quick-start)
21-
- [🎯 Traits System](#-traits-system)
22-
- [πŸ”„ Field Transformers](#-field-transformers)
23-
- [πŸ“Š Export Formats](#-export-formats)
24-
- [βš™οΈ Configuration](#️-configuration)
25-
- [πŸ“š Documentation](#-documentation)
26-
- [πŸ’‘ Examples](#-examples)
27-
- [πŸ§ͺ Testing](#-testing)
28-
- [πŸ”§ Requirements](#-requirements)
29-
- [πŸš€ Performance](#-performance)
30-
- [🀝 Contributing](#-contributing)
31-
- [πŸ”’ Security](#-security)
32-
- [πŸ“„ License](#-license)
33-
3415
## Overview
3516

3617
Laravel Arc is a powerful Laravel package that simplifies Data Transfer Object (DTO) management through YAML-driven generation. Define your DTOs in simple YAML files and let Laravel Arc generate type-safe, validated PHP classes with automatic property access and comprehensive collection support.
3718

3819
**Think of it as Laravel API Resources, but with stronger typing, automatic validation, and generated from YAML definitions.**
3920

40-
### 🎯 Use Cases
41-
42-
Laravel Arc is perfect for:
21+
### 🎯 Key Features
4322

44-
- **API Development** - Type-safe request/response handling
45-
- **Data Validation** - Consistent validation across your application
46-
- **Model Transformation** - Clean data layer separation
47-
- **Complex Forms** - Nested form validation and processing
48-
- **API Resources** - Alternative to Laravel Resources with stronger typing
23+
- **πŸ—οΈ YAML-Driven Generation** - Define DTOs in clean, readable YAML
24+
- **πŸ”’ Type Safety** - Full PHP 8.3+ type enforcement with readonly properties
25+
- **βœ… Automatic Validation** - Generate Laravel validation rules from field definitions
26+
- **πŸ”„ Field Transformers** - Built-in data transformation (trim, slugify, normalize, etc.)
27+
- **πŸ“Š Export Formats** - Convert to JSON, XML, CSV, YAML, and more
28+
- **🎯 Behavioral Traits** - Timestamps, UUIDs, soft deletes, and tagging
29+
- **πŸš€ Modern PHP** - Leverages PHP 8.3+ features and best practices
4930

50-
## ✨ Features
31+
### πŸ“š Complete Documentation
5132

52-
- πŸš€ **YAML-driven generation** - Define DTOs in simple, readable YAML files
53-
- πŸ” **Automatic validation** - Built-in Laravel validation rules support
54-
- πŸ—οΈ **Rich field types** - 14+ field types including enums, UUIDs, nested DTOs, and JSON
55-
- πŸ”— **Eloquent relationships** - Full support for Laravel relationship types
56-
- ⚑ **Direct property access** - Clean, modern syntax with PHP 8.3+ features
57-
- πŸ“¦ **Collection management** - Convert models to DTO collections like Laravel Resources
58-
- 🎯 **Powerful trait system** - Built-in behavioral traits for common functionality
59-
- πŸ”„ **Field transformers** - Automatically transform field values during DTO creation
60-
- πŸ“€ **Multiple export formats** - Export DTOs in 10 formats
61-
- πŸ› οΈ **Powerful CLI commands** - Generate, list, and manage DTOs from the command line
62-
- πŸ“ **Smart path resolution** - Automatic namespace-to-path conversion with custom organization
63-
- 🚨 **Enhanced error handling** - Detailed error messages with actionable suggestions
64-
- πŸ“¦ **Zero configuration** - Works out of the box with sensible defaults
65-
- πŸ§ͺ **Fully tested** - Comprehensive test suite with high coverage
33+
**➑️ [Visit the Wiki for complete documentation, examples, and guides](https://github.com/Grazulex/laravel-arc/wiki)**
6634

67-
## πŸ“¦ Installation
35+
The wiki contains:
36+
- **[Getting Started Guide](https://github.com/Grazulex/laravel-arc/wiki/Getting-Started)**
37+
- **[Field Types & Transformers](https://github.com/Grazulex/laravel-arc/wiki/Field-Types)**
38+
- **[Advanced Features](https://github.com/Grazulex/laravel-arc/wiki/Advanced-Features)**
39+
- **[API Reference](https://github.com/Grazulex/laravel-arc/wiki/API-Reference)**
40+
- **[Examples & Recipes](https://github.com/Grazulex/laravel-arc/wiki/Examples)**
6841

69-
Install the package via Composer:
42+
## πŸ“¦ Quick Installation
7043

7144
```bash
7245
composer require grazulex/laravel-arc
73-
```
74-
75-
> **πŸ’‘ Auto-Discovery**
76-
> The service provider will be automatically registered thanks to Laravel's package auto-discovery.
77-
78-
Publish configuration:
79-
80-
```bash
81-
php artisan vendor:publish --tag=arc-config
46+
php artisan vendor:publish --provider="Grazulex\LaravelArc\LaravelArcServiceProvider"
8247
```
8348

8449
## πŸš€ Quick Start
8550

86-
### 1. Create a DTO definition
87-
51+
1. **Create a DTO definition:**
8852
```bash
8953
php artisan dto:definition-init UserDTO --model=App\\Models\\User --table=users
9054
```
9155

92-
### 2. Define your DTO in YAML
93-
94-
```yaml
95-
# dto-definitions/UserDTO.yaml
96-
header:
97-
dto: UserDTO
98-
namespace: App\DTO
99-
model: App\Models\User
100-
traits:
101-
- HasTimestamps
102-
- HasUuid
103-
104-
fields:
105-
name:
106-
type: string
107-
validation: [required, string, max:255]
108-
transformers: [trim, title_case]
109-
110-
email:
111-
type: string
112-
validation: [required, email]
113-
transformers: [trim, lowercase]
114-
115-
status:
116-
type: string
117-
default: "active"
118-
validation: [required, in:active,inactive]
119-
```
120-
121-
### 3. Generate your DTO
122-
56+
2. **Generate the DTO class:**
12357
```bash
124-
php artisan dto:generate UserDTO.yaml
58+
php artisan dto:generate user.yaml
12559
```
12660

127-
### 4. Use your DTO
128-
61+
3. **Use your DTO:**
12962
```php
130-
// Convert a model to DTO
131-
$user = User::find(1);
132-
$userDto = UserDTO::fromModel($user);
133-
134-
// Convert a collection to DTO collection (like Laravel Resources)
135-
$users = User::all();
136-
$userDtos = UserDTO::collection($users); // Returns DtoCollection
137-
138-
// API Resource format
139-
return response()->json($userDtos->toArrayResource());
140-
// Output: {"data": [{"id": 1, "name": "John", "email": "[email protected]", "status": "active"}]}
141-
142-
// Export in multiple formats - 10 formats available
143-
$json = $userDto->toJson();
144-
$yaml = $userDto->toYaml();
145-
$csv = $userDto->toCsv();
146-
$xml = $userDto->toXml();
147-
148-
// Validation
149-
$userDto = UserDTO::fromArray($request->all());
150-
if (!$userDto->isValid()) {
151-
return response()->json(['errors' => $userDto->getErrors()], 422);
152-
}
153-
```
154-
155-
## 🎯 Traits System
156-
157-
Laravel Arc provides a powerful trait system with two types of traits:
63+
$userData = ['name' => 'John Doe', 'email' => '[email protected]'];
64+
$userDto = UserDTO::fromArray($userData);
15865

159-
### Functional Traits (Automatic)
160-
161-
Every DTO automatically includes these three powerful traits:
162-
163-
- **ValidatesData** - Provides validation methods (`validate()`, `passes()`, `fails()`)
164-
- **ConvertsData** - Provides conversion methods (`toJson()`, `toCsv()`, `toXml()`, etc.)
165-
- **DtoUtilities** - Provides utility methods (`getProperties()`, `with()`, `equals()`)
166-
167-
### Behavioral Traits (Optional) - 7 Available Traits
168-
169-
Add specific functionality by including traits in your YAML definition:
170-
171-
```yaml
172-
header:
173-
traits:
174-
- HasTimestamps # Adds created_at, updated_at fields and methods
175-
- HasUuid # Adds id field with UUID validation
176-
- HasSoftDeletes # Adds deleted_at field for soft deletes
177-
- HasVersioning # Adds version field and versioning methods
178-
- HasTagging # Adds tags field and tagging methods
179-
- HasAuditing # Adds audit trail fields and methods
180-
- HasCaching # Adds caching capabilities
181-
```
182-
183-
Example usage:
184-
185-
```php
186-
// Using functional traits (automatic)
187-
$userDto = UserDTO::fromArray($data);
188-
if (UserDTO::passes($data)) {
189-
$validated = UserDTO::validate($data);
190-
}
191-
192-
// Using behavioral traits (if included)
193-
$userDto = $userDto->addTag('premium')
194-
->nextVersion()
195-
->touch()
196-
->cache(3600);
197-
```
198-
199-
## πŸ”„ Field Transformers
200-
201-
Automatically transform field values during DTO creation:
202-
203-
```yaml
204-
fields:
205-
name:
206-
type: string
207-
transformers: [trim, title_case] # " john doe " β†’ "John Doe"
208-
209-
email:
210-
type: string
211-
transformers: [trim, lowercase] # " [email protected] " β†’ "[email protected]"
212-
213-
price:
214-
type: decimal
215-
transformers: [abs, clamp_min:0] # -19.99 β†’ 19.99
66+
echo $userDto->name; // 'John Doe'
67+
echo $userDto->toJson(); // JSON representation
21668
```
21769

218-
**Available transformers:**
219-
- **String transformers**: `trim`, `lowercase`, `uppercase`, `title_case`, `slugify`
220-
- **Numeric transformers**: `abs`, `clamp_max`, `clamp_min`
221-
- **Security transformers**: `encrypt`
222-
- **Phone transformers**: `normalize_phone` (adds +33 prefix for French numbers starting with 0)
70+
## πŸ“– Learn More
22371

224-
## πŸ“Š Export Formats
72+
- **[πŸ“š Complete Documentation](https://github.com/Grazulex/laravel-arc/wiki)** - Full guides and API reference
73+
- **[πŸš€ Getting Started](https://github.com/Grazulex/laravel-arc/wiki/Getting-Started)** - Installation and first steps
74+
- **[πŸ’‘ Examples](https://github.com/Grazulex/laravel-arc/wiki/Examples)** - Real-world usage examples
75+
- **[πŸ”§ Advanced Features](https://github.com/Grazulex/laravel-arc/wiki/Advanced-Features)** - Transformers, traits, and more
22576

226-
Export DTOs in 10 different formats:
227-
228-
```php
229-
// Individual exports
230-
$json = $userDto->toJson();
231-
$yaml = $userDto->toYaml();
232-
$csv = $userDto->toCsv();
233-
$xml = $userDto->toXml();
234-
$toml = $userDto->toToml();
235-
$markdown = $userDto->toMarkdownTable();
236-
$phpArray = $userDto->toPhpArray();
237-
$queryString = $userDto->toQueryString();
238-
$messagepack = $userDto->toMessagePack();
239-
$collection = $userDto->toCollection();
240-
241-
// Collection exports (with data wrapper like Laravel Resources)
242-
$jsonData = UserDTO::collectionToJson($users);
243-
$csvData = UserDTO::collectionToCsv($users);
244-
$xmlData = UserDTO::collectionToXml($users);
245-
$yamlData = UserDTO::collectionToYaml($users);
246-
$markdownData = UserDTO::collectionToMarkdownTable($users);
247-
```
248-
249-
## βš™οΈ Configuration
250-
251-
Laravel Arc works out of the box, but you can customize it:
252-
253-
```php
254-
// config/dto.php
255-
return [
256-
'definitions_path' => base_path('database/dto_definitions'),
257-
'output_path' => base_path('app/DTO'),
258-
];
259-
```
260-
261-
## πŸ“š Documentation
262-
263-
For complete documentation, examples, and advanced usage, please see:
264-
265-
### Core Concepts
266-
- [πŸ“– Documentation Index](docs/README.md) - Complete navigation guide
267-
- [πŸš€ Getting Started](docs/GETTING_STARTED.md) - Installation and first DTO
268-
- [πŸ“˜ DTO Usage Guide](docs/DTO_USAGE_GUIDE.md) - How to use DTOs in your Laravel application
269-
- [YAML Schema](docs/YAML_SCHEMA.md) - Full YAML configuration reference
270-
- [Field Types](docs/FIELD_TYPES.md) - All available field types and options
271-
- [Traits Guide](docs/TRAITS_GUIDE.md) - Functional and behavioral traits system
272-
- [Validation Rules](docs/VALIDATION_RULES.md) - Custom validation and error handling
273-
274-
### Advanced Features
275-
- [Collection Management](docs/COLLECTION_MANAGEMENT.md) - Working with DTO collections and API resources
276-
- [Export Formats](docs/EXPORT_FORMATS.md) - Export DTOs in 10 different formats
277-
- [Field Transformers](docs/FIELD_TRANSFORMERS.md) - Automatic field value transformation
278-
- [Relationships](docs/RELATIONSHIPS.md) - Eloquent relationships in DTOs
279-
- [Nested DTOs](docs/NESTED_DTO_GUIDE.md) - Building complex nested structures
280-
- [CLI Commands](docs/CLI_COMMANDS.md) - All available Artisan commands
281-
- [Advanced Usage](docs/ADVANCED_USAGE.md) - Advanced patterns and customizations
282-
283-
## πŸ’‘ Examples
284-
285-
Check out the [examples directory](examples) for complete working examples:
77+
## πŸ”§ Requirements
28678

287-
- [🎯 Examples Collection](examples/README.md) - Working examples and templates
288-
- [Basic User DTO](examples/user.yaml) - Simple user DTO with validation
289-
- [API Controllers](examples/api-controller-example.php) - Using DTOs in API controllers
290-
- [Export Formats](examples/export-formats-example.php) - Export DTOs in 10 different formats
291-
- [Collection Methods](examples/collection-methods-example.php) - Advanced collection management
292-
- [Nested Structures](examples/nested-order.yaml) - Complex nested DTOs
293-
- [Enum Support](examples/enum-examples.yaml) - Working with PHP enums
79+
- **PHP:** ^8.3
80+
- **Laravel:** ^12.19
81+
- **Carbon:** ^3.10
29482

29583
## πŸ§ͺ Testing
29684

297-
Laravel Arc includes comprehensive testing utilities:
298-
299-
```php
300-
use Grazulex\LaravelArc\Testing\DtoTester;
301-
302-
// Test DTO validation
303-
DtoTester::assertValidates($data, UserDTO::class);
304-
DtoTester::assertFailsValidation($data, UserDTO::class);
305-
306-
// Test transformations
307-
DtoTester::assertTransforms($input, $expected, UserDTO::class);
308-
309-
// Test collections
310-
DtoTester::assertCollection($models, UserDTO::class);
85+
```bash
86+
composer test
31187
```
31288

313-
## πŸ”§ Requirements
314-
315-
- PHP: ^8.3
316-
- Laravel: ^12.19
317-
- Carbon: ^3.10
318-
319-
## πŸš€ Performance
320-
321-
Laravel Arc is optimized for performance:
322-
323-
- **Memory Efficient**: Minimal memory footprint with smart serialization
324-
- **Fast Generation**: Optimized YAML parsing and PHP generation
325-
- **Cached Definitions**: YAML definitions cached for better performance
326-
- **Bulk Operations**: Efficient handling of large model collections
327-
32889
## 🀝 Contributing
32990

33091
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
33192

33293
## πŸ”’ Security
33394

334-
If you discover a security vulnerability, please review our [Security Policy](SECURITY.md) before disclosing it.
95+
Please review our [Security Policy](SECURITY.md) for reporting vulnerabilities.
33596

33697
## πŸ“„ License
33798

33899
Laravel Arc is open-sourced software licensed under the [MIT license](LICENSE.md).
339100

340101
---
341102

342-
**Made with ❀️ for the Laravel community**
343-
344-
### Resources
345-
346-
- [πŸ“– Documentation](docs/README.md)
347-
- [πŸ’¬ Discussions](https://github.com/Grazulex/laravel-arc/discussions)
348-
- [πŸ› Issue Tracker](https://github.com/Grazulex/laravel-arc/issues)
349-
- [πŸ“¦ Packagist](https://packagist.org/packages/grazulex/laravel-arc)
350-
351-
### Community Links
352-
353-
- [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md) - Our code of conduct
354-
- [CONTRIBUTING.md](CONTRIBUTING.md) - How to contribute
355-
- [SECURITY.md](SECURITY.md) - Security policy
356-
- [RELEASES.md](RELEASES.md) - Release notes and changelog
103+
**Made with ❀️ by [Jean-Marc Strauven](https://github.com/Grazulex)**

β€Žcomposer.jsonβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"support": {
6363
"issues": "https://github.com/Grazulex/laravel-arc/issues",
6464
"source": "https://github.com/Grazulex/laravel-arc",
65+
"docs": "https://github.com/Grazulex/laravel-arc/wiki",
6566
"wiki": "https://github.com/Grazulex/laravel-arc/wiki",
6667
"forum": "https://github.com/Grazulex/laravel-arc/discussions"
6768
},

0 commit comments

Comments
Β (0)