flux-eco / php-model-class-generator
Writes model classes from json schema files
Installs: 103
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
Open Issues: 0
Type:flux-app
Requires
- php: >=8.0
- ext-curl: *
- ext-json: *
- ext-yaml: *
- flux-eco/json-schema-document: >=0.1.0
README
This component creates model classes from json schema files
Functional Usage
accounts.yaml
name: accounts
type: object
properties:
personId:
type: integer
firstname:
type: string
lastname:
type: string
email:
type: string
type:
type: string
lastChanged:
type: string
generateAccounts.php
fluxPhpModelClassGenerator\generateModelClass(
__DIR__ . '/accounts.yaml',
'FluxCap\ExampleApp\Core\Domain\Models',
__DIR__ . '/generated'
);
generates: Accounts.php
<?php
namespace FluxCap\ExampleApp\Core\Domain\Models;
use JsonSerializable;
class Accounts implements JsonSerializable {
private int $personId;
private string $firstname;
private string $lastname;
private string $email;
private string $type;
private string $lastChanged;
private function __construct(
int $personId,
string $firstname,
string $lastname,
string $email,
string $type,
string $lastChanged,
) {
$this->personId = $personId;
$this->firstname = $firstname;
$this->lastname = $lastname;
$this->email = $email;
$this->type = $type;
$this->lastChanged = $lastChanged;
}
public static function new(
int $personId,
string $firstname,
string $lastname,
string $email,
string $type,
string $lastChanged,
): self {
return new self(
$personId, $firstname, $lastname, $email, $type, $lastChanged
);
}
final public function getPersonId(): int {
return $this->personId;
}
final public function getFirstname(): string {
return $this->firstname;
}
final public function getLastname(): string {
return $this->lastname;
}
final public function getEmail(): string {
return $this->email;
}
final public function getType(): string {
return $this->type;
}
final public function getLastChanged(): string {
return $this->lastChanged;
}
final public function toJson(): string {
return json_encode($this, JSON_THROW_ON_ERROR);
}
final public function toArray(): array {
return get_object_vars($this);
}
final public function jsonSerialize(): array {
return $this->toArray();
}
}
Contributing 💜
Please ...
- ... register an account at https://git.fluxlabs.ch
- ... create pull requests 🔥
Adjustment suggestions / bug reporting 🐾
Please ...
- ... register an account at https://git.fluxlabs.ch
- ... ask us for a Service Level Agreement: support@fluxlabs.ch 😘
- ... read and create issues