|
1 | 1 | # Derafu: Support - Essential PHP Utilities |
2 | 2 |
|
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | -A collection of essential PHP utility classes that provide common functionality for string manipulation, array handling, file operations, date management, and more. |
11 | | - |
12 | | -## Features |
13 | | - |
14 | | -{.list-unstyled} |
15 | | -- 🔡 String manipulation utilities. |
16 | | -- 📚 Array handling helpers. |
17 | | -- 📅 Date and time management. |
18 | | -- 📂 File system operations. |
19 | | -- 📝 CSV file handling. |
20 | | -- 🔧 Object manipulation tools. |
21 | | -- 🐛 Debugging utilities. |
22 | | -- 🏭 Object factory and hydration. |
23 | | -- 🔄 Data serialization helpers. |
24 | | -- 🧪 Comprehensive test coverage. |
25 | | - |
26 | | -## Why Derafu\Support? |
27 | | - |
28 | | -This package focuses on solving specific business and data processing needs that are often overlooked by standard PHP utilities: |
29 | | - |
30 | | -- **Business Date Handling**: Working days calculation, fiscal period management, and date ranges that understand holidays and weekends. |
31 | | -- **Robust CSV Processing**: Consistent handling of different encodings, separators, and quote styles across systems. |
32 | | -- **Practical Data Transformations**: Convert between different data structures (trees, tables, lists) while preserving data integrity. |
33 | | -- **Real-world File Operations**: Safe file handling with proper error management and automatic MIME type detection. |
34 | | - |
35 | | -If your application deals with business dates, data processing, or file management, these utilities can save you from reinventing common solutions. |
36 | | - |
37 | | -## Installation |
38 | | - |
39 | | -Install via Composer: |
40 | | - |
41 | | -```bash |
42 | | -composer require derafu/support |
43 | | -``` |
44 | | - |
45 | | -## Usage Examples |
46 | | - |
47 | | -### String Manipulation (Str) |
48 | | - |
49 | | -```php |
50 | | -use Derafu\Support\Str; |
51 | | - |
52 | | -// Generate UUID. |
53 | | -$uuid = Str::uuid4(); |
54 | | - |
55 | | -// Replace placeholders. |
56 | | -$result = Str::format('Hello {{name}}!', ['name' => 'John']); |
57 | | - |
58 | | -// Normalize strings for URLs. |
59 | | -$slug = Str::slug('Hello World!'); // "hello-world". |
60 | | -``` |
61 | | - |
62 | | -### Array Handling (Arr) |
63 | | - |
64 | | -```php |
65 | | -use Derafu\Support\Arr; |
66 | | - |
67 | | -// Auto-cast array values. |
68 | | -$result = Arr::cast($array); |
69 | | - |
70 | | -// Convert array to tree structure. |
71 | | -$tree = Arr::toTree($items, 'parent_id', 'children'); |
72 | | -``` |
73 | | - |
74 | | -### Date Management (Date) |
75 | | - |
76 | | -```php |
77 | | -use Derafu\Support\Date; |
78 | | - |
79 | | -// Add working days. |
80 | | -$newDate = Date::addWorkingDays('2024-01-15', 5, $holidays); |
81 | | - |
82 | | -// Format date in Spanish. |
83 | | -$formatted = Date::formatSpanish('2024-01-15'); // "Lunes, 15 de enero del 2024". |
84 | | - |
85 | | -// Calculate periods |
86 | | -$nextPeriod = Date::nextPeriod(202401); // 202402. |
87 | | -``` |
88 | | - |
89 | | -### File Operations (File) |
90 | | - |
91 | | -```php |
92 | | -use Derafu\Support\File; |
93 | | - |
94 | | -// Get file MIME type. |
95 | | -$mime = File::mimetype('document.pdf'); |
96 | | - |
97 | | -// Compress directory. |
98 | | -File::compress('/path/to/dir'); |
99 | | - |
100 | | -// Send file through browser. |
101 | | -File::send('document.pdf'); |
102 | | -``` |
103 | | - |
104 | | -### CSV Handling (Csv) |
105 | | - |
106 | | -```php |
107 | | -use Derafu\Support\Csv; |
108 | | - |
109 | | -// Read CSV file. |
110 | | -$data = Csv::read('file.csv', ';'); |
111 | | - |
112 | | -// Generate CSV content. |
113 | | -$csvString = Csv::generate($data); |
114 | | - |
115 | | -// Send CSV as download. |
116 | | -Csv::send($data, 'export.csv'); |
117 | | -``` |
118 | | - |
119 | | -### Object Manipulation (Obj) |
120 | | - |
121 | | -```php |
122 | | -use Derafu\Support\Obj; |
123 | | - |
124 | | -// Fill object properties. |
125 | | -$object = Obj::fill($instance, $data); |
126 | | - |
127 | | -// Get public properties. |
128 | | -$properties = Obj::getPublicProperties($instance); |
129 | | -``` |
130 | | - |
131 | | -### Object Factory and Hydration |
132 | | - |
133 | | -```php |
134 | | -use Derafu\Support\Factory; |
135 | | -use Derafu\Support\Hydrator; |
136 | | - |
137 | | -// Create and hydrate objects. |
138 | | -$instance = Factory::create($data, MyClass::class); |
139 | | - |
140 | | -// Hydrate existing instance. |
141 | | -$hydrated = Hydrator::hydrate($instance, $data); |
142 | | -``` |
143 | | - |
144 | | -### Debug Utilities |
145 | | - |
146 | | -```php |
147 | | -use Derafu\Support\Debug; |
148 | | - |
149 | | -// Inspect variable. |
150 | | -$info = Debug::inspect($var, 'myVar'); |
151 | | - |
152 | | -// Print debug information. |
153 | | -Debug::print($var); |
154 | | -``` |
155 | | - |
156 | | -## Contributing |
157 | | - |
158 | | -Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change. |
159 | | - |
160 | | -## License |
161 | | - |
162 | | -This package is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT). |
| 3 | +Please refer to the [documentation](https://www.derafu.dev/docs/core/support) for more information. |
0 commit comments