This repository has been archived by the owner on May 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathschema.class.php
101 lines (73 loc) · 1.89 KB
/
schema.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?
class builder
{
public $data = '';
public $schema;
private $declaredProps = array();
function addToFile($data)
{
$this->data .= $data;
}
function startClass($name, $extends = null)
{
$data = "<?php
class $name";
if ($extends) {
$data .= " extends $extends";
}
$this->addToFile($data . '{
');
}
function endClass()
{
$this->addToFile('}');
}
function addClassProp($name, $ancestors)
{
foreach ($ancestors as $class) {
if (in_array($name, $this->schema->types->{$class}->properties)) {
return true;
}
}
//var_dump($this->schema->properties->{$name});
$dataType = '';
$count = 0;
foreach ($this->schema->properties->{$name}->ranges as $range) {
if ($count > 0) {
$dataType .= '|';
}
if ($range == 'Text' || $range == 'URL') {
$range = 'string';
}
if (isset($this->schema->types->{$range})) {
$tmp = '';
foreach ($this->schema->types->{$range}->ancestors as $parent) {
$tmp .= $parent . '_';
}
$range = $tmp . $range;
}
$dataType .= $range;
$count++;
}
$comment = $this->schema->properties->{$name}->comment_plain;
$data =
"
/**
* $comment
*
* @var $$name $dataType
*/
public $$name;
";
$this->addToFile($data);
//die(var_dump($this->schema->properties->{$name}));
}
function clearBuffer()
{
$this->data = '';
}
function fetchSchema()
{
$this->schema = json_decode(file_get_contents('http://schema.rdfs.org/all.json'));
}
}