-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhpTemplate.php
More file actions
77 lines (64 loc) · 2.16 KB
/
PhpTemplate.php
File metadata and controls
77 lines (64 loc) · 2.16 KB
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
<?php
/**
* This file is part of JsonClassified.
* @link https://github.com/akimsko/JsonClassified
*
* @copyright Copyright 2012 Bo Thinggaard
* @license http://www.apache.org/licenses/LICENSE-2.0
*/
require_once __DIR__ . '/ITemplate.php';
/**
* Template for PHP
*
* @author bo@unpossiblesystems.dk
*/
class PhpTemplate implements ITemplate {
private static $_types = array(
Builder::TYPE_STRING => 'string',
Builder::TYPE_INT => 'int',
Builder::TYPE_FLOAT => 'float',
Builder::TYPE_BOOL => 'bool',
Builder::TYPE_ARRAY => '{subtype}[]',
Builder::TYPE_OBJECT => '{subtype}'
);
public function getClass() {
$snippet = "<?php\n\n";
$snippet .= "class {classname} {\n";
$snippet .= "{properties}";
$snippet .= "{methods}";
$snippet .= "}\n";
$snippet .= "?>";
return $snippet;
}
public function getPropertyMethods() {
$snippet = "\n\t/**\n";
$snippet .= "\t* @return {type}\n";
$snippet .= "\t*/\n";
$snippet .= "\tpublic function get{name.uc}() {\n";
$snippet .= "\t\treturn \$this->_{name.lc};\n";
$snippet .= "\t}\n";
$snippet .= "\n\t/**\n";
$snippet .= "\t* @param {type} \${name.lc}\n";
$snippet .= "\t* @return {classname}\n";
$snippet .= "\t*/\n";
$snippet .= "\tpublic function set{name.uc}(\${name.lc}) {\n";
$snippet .= "\t\t\$this->_{name.lc} = \${name.lc};\n";
$snippet .= "\t\treturn \$this;\n";
$snippet .= "\t}\n";
return $snippet;
}
public function getProperty() {
$snippet = "\n\t/** @var {type} */\n";
$snippet .= "\tprivate \$_{name.lc};\n";
return $snippet;
}
public function getType($typeIndex) {
return array_key_exists($typeIndex, self::$_types) ? self::$_types[$typeIndex] : self::$_types[Builder::TYPE_STRING];
}
public function getFileExtension() {
return ".php";
}
public function getExtras($properties, $class) {
}
}
?>