alexnguetcha/json-to-class

There is no license information available for the latest version (dev-master) of this package.

simple tool to create php class from json file.

dev-master 2020-09-20 19:21 UTC

This package is auto-updated.

Last update: 2025-01-21 04:51:05 UTC


README

simple tool to create php class from json file.

Example:

{
    "class_name": "post",
    "class_attrs": {
        "id": {
            "type": "int",
            "visibility": "private"
        },
        "id_member": {
            "type": "int",
            "visibility": "private"
        },
        "content": {
            "type": "string",
            "visibility": "private"
        },
        "create_at": {
            "type": "DateTime",
            "visibility": "private"
        }
    }
}
$jtc = new JsonToClass(__DIR__."\\post.json");
$jtc->toFile();

Output:

//Post.php
<?php

class Person
{
	private $name;
	private $old;
	private $sick;

	public function __construct(string $name, int $old, bool $sick)
	{
		$this->name = $name;
		$this->old = $old;
		$this->sick = $sick;
	}

	public function getName(): string
	{
		return $this->name;
	}

	public function getOld(): int
	{
		return $this->old;
	}

	public function isSick(): bool
	{
		return $this->sick;
	}


	public function setName(string $name):self
	{
		$this->name = $name;
		return $this;
	}

	public function setOld(int $old):self
	{
		$this->old = $old;
		return $this;
	}

	public function setSick(bool $sick):self
	{
		$this->sick = $sick;
		return $this;
	}


}