1. Go to this page and download the library: Download le0daniel/typescript-schema library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use TypescriptSchema\Definition\Complex\Field;use TypescriptSchema\Definition\Schema;
use TypescriptSchema\Definition\Schema;
$user = Schema::object([
'fullName' => Field::ofType(Schema::string())
->resolvedBy(fn(User $user): string => $user->fullName()),
]);
use TypescriptSchema\Definition\Complex\Field;
use TypescriptSchema\Definition\Schema;
$user = Schema::object([
'fullName' => Field::ofType(Schema::string())
->resolvedBy(fn(User $user): string => $user->fullName())
->describe('The combination of title, first and last name')
->deprecated('Use lastName, firstName and title to compute manually', DateTime::createFromFormat('Y-m-d', '2024-05-25')),
]);
use TypescriptSchema\Contracts\Type;
use TypescriptSchema\Definition\Shared\Nullable;
use TypescriptSchema\Definition\Shared\Refinable;
use TypescriptSchema\Definition\Shared\Transformable;
use TypescriptSchema\Definition\Shared\Validators;
use TypescriptSchema\Helpers\Context;
use TypescriptSchema\Data\Enum\Value;
use TypescriptSchema\Exceptions\Issue;
final class MyCustomType implements Type {
use Nullable, Refinable, Transformable, Validators;
public function toDefinition(): SchemaDefinition {
return new \TypescriptSchema\Data\Schema\Definition(
['type' => 'string'],
['type' => 'string'],
);
}
public function serializeValue(mixed $value, Context $context): Value|string {
if (!is_string($value)) {
$context->addIssue(Issue::custom('Value must be a string.'));
return Value::INVALID;
}
if (!$this->runValidators($value, $context)) {
return Value::INVALID;
}
return $value;
}
public function minLength(): MyCustomType {
return $this->addValidator(function (string $value) {
return strlen($value) > 5;
});
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.