-
-
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.
feat: add array support for metadata (#6)
- Loading branch information
Showing
5 changed files
with
22 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ | |
|
||
/** | ||
* @author Kevin Bond <[email protected]> | ||
* | ||
* @phpstan-type Value scalar|array<scalar> | ||
*/ | ||
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)] | ||
final class Metadata | ||
|
@@ -23,8 +25,11 @@ public function __construct( | |
/** @readonly */ | ||
public string $key, | ||
|
||
/** @readonly */ | ||
public string|bool|int|float $value, | ||
/** | ||
* @readonly | ||
* @var Value | ||
*/ | ||
public string|bool|int|float|array $value, | ||
) { | ||
} | ||
|
||
|
@@ -33,7 +38,7 @@ public function __construct( | |
* | ||
* @param object|class-string|string $objectOrClassOrAlias | ||
* | ||
* @return array<string,scalar> | ||
* @return array<string,Value> | ||
*/ | ||
public static function for(object|string $objectOrClassOrAlias): array | ||
{ | ||
|
@@ -45,8 +50,9 @@ public static function for(object|string $objectOrClassOrAlias): array | |
* or null if key does not exist. | ||
* | ||
* @param object|class-string|string $objectOrClassOrAlias | ||
* @return Value|null | ||
*/ | ||
public static function get(object|string $objectOrClassOrAlias, string $key): string|bool|int|float|null | ||
public static function get(object|string $objectOrClassOrAlias, string $key): string|bool|int|float|array|null | ||
{ | ||
return self::for($objectOrClassOrAlias)[$key] ?? null; | ||
} | ||
|
@@ -56,8 +62,9 @@ public static function get(object|string $objectOrClassOrAlias, string $key): st | |
* class/object/alias or null if no keys exist. | ||
* | ||
* @param object|class-string|string $objectOrClassOrAlias | ||
* @return Value|null | ||
*/ | ||
public static function first(object|string $objectOrClassOrAlias, string ...$keys): string|bool|int|float|null | ||
public static function first(object|string $objectOrClassOrAlias, string ...$keys): string|bool|int|float|array|null | ||
{ | ||
$metadata = self::for($objectOrClassOrAlias); | ||
|
||
|
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 |
---|---|---|
|
@@ -18,6 +18,8 @@ | |
* @author Kevin Bond <[email protected]> | ||
* | ||
* @internal | ||
* | ||
* @phpstan-import-type Value from Metadata | ||
*/ | ||
final class Map | ||
{ | ||
|
@@ -27,7 +29,7 @@ final class Map | |
/** @var array<string,class-string> */ | ||
public array $aliasToClassMap = []; | ||
|
||
/** @var array<string|class-string,array<string,scalar>> */ | ||
/** @var array<string|class-string,array<string,Value>> */ | ||
public array $metadataMap = []; | ||
|
||
/** @var array<string,class-string[]> */ | ||
|
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 |
---|---|---|
|
@@ -16,6 +16,8 @@ | |
|
||
#[Alias('class5')] | ||
#[Metadata('key1', 'class5-value1')] | ||
#[Metadata('key2', ['a','b'])] | ||
|
||
final class Class5 | ||
{ | ||
} |
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