-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhancement: Metadata (headers) support
Signed-off-by: Oğuzhan Durgun <[email protected]>
- Loading branch information
1 parent
1c86c21
commit 18569d4
Showing
5 changed files
with
105 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
// Copyright 2021-2023 Zenauth Ltd. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cerbos\Sdk\Utility; | ||
|
||
use Exception; | ||
|
||
class Metadata | ||
{ | ||
/** | ||
* @param array|null $first | ||
* @param array|null $second | ||
* @return array<string, array> | ||
* @throws Exception | ||
*/ | ||
public static function merge(?array $first, ?array $second): array { | ||
if (is_null($first) && is_null($second)) | ||
return []; | ||
else if (is_null($first) && !is_null($second)) | ||
return $second; | ||
else if (is_null($second)) | ||
return $first; | ||
|
||
$combined = array(); | ||
foreach ($first as $k => $v) { | ||
if (is_array($v)) { | ||
foreach ($v as $i => $vv) { | ||
$combined[$k][] = $vv; | ||
} | ||
} | ||
else { | ||
throw new Exception("the type for the parameter first and second parameter is array<string, array>|null"); | ||
} | ||
} | ||
|
||
foreach ($second as $k => $v) { | ||
if (is_array($v)) { | ||
foreach ($v as $i => $vv) { | ||
$combined[$k][] = $vv; | ||
} | ||
} | ||
else { | ||
throw new Exception("the type for the parameter first and second parameter is array<string, array>|null"); | ||
} | ||
} | ||
|
||
return $combined; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters