Skip to content

Commit c2c8555

Browse files
committed
refactor: remove legacy component utils from core
1 parent 9f90ef0 commit c2c8555

9 files changed

Lines changed: 147 additions & 847 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,16 @@ elprobe run <package>
356356
- Removed unused `HttpUtils` and `FunctionUtils` helpers from
357357
`components\utils`. HTTP should move to future async `LibHttp`; delayed
358358
callbacks should use PocketMine scheduler or plugin-owned services.
359+
- Removed the remaining pure legacy `components\utils` helpers from the core:
360+
`ArrayUtils`, `Text`, `Number`, `TimeUtils` and `ValidationUtils`.
361+
Supported 3.x utility code now belongs to LibCommons. Use
362+
`imperazim\commons\collection\Arr`, `imperazim\commons\text\Text`,
363+
`imperazim\commons\number\Number`, `imperazim\commons\time\Clock`,
364+
`imperazim\commons\time\Duration`, `imperazim\commons\time\KeyCooldown` and
365+
`imperazim\commons\validation\Validator` as replacements.
366+
- The old SQL-like `ArrayUtils::query`, `select`, `insert`, `update` and
367+
`delete` APIs were intentionally not carried forward. They were too broad for
368+
a commons helper and should become explicit collection code or LibDB usage.
359369
- `imperazim\components\filesystem\File` no longer depends on the removed
360370
Config wrapper; pass a directory string or use PocketMine `Config` directly.
361371
- `File`, `Path`, `FileExtensionTypes` and `FileSystemException` remain part of

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,17 @@ move it to a future dedicated assets/resource-pack package such as `LibAssets`
225225
if the ecosystem needs one later. This does not belong in `LibCommons`, because
226226
resource packs require PocketMine lifecycle, files, manifests and server state.
227227

228-
The old `HttpUtils` and `FunctionUtils` helpers were removed from
228+
The remaining pure `components\utils` helpers were removed from the core too:
229+
`ArrayUtils`, `Text`, `Number`, `TimeUtils` and `ValidationUtils`. Their stable
230+
3.x direction is `LibCommons`:
231+
`imperazim\commons\collection\Arr`, `imperazim\commons\text\Text`,
232+
`imperazim\commons\number\Number`, `imperazim\commons\time\Clock`,
233+
`imperazim\commons\time\Duration`, `imperazim\commons\time\KeyCooldown` and
234+
`imperazim\commons\validation\Validator`. The old SQL-like `ArrayUtils::query`,
235+
`select`, `insert`, `update` and `delete` helpers were intentionally not ported;
236+
use LibDB or explicit collection code instead.
237+
238+
The old `HttpUtils` and `FunctionUtils` helpers were also removed from
229239
`components\utils`. Use a future async `LibHttp` for HTTP work and PocketMine's
230240
scheduler or plugin-owned services for delayed callbacks. The `File` filesystem
231241
utility remains part of the EasyLibrary core direction and will be refined

changelogs/3.0.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,6 +1540,16 @@ Reload rereads config files for future EasyLibrary operations. It does not:
15401540
`PluginCdnResourcePackTrait` and `components\utils\ResourcePacks`.
15411541
- The unused `HttpUtils` and `FunctionUtils` helpers were removed from
15421542
`components\utils`.
1543+
- The remaining pure legacy utility helpers were removed from
1544+
`components\utils` as well:
1545+
`ArrayUtils`, `Text`, `Number`, `TimeUtils` and `ValidationUtils`.
1546+
Their 3.x replacement is LibCommons, using focused namespaces such as
1547+
`imperazim\commons\collection`, `imperazim\commons\text`,
1548+
`imperazim\commons\number`, `imperazim\commons\time` and
1549+
`imperazim\commons\validation`.
1550+
- The old SQL-like `ArrayUtils::query`, `select`, `insert`, `update` and
1551+
`delete` helpers were intentionally not ported to LibCommons. Use LibDB or
1552+
explicit collection code instead.
15431553
- `imperazim\components\filesystem\File` no longer depends on the removed
15441554
Config wrapper. New code should pass a directory string and file metadata, or
15451555
use PocketMine `Config` directly for normal config files.
@@ -1596,6 +1606,21 @@ need PocketMine lifecycle, filesystem state and server resource-pack handling.
15961606
work belongs in `LibHttp`; delayed callbacks should use PocketMine scheduler or
15971607
a plugin-owned service.
15981608

1609+
The remaining pure utility classes were moved out of the core because
1610+
EasyLibrary 3.x is a manager, not a general-purpose utility bundle. Keeping
1611+
`ArrayUtils`, `Text`, `Number`, `TimeUtils` and `ValidationUtils` in the core
1612+
would recreate the old full-bundle expectation in a smaller shape. LibCommons
1613+
is the correct owner for these helpers because it can be installed as a normal
1614+
official package, versioned independently and reused by standalone libraries
1615+
without implying that EasyLibrary core owns every helper API.
1616+
1617+
The SQL-like `ArrayUtils` methods were not moved because their behavior looked
1618+
database-shaped but operated on arbitrary arrays through regex parsing. That is
1619+
too surprising for a commons package and too weak for real persistence. In 3.x,
1620+
database-shaped data should use LibDB, while in-memory array transformations
1621+
should be written explicitly with `Arr::pluck`, `Arr::groupBy`,
1622+
`Arr::sortBy`, `array_filter`, `array_map` or small local domain code.
1623+
15991624
The filesystem area is different: `File` and `Path` are actively useful to the
16001625
core and remain part of the EasyLibrary direction. They may be renamed, moved or
16011626
hardened, but the idea should stay available.
@@ -1668,6 +1693,59 @@ task through the plugin scheduler directly:
16681693
$this->getScheduler()->scheduleDelayedTask($task, 20);
16691694
```
16701695

1696+
If old code used the remaining `components\utils` classes, install LibCommons
1697+
and import the focused replacement:
1698+
1699+
```php
1700+
use imperazim\commons\collection\Arr;
1701+
use imperazim\commons\number\Number;
1702+
use imperazim\commons\text\Text;
1703+
use imperazim\commons\time\Clock;
1704+
use imperazim\commons\time\Duration;
1705+
use imperazim\commons\validation\Validator;
1706+
1707+
$names = Arr::pluck($users, "name");
1708+
$message = Text::colorize("&aOnline");
1709+
$coins = Number::compact(15320);
1710+
$now = Clock::time();
1711+
$seconds = Duration::parse("10m");
1712+
$validName = Validator::minecraftUsername("Steve_01");
1713+
```
1714+
1715+
Common method migrations:
1716+
1717+
| 2.x helper | 3.x direction |
1718+
|---|---|
1719+
| `ArrayUtils::pluck($rows, "name")` | `Arr::pluck($rows, "name")` |
1720+
| `ArrayUtils::flatten($array)` | `Arr::flatten($array)` |
1721+
| `ArrayUtils::groupBy($rows, "rank")` | `Arr::groupBy($rows, "rank")` |
1722+
| `Text::insertLineBreaks($text, 36)` | `Text::wrapWords($text, 36)` |
1723+
| `Text::removeExtraSpaces($text)` | `Text::normalizeSpaces($text)` |
1724+
| `Text::toUpperCase($text)` | `Text::upper($text)` |
1725+
| `Text::toLowerCase($text)` | `Text::lower($text)` |
1726+
| `Text::titleCase($text)` | `Text::title($text)` |
1727+
| `Text::slugify($text)` | `Text::slug($text)` |
1728+
| `Text::colorize($text)` | `Text::colorize($text)` |
1729+
| `Number::formatAsCurrency($value)` | `Number::currency($value)` |
1730+
| `Number::formatAsPercentage($ratio)` | `Number::percent($ratio)` |
1731+
| `Number::format($length, $number)` | `Number::pad($number, $length)` |
1732+
| `Number::max($numbers)` | `Number::maxOrNull($numbers)` |
1733+
| `Number::min($numbers)` | `Number::minOrNull($numbers)` |
1734+
| `TimeUtils::GetCurrentTime()` | `Clock::time()` |
1735+
| `TimeUtils::GetCurrentDate()` | `Clock::date()` |
1736+
| `TimeUtils::IsWeekend()` | `Clock::isWeekend()` |
1737+
| `TimeUtils::IsLeapYear()` | `Clock::isLeapYear()` |
1738+
| `ValidationUtils::isEmail($value)` | `Validator::email($value)` |
1739+
| `ValidationUtils::isUrl($value)` | `Validator::url($value)` |
1740+
| `ValidationUtils::isInteger($value)` | `Validator::integer($value)` |
1741+
| `ValidationUtils::isMinecraftUsername($value)` | `Validator::minecraftUsername($value)` |
1742+
| `ValidationUtils::isIpAddress($value)` | `Validator::ip($value)` |
1743+
1744+
The phone-number validator and generic `Text::substring`, `Text::reverse` or
1745+
`Text::stripHtmlTags` style helpers were not copied as-is. Use native PHP
1746+
functions or plugin-local validation for those cases unless they become common
1747+
enough to justify a focused LibCommons addition later.
1748+
16711749
Recommended mindset:
16721750

16731751
```text

docs/migration.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ Removed 2.x-era helpers:
9494
| `imperazim\components\utils\ResourcePacks` | Plugin-owned resource-pack registration or future `LibAssets` |
9595
| `imperazim\components\utils\HttpUtils` | Future async `LibHttp` or plugin-owned HTTP client |
9696
| `imperazim\components\utils\FunctionUtils` | PocketMine scheduler directly or plugin-owned service |
97+
| `imperazim\components\utils\ArrayUtils` | `imperazim\commons\collection\Arr` for collection helpers; LibDB or explicit code for query/update behavior |
98+
| `imperazim\components\utils\Text` | `imperazim\commons\text\Text` |
99+
| `imperazim\components\utils\Number` | `imperazim\commons\number\Number` |
100+
| `imperazim\components\utils\TimeUtils` | `imperazim\commons\time\Clock`, `Duration` or `KeyCooldown` |
101+
| `imperazim\components\utils\ValidationUtils` | `imperazim\commons\validation\Validator` |
97102

98103
The old `File` constructor no longer accepts the removed
99104
`imperazim\components\config\Config` wrapper. Pass a directory string and file
@@ -110,6 +115,49 @@ registration explicit in the plugin that owns the pack until a focused API is
110115
designed. If this becomes an official library, it should be a dedicated
111116
assets/resource-pack package such as `LibAssets`, not `LibCommons`.
112117

118+
Pure utility migration now points to LibCommons. The new API uses smaller
119+
focused classes instead of a broad `components\utils` namespace:
120+
121+
```php
122+
use imperazim\commons\collection\Arr;
123+
use imperazim\commons\number\Number;
124+
use imperazim\commons\text\Text;
125+
use imperazim\commons\time\Clock;
126+
use imperazim\commons\time\Duration;
127+
use imperazim\commons\validation\Validator;
128+
129+
$names = Arr::pluck($players, "name");
130+
$message = Text::colorize("&aWelcome");
131+
$coins = Number::compact(15320);
132+
$now = Clock::time();
133+
$cooldown = Duration::parse("5m");
134+
$valid = Validator::minecraftUsername("Steve_01");
135+
```
136+
137+
The old SQL-like `ArrayUtils` methods are not part of LibCommons:
138+
139+
```php
140+
ArrayUtils::query("SELECT name FROM users WHERE age > 20", $data);
141+
ArrayUtils::insert("INSERT INTO users (id, name) VALUES (1, 'Alice')", $data);
142+
ArrayUtils::update("UPDATE users SET name = 'Bob' WHERE id = 1", $data);
143+
ArrayUtils::delete("DELETE FROM users WHERE id = 1", $data);
144+
```
145+
146+
Those helpers were convenient but too vague for a shared commons package. Use
147+
LibDB when the data is database-shaped, or write explicit collection code when
148+
the data is already an in-memory array:
149+
150+
```php
151+
use imperazim\commons\collection\Arr;
152+
153+
$adults = array_values(array_filter(
154+
$users,
155+
static fn(array $user): bool => ((int) ($user["age"] ?? 0)) > 20
156+
));
157+
158+
$names = Arr::pluck($adults, "name");
159+
```
160+
113161
For plugin code, prefer normal PMMP dependency declarations instead of assuming
114162
EasyLibrary always ships a class:
115163

0 commit comments

Comments
 (0)