-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathfunctions.php
More file actions
30 lines (23 loc) · 650 Bytes
/
functions.php
File metadata and controls
30 lines (23 loc) · 650 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
declare(strict_types=1);
namespace JsonApiPhp\JsonApi;
use JsonApiPhp\JsonApi\Internal\Attachable;
function combine(Attachable ...$members): object {
$obj = (object)[];
foreach ($members as $member) {
$member->attachTo($obj);
}
return $obj;
}
function child($o, string $name): mixed {
if (!isset($o->{$name})) {
$o->{$name} = (object)[];
}
return $o->{$name};
}
function isValidName(string $name): bool {
return preg_match('/^(?=[^-_ ])[a-zA-Z0-9\x{0080}-\x{FFFF}-_ ]*(?<=[^-_ ])$/u', $name) === 1;
}
function compositeKey(string $type, string $id): string {
return "{$type}:{$id}";
}