-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from sitegeist/stringPropertyFormats
String property formats
- Loading branch information
Showing
11 changed files
with
307 additions
and
64 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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sitegeist\SchemeOnYou\Domain\Metadata; | ||
|
||
use Neos\Flow\Annotations as Flow; | ||
|
||
/** | ||
* @see https://swagger.io/docs/specification/data-models/data-types/#string | ||
*/ | ||
#[Flow\Proxy(false)] | ||
#[\Attribute(\Attribute::TARGET_PROPERTY)] | ||
final readonly class StringProperty | ||
{ | ||
public const FORMAT_DATE = 'date'; | ||
public const FORMAT_DATE_TIME = 'date-time'; | ||
public const FORMAT_PASSWORD = 'password'; | ||
public const FORMAT_BYTE = 'byte'; | ||
public const FORMAT_BINARY = 'binary'; | ||
|
||
public function __construct( | ||
public ?string $format = null, | ||
public ?string $description = null, | ||
) { | ||
} | ||
|
||
public static function tryFromReflectionParameter(\ReflectionParameter $reflectionParameter): ?self | ||
{ | ||
$parameterAttributes = $reflectionParameter->getAttributes(self::class); | ||
switch (count($parameterAttributes)) { | ||
case 0: | ||
return null; | ||
case 1: | ||
$arguments = $parameterAttributes[0]->getArguments(); | ||
|
||
return new self( | ||
$arguments['format'] ?? $arguments[0] ?? null, | ||
$arguments['description'] ?? $arguments[1] ?? null, | ||
); | ||
default: | ||
throw new \DomainException( | ||
'There must be no or exactly one string property attribute declared in parameter ' | ||
. $reflectionParameter->getDeclaringClass()?->name | ||
. '::' . $reflectionParameter->getDeclaringFunction()->name | ||
. '::' . $reflectionParameter->name | ||
. ', ' . count($parameterAttributes) . ' given', | ||
1715000621 | ||
); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.