1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5pub struct PhpRoot {
6 pub items: Vec<PhpItem>,
7}
8
9#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11pub enum PhpItem {
12 OpenTag,
13 CloseTag,
14 Statement(PhpStatement),
15 Function(PhpFunction),
16 Class(PhpClass),
17 Interface(PhpInterface),
18 Trait(PhpTrait),
19 Namespace(PhpNamespace),
20 Use(PhpUse),
21}
22
23#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
25pub enum PhpStatement {
26 Expression(PhpExpression),
27 If(PhpIf),
28 While(PhpWhile),
29 For(PhpFor),
30 Foreach(PhpForeach),
31 Switch(PhpSwitch),
32 Try(PhpTry),
33 Return(Option<PhpExpression>),
34 Break(Option<PhpExpression>),
35 Continue(Option<PhpExpression>),
36 Echo(Vec<PhpExpression>),
37 Print(PhpExpression),
38 Global(Vec<String>),
39 Static(Vec<PhpVariable>),
40 Unset(Vec<PhpExpression>),
41 Declare(Vec<PhpDeclareItem>),
42 Block(Vec<PhpStatement>),
43}
44
45#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
47pub enum PhpExpression {
48 Literal(PhpLiteral),
49 Variable(PhpVariable),
50 Array(Vec<PhpArrayElement>),
51 FunctionCall(PhpFunctionCall),
52 MethodCall(PhpMethodCall),
53 PropertyAccess(PhpPropertyAccess),
54 ArrayAccess(PhpArrayAccess),
55 Assignment(PhpAssignment),
56 BinaryOp(PhpBinaryOp),
57 UnaryOp(PhpUnaryOp),
58 TernaryOp(PhpTernaryOp),
59 Cast(PhpCast),
60 New(PhpNew),
61 Clone(Box<PhpExpression>),
62 Instanceof(PhpInstanceof),
63 Include(PhpInclude),
64 Require(PhpRequire),
65 Eval(Box<PhpExpression>),
66 Exit(Option<Box<PhpExpression>>),
67 Empty(Box<PhpExpression>),
68 Isset(Vec<PhpExpression>),
69 List(Vec<Option<PhpExpression>>),
70 Yield(PhpYield),
71}
72
73#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
75pub enum PhpLiteral {
76 String(String),
77 Number(String),
78 Boolean(bool),
79 Null,
80}
81
82#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
84pub struct PhpVariable {
85 pub name: String,
86}
87
88#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
90pub struct PhpArrayElement {
91 pub key: Option<PhpExpression>,
92 pub value: PhpExpression,
93}
94
95#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
97pub struct PhpFunctionCall {
98 pub name: Box<PhpExpression>,
99 pub arguments: Vec<PhpExpression>,
100}
101
102#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
104pub struct PhpMethodCall {
105 pub object: Box<PhpExpression>,
106 pub method: String,
107 pub arguments: Vec<PhpExpression>,
108}
109
110#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
112pub struct PhpPropertyAccess {
113 pub object: Box<PhpExpression>,
114 pub property: String,
115}
116
117#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
119pub struct PhpArrayAccess {
120 pub array: Box<PhpExpression>,
121 pub index: Box<PhpExpression>,
122}
123
124#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
126pub struct PhpAssignment {
127 pub left: Box<PhpExpression>,
128 pub operator: PhpAssignmentOp,
129 pub right: Box<PhpExpression>,
130}
131
132#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
134pub enum PhpAssignmentOp {
135 Assign,
136 PlusAssign,
137 MinusAssign,
138 MultiplyAssign,
139 DivideAssign,
140 ModuloAssign,
141 PowerAssign,
142 ConcatAssign,
143 BitwiseAndAssign,
144 BitwiseOrAssign,
145 BitwiseXorAssign,
146 LeftShiftAssign,
147 RightShiftAssign,
148 NullCoalesceAssign,
149}
150
151#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
153pub struct PhpBinaryOp {
154 pub left: Box<PhpExpression>,
155 pub operator: PhpBinaryOperator,
156 pub right: Box<PhpExpression>,
157}
158
159#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
161pub enum PhpBinaryOperator {
162 Plus,
163 Minus,
164 Multiply,
165 Divide,
166 Modulo,
167 Power,
168 Concat,
169 Equal,
170 NotEqual,
171 Identical,
172 NotIdentical,
173 Less,
174 LessEqual,
175 Greater,
176 GreaterEqual,
177 Spaceship,
178 LogicalAnd,
179 LogicalOr,
180 LogicalXor,
181 BitwiseAnd,
182 BitwiseOr,
183 BitwiseXor,
184 LeftShift,
185 RightShift,
186 NullCoalesce,
187}
188
189#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
191pub struct PhpUnaryOp {
192 pub operator: PhpUnaryOperator,
193 pub operand: Box<PhpExpression>,
194}
195
196#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
198pub enum PhpUnaryOperator {
199 Plus,
200 Minus,
201 LogicalNot,
202 BitwiseNot,
203 PreIncrement,
204 PostIncrement,
205 PreDecrement,
206 PostDecrement,
207 ErrorSuppression,
208}
209
210#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
212pub struct PhpTernaryOp {
213 pub condition: Box<PhpExpression>,
214 pub true_expr: Option<Box<PhpExpression>>,
215 pub false_expr: Box<PhpExpression>,
216}
217
218#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
220pub struct PhpCast {
221 pub cast_type: PhpCastType,
222 pub expression: Box<PhpExpression>,
223}
224
225#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
227pub enum PhpCastType {
228 Int,
229 Float,
230 String,
231 Bool,
232 Array,
233 Object,
234 Unset,
235}
236
237#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
239pub struct PhpNew {
240 pub class: Box<PhpExpression>,
241 pub arguments: Vec<PhpExpression>,
242}
243
244#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
246pub struct PhpInstanceof {
247 pub expression: Box<PhpExpression>,
248 pub class: Box<PhpExpression>,
249}
250
251#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
253pub struct PhpInclude {
254 pub once: bool,
255 pub path: Box<PhpExpression>,
256}
257
258#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
260pub struct PhpRequire {
261 pub once: bool,
262 pub path: Box<PhpExpression>,
263}
264
265#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
267pub struct PhpYield {
268 pub key: Option<Box<PhpExpression>>,
269 pub value: Option<Box<PhpExpression>>,
270 pub from: bool,
271}
272
273#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
275pub struct PhpIf {
276 pub condition: Box<PhpExpression>,
277 pub then_stmt: Box<PhpStatement>,
278 pub elseif_stmts: Vec<PhpElseif>,
279 pub else_stmt: Option<Box<PhpStatement>>,
280}
281
282#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
284pub struct PhpElseif {
285 pub condition: Box<PhpExpression>,
286 pub statement: Box<PhpStatement>,
287}
288
289#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
291pub struct PhpWhile {
292 pub condition: Box<PhpExpression>,
293 pub statement: Box<PhpStatement>,
294}
295
296#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
298pub struct PhpFor {
299 pub init: Vec<PhpExpression>,
300 pub condition: Vec<PhpExpression>,
301 pub update: Vec<PhpExpression>,
302 pub statement: Box<PhpStatement>,
303}
304
305#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
307pub struct PhpForeach {
308 pub iterable: Box<PhpExpression>,
309 pub key: Option<Box<PhpExpression>>,
310 pub value: Box<PhpExpression>,
311 pub statement: Box<PhpStatement>,
312}
313
314#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
316pub struct PhpSwitch {
317 pub expression: Box<PhpExpression>,
318 pub cases: Vec<PhpCase>,
319}
320
321#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
323pub struct PhpCase {
324 pub value: Option<Box<PhpExpression>>, pub statements: Vec<PhpStatement>,
326}
327
328#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
330pub struct PhpTry {
331 pub statement: Box<PhpStatement>,
332 pub catches: Vec<PhpCatch>,
333 pub finally_stmt: Option<Box<PhpStatement>>,
334}
335
336#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
338pub struct PhpCatch {
339 pub types: Vec<String>,
340 pub variable: PhpVariable,
341 pub statement: Box<PhpStatement>,
342}
343
344#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
346pub struct PhpDeclareItem {
347 pub name: String,
348 pub value: Box<PhpExpression>,
349}
350
351#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
353pub struct PhpFunction {
354 pub name: String,
355 pub parameters: Vec<PhpParameter>,
356 pub return_type: Option<PhpType>,
357 pub body: Box<PhpStatement>,
358 pub by_ref: bool,
359}
360
361#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
363pub struct PhpParameter {
364 pub name: String,
365 pub param_type: Option<PhpType>,
366 pub default: Option<Box<PhpExpression>>,
367 pub by_ref: bool,
368 pub variadic: bool,
369}
370
371#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
373pub enum PhpType {
374 Named(String),
375 Nullable(Box<PhpType>),
376 Union(Vec<PhpType>),
377}
378
379#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
381pub struct PhpClass {
382 pub name: String,
383 pub extends: Option<String>,
384 pub implements: Vec<String>,
385 pub members: Vec<PhpClassMember>,
386 pub modifiers: Vec<PhpModifier>,
387}
388
389#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
391pub enum PhpClassMember {
392 Property(PhpProperty),
393 Method(PhpMethod),
394 Constant(PhpConstant),
395 Use(PhpTraitUse),
396}
397
398#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
400pub struct PhpProperty {
401 pub name: String,
402 pub property_type: Option<PhpType>,
403 pub default: Option<Box<PhpExpression>>,
404 pub modifiers: Vec<PhpModifier>,
405}
406
407#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
409pub struct PhpMethod {
410 pub name: String,
411 pub parameters: Vec<PhpParameter>,
412 pub return_type: Option<PhpType>,
413 pub body: Option<Box<PhpStatement>>,
414 pub modifiers: Vec<PhpModifier>,
415 pub by_ref: bool,
416}
417
418#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
420pub struct PhpConstant {
421 pub name: String,
422 pub value: Box<PhpExpression>,
423 pub modifiers: Vec<PhpModifier>,
424}
425
426#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
428pub struct PhpTraitUse {
429 pub traits: Vec<String>,
430 pub adaptations: Vec<PhpTraitAdaptation>,
431}
432
433#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
435pub enum PhpTraitAdaptation {
436 Precedence { method: String, trait_name: String, insteadof: Vec<String> },
437 Alias { method: String, trait_name: Option<String>, alias: String, modifier: Option<PhpModifier> },
438}
439
440#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
442pub enum PhpModifier {
443 Public,
444 Protected,
445 Private,
446 Static,
447 Abstract,
448 Final,
449}
450
451#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
453pub struct PhpInterface {
454 pub name: String,
455 pub extends: Vec<String>,
456 pub members: Vec<PhpInterfaceMember>,
457}
458
459#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
461pub enum PhpInterfaceMember {
462 Method(PhpMethod),
463 Constant(PhpConstant),
464}
465
466#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
468pub struct PhpTrait {
469 pub name: String,
470 pub members: Vec<PhpClassMember>,
471}
472
473#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
475pub struct PhpNamespace {
476 pub name: Option<String>,
477 pub items: Vec<PhpItem>,
478}
479
480#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
482pub struct PhpUse {
483 pub uses: Vec<PhpUseItem>,
484 pub use_type: PhpUseType,
485}
486
487#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
489pub struct PhpUseItem {
490 pub name: String,
491 pub alias: Option<String>,
492}
493
494#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
496pub enum PhpUseType {
497 Normal,
498 Function,
499 Const,
500}