-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
95 additions
and
8 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,39 @@ | ||
<?php | ||
|
||
namespace App\Helpers\MetaFormats\Validators; | ||
|
||
use App\Exceptions\InternalServerException; | ||
use App\Helpers\MetaFormats\FormatCache; | ||
use App\Helpers\MetaFormats\MetaFormat; | ||
|
||
/** | ||
* Validates formats. Accepts any format derived of the base MetaFormat. | ||
* Format fields are validated by validators added to the fields. | ||
*/ | ||
class VFormat | ||
{ | ||
public const SWAGGER_TYPE = "object"; | ||
public string $format; | ||
|
||
public function __construct(string $format) | ||
{ | ||
$this->format = $format; | ||
|
||
// throw immediatelly if the format does not exist | ||
if (!FormatCache::formatExists($format)) { | ||
throw new InternalServerException("Format $format does not exist."); | ||
} | ||
} | ||
|
||
public function getExampleValue() | ||
{ | ||
///TODO | ||
return "0"; | ||
} | ||
|
||
public function validate(mixed $value) | ||
{ | ||
// fine-grained checking is done in the properties | ||
return $value instanceof MetaFormat; | ||
} | ||
} |