forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConstant.php
More file actions
58 lines (47 loc) · 1.59 KB
/
Copy pathConstant.php
File metadata and controls
58 lines (47 loc) · 1.59 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
<?php
class Constant
{
public $name; // TEXTURE_ATLAS_JSON_ARRAY, PHYSICS_PHASER_JSON, etc
public $types = []; // an array containing the one single type the const can be
public $help = [];
public $line; // number, line number in the source file this is found on?
public function __construct($block)
{
// Because zero offset + allowing for final line
$this->line = $block->end + 2;
// Phaser.Cache.TEXTURE = 3;
$name = $block->code;
$period = strrpos($name, '.');
$equals = strrpos($name, '=');
if ($period > 0 && $equals > 0)
{
$len = $equals - $period - 1;
$name = substr($name, $period + 1, $len);
}
else if ($period > 0)
{
$name = substr($name, $period + 1, -1);
}
$this->name = trim($name);
$line = $block->getLine('@type');
if ($line && preg_match("/.*@type\s?{(\S*)}/", $line, $output))
{
$this->types = explode('|', $output[1]);
}
}
public function getArray()
{
$a = array(
'name' => $this->name,
'type' => $this->types[0],
'help' => implode('\n', $this->help),
'line' => $this->line
);
return $a;
}
public function getJSON()
{
return json_encode($this->getArray());
}
}
?>