-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathPHPFile.php
167 lines (134 loc) · 3.44 KB
/
PHPFile.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
namespace Archetype;
use Archetype\Drivers\InputInterface;
use Archetype\Drivers\OutputInterface;
use Archetype\Endpoints\PHP\AstQuery;
use Archetype\Endpoints\PHP\ClassConstant;
use Archetype\Endpoints\PHP\ClassName;
use Archetype\Endpoints\PHP\Extends_;
use Archetype\Endpoints\PHP\Implements_;
use Archetype\Endpoints\Maker;
use Archetype\Endpoints\PHP\MethodNames;
use Archetype\Endpoints\PHP\Namespace_;
use Archetype\Endpoints\PHP\Property;
use Archetype\Endpoints\PHP\ReflectionProxy;
use Archetype\Endpoints\PHP\Use_;
use Archetype\Endpoints\PHP\UseTrait;
use Archetype\Support\AST\ASTQueryBuilder;
use Archetype\Support\Types;
use Archetype\Traits\HasDirectives;
use Archetype\Traits\HasDirectiveHandlers;
use Archetype\Traits\HasIO;
use Archetype\Traits\HasSyntacticSweeteners;
class PHPFile
{
use HasIO;
use HasDirectives;
use HasDirectiveHandlers;
use HasSyntacticSweeteners;
public InputInterface $input;
public OutputInterface $output;
protected string $contents;
protected string $fileQueryBuilder = Endpoints\PHP\PHPFileQueryBuilder::class;
protected Maker $maker;
public string $astQueryBuilder = ASTQueryBuilder::class;
protected $ast;
protected string $initialModificationHash;
protected $originalAst;
protected $tokens;
protected $directives = [];
public function __construct(
InputInterface $input,
OutputInterface $output,
Maker $maker
) {
$this->input = $input;
$this->output = $output;
$this->maker = $maker;
}
public function query()
{
return new $this->fileQueryBuilder($this);
}
public function all(...$args)
{
return $this->query()->all(...$args);
}
public function in(...$args)
{
return $this->query()->in(...$args);
}
public function where(...$args)
{
return $this->query()->where(...$args);
}
public function astQuery()
{
$handler = new AstQuery($this);
return $handler->astQuery();
}
public function getReflection()
{
$handler = new ReflectionProxy($this);
return $handler->getReflection();
}
public function make()
{
return $this->maker->withFile($this);
}
public function property($key, $value = Types::NO_VALUE)
{
$handler = new Property($this);
return $handler->property($key, $value);
}
public function setProperty($key, $value = Types::NO_VALUE)
{
$handler = new Property($this);
return $handler->setProperty($key, $value);
}
public function use($value = null)
{
$handler = new Use_($this);
return $handler->use($value);
}
public function useTrait($value = null)
{
$handler = new UseTrait($this);
return $handler->useTrait($value);
}
public function namespace(string $value = null)
{
$handler = new Namespace_($this);
return $handler->namespace($value);
}
public function methodNames()
{
$handler = new MethodNames($this);
return $handler->methodNames();
}
public function implements($name = null)
{
$handler = new Implements_($this);
return $handler->implements($name);
}
public function extends($name = null)
{
$handler = new Extends_($this);
return $handler->extends($name);
}
public function className($name = null)
{
$handler = new ClassName($this);
return $handler->className($name);
}
public function classConstant($key, $value = Types::NO_VALUE)
{
$handler = new ClassConstant($this);
return $handler->classConstant($key, $value);
}
public function setClassConstant($key, $value = Types::NO_VALUE)
{
$handler = new ClassConstant($this);
return $handler->setClassConstant($key, $value);
}
}