src/Table/functions.php source

1 <?php
2
3 namespace mini;
4
5 use Collator;
6
7 // Register Collator service - uses application locale by default
8 Mini::$mini->addService(Collator::class, Lifetime::Singleton, fn() => Mini::$mini->loadServiceConfig(
9 Collator::class,
10 new Collator(Mini::$mini->locale)
11 ));
12
13 /**
14 * Get the application's Collator instance for locale-aware string comparison
15 *
16 * Used by table sorting and LIKE operations for consistent collation behavior.
17 * Configure via config/Collator.php or defaults to Mini::$mini->locale.
18 *
19 * @return Collator
20 */
21 function collator(): Collator
22 {
23 return Mini::$mini->get(Collator::class);
24 }
25
26 /**
27 * Empty predicate constant for building filter conditions
28 *
29 * Since Predicate is immutable, a single shared instance is safe.
30 *
31 * ```php
32 * use const mini\p;
33 *
34 * $users->or(
35 * p->eq('status', 'active'),
36 * p->eq('status', 'pending')
37 * );
38 *
39 * // Chain multiple conditions (AND)
40 * p->eq('role', 'admin')->gte('level', 5)
41 * ```
42 */
43 const p = new Table\Predicate();
44