|
1
|
""" |
|
2
|
Laravel framework enricher. |
|
3
|
|
|
4
|
Promotes generic graph nodes to Laravel semantic types: |
|
5
|
- Controller (files under Controllers/) |
|
6
|
- Model (classes that extend Model) |
|
7
|
- Route (files under routes/) |
|
8
|
- Job (files under Jobs/) |
|
9
|
- Policy (files under Policies/) |
|
10
|
""" |
|
11
|
|
|
12
|
from navegador.enrichment.base import EnrichmentResult, FrameworkEnricher |
|
13
|
|
|
14
|
|
|
15
|
class LaravelEnricher(FrameworkEnricher): |
|
16
|
"""Enriches a navegador graph with Laravel-specific semantics.""" |
|
17
|
|
|
18
|
@property |
|
19
|
def framework_name(self) -> str: |
|
20
|
return "laravel" |
|
21
|
|
|
22
|
@property |
|
23
|
def detection_patterns(self) -> list[str]: |
|
24
|
return ["Illuminate"] |
|
25
|
|
|
26
|
@property |
|
27
|
def detection_files(self) -> list[str]: |
|
28
|
return ["artisan"] |
|
29
|
|
|
30
|
def enrich(self) -> EnrichmentResult: |
|
31
|
result = EnrichmentResult() |
|
32
|
|
|
33
|
# Path-based promotions: (file_path_fragment, semantic_type, pattern_key) |
|
34
|
path_promotions = [ |
|
35
|
("Controllers/", "LaravelController", "controllers"), |
|
36
|
("routes/", "LaravelRoute", "routes"), |
|
37
|
("Jobs/", "LaravelJob", "jobs"), |
|
38
|
("Policies/", "LaravelPolicy", "policies"), |
|
39
|
] |
|
40
|
|
|
41
|
for path_fragment, semantic_type, pattern_key in path_promotions: |
|
42
|
query_result = self.store.query( |
|
43
|
"MATCH (n) WHERE n.file_path IS NOT NULL " |
|
44
|
"AND n.file_path CONTAINS $fragment " |
|
45
|
"RETURN n.name, n.file_path", |
|
46
|
{"fragment": path_fragment}, |
|
47
|
) |
|
48
|
rows = query_result.result_set or [] |
|
49
|
count = 0 |
|
50
|
for row in rows: |
|
51
|
name, file_path = row[0], row[1] |
|
52
|
self._promote_node(name, file_path, semantic_type) |
|
53
|
count += 1 |
|
54
|
result.promoted += 1 |
|
55
|
result.patterns_found[pattern_key] = count |
|
56
|
|
|
57
|
# Model detection: classes that extend Model (name or file_path contains "Model") |
|
58
|
model_result = self.store.query( |
|
59
|
"MATCH (n) WHERE " |
|
60
|
"(n.name IS NOT NULL AND n.name CONTAINS $fragment) OR " |
|
61
|
"(n.file_path IS NOT NULL AND n.file_path CONTAINS $fragment) " |
|
62
|
"RETURN n.name, n.file_path", |
|
63
|
{"fragment": "Model"}, |
|
64
|
) |
|
65
|
rows = model_result.result_set or [] |
|
66
|
model_count = 0 |
|
67
|
for row in rows: |
|
68
|
name, file_path = row[0], row[1] |
|
69
|
self._promote_node(name, file_path, "LaravelModel") |
|
70
|
model_count += 1 |
|
71
|
result.promoted += 1 |
|
72
|
result.patterns_found["models"] = model_count |
|
73
|
|
|
74
|
return result |
|
75
|
|