Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ configuration or object models.
| **ArrayShape** | Lightweight array-shape assertions for row validation (`require`). |
| **BaseArrayHelper** | Internal shared base for consistent API across helpers. |
| **ArraySharedOps** | Internal shared operations used by `ArraySingle` and `ArrayMulti` (`each/every/partition/skip*`). |
| **ArrayValueSetOps** | Internal equality/set engine with exact PHP comparison semantics and collision-verified strict fingerprints. |

### Config System

| Class | Description |
|---------------------|---------------------------------------------------------------------------------------------------------------------|
| **Config** | Dot-access configuration loader with explicit hook-aware variants (`getWithHooks`, `setWithHooks`, `fillWithHooks`) plus compiled cache export/load and read memoization. |
| **Config** | Dot-access configuration loader with explicit hook-aware variants (`getWithHooks`, `setWithHooks`, `fillWithHooks`) plus compiled cache export/load and bounded read memoization. |
| **LazyFileConfig** | First-segment lazy loader (`db.host` loads `db.php` on demand) with namespace cache files for structural reads and a flat leaf-index cache for exact scalar lookups. |
| **EnvParser** | Strict dotenv parser with variable expansion and circular-reference detection. |
| **Environment** | Process-environment reader and `EnvReference` factory for deferred configuration values. |
Expand Down
16 changes: 16 additions & 0 deletions benchmarks/CoreBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ final class CoreBench

private array $singleAssoc = [];

private array $uniqueNestedLarge = [];

public function setUp(): void
{
$this->single = [
Expand Down Expand Up @@ -81,6 +83,14 @@ public function setUp(): void
];
}

$this->uniqueNestedLarge = [];
for ($i = 0; $i < 1000; $i++) {
$this->uniqueNestedLarge[] = [
'id' => $i % 500,
'payload' => str_repeat(chr(65 + ($i % 26)), 128),
];
}

$this->dot = [
'app' => ['name' => 'ArrayKit', 'env' => 'local'],
'db' => [
Expand Down Expand Up @@ -184,6 +194,12 @@ public function benchArraySingleUnique(): void
ArraySingle::unique($this->single);
}

#[Subject]
public function benchArraySingleUniqueNestedLong(): void
{
ArraySingle::unique($this->uniqueNestedLarge, true);
}

#[Subject]
public function benchConfigGet(): void
{
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
}
],
"require": {
"php": ">=8.4"
"php": ">=8.4",
"ext-hash": "*"
},
"require-dev": {
"infocyph/phpforge": "dev-main"
Expand Down
2 changes: 2 additions & 0 deletions docs/array-helpers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ Behavior Notes
- ``ArraySingle::avg()``, ``sum()``, ``isPositive()``, and ``isNegative()`` ignore non-numeric values.
- ``ArraySingle::paginate()`` requires ``$page >= 1`` and ``$perPage >= 1``.
- ``ArrayMulti::whereIn()`` / ``whereNotIn()`` treat ``null`` as a real value when the key exists.
- ``ArrayMulti::where()`` / ``firstWhere()`` distinguish explicit ``null`` from
the two-argument shorthand form.
- ``ArrayMulti::flatten($array, 0)`` returns unchanged top-level values.
- Use ``depthGuarded()``, ``flattenGuarded()``, and ``sortRecursiveGuarded()`` when processing untrusted/deep inputs.
- ``ArrayMulti`` callback helpers such as ``sortBy()``, ``sum()``, ``maxBy()``, ``minBy()`` support ``($row, $key)``.
Expand Down
3 changes: 3 additions & 0 deletions docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,9 @@ Config methods:
- ``snapshot()``, ``restore()``, ``changed()``
- ``readonly()``, ``isReadonly()``

Read memoization is bounded to 1,024 resolved paths for predictable memory use
in persistent workers. Mutations and reloads invalidate the memoized values.

Hook-aware methods:

- ``getWithHooks()``
Expand Down
4 changes: 4 additions & 0 deletions docs/lazy-config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ Important lazy-cache details:
exist or are not readable.
- If env values change, rerun ``warmNamespaceCache()`` or flush and rebuild the
namespace cache.
- A namespace is marked loaded only after its source returns a valid array, so
a corrected file can be retried after a failed read.
- A full cache flush removes only ``__flat.php`` and valid namespace cache
files; unrelated files in the configured directory are preserved.

Method Summary
--------------
Expand Down
14 changes: 1 addition & 13 deletions src/Array/ArrayMulti.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,19 +361,7 @@ public static function transpose(array $matrix): array
*/
public static function unique(array $array, bool $strict = false): array
{
$seenFingerprints = [];
$results = [];
foreach ($array as $key => $row) {
$fingerprint = ArraySingleOps::fingerprint($row, $strict);
if (isset($seenFingerprints[$fingerprint])) {
continue;
}

$seenFingerprints[$fingerprint] = true;
$results[$key] = $row;
}

return $results;
return ArraySingleOps::unique($array, $strict);
}

/**
Expand Down
8 changes: 2 additions & 6 deletions src/Array/ArraySingle.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public static function except(array $array, array|string $keys): array
*/
public static function exists(array $array, int|string $key): bool
{
return isset($array[$key]) || array_key_exists($key, $array);
return array_key_exists($key, $array);
}

/**
Expand Down Expand Up @@ -1008,11 +1008,7 @@ public static function where(array $array, ?callable $callback = null): array

private static function invokeValueCallback(callable $callback, mixed $value, int|string $key): mixed
{
try {
return $callback($value, $key);
} catch (\ArgumentCountError) {
return $callback($value);
}
return $callback($value, $key);
}

private static function normalizeArrayKey(mixed $value): int|string
Expand Down
Loading