1
|
|
|
<?php |
2
|
|
|
/****************************************************************************** |
3
|
|
|
* An implementation of dicto (scg.unibe.ch/dicto) in and for PHP. |
4
|
|
|
* |
5
|
|
|
* Copyright (c) 2016 Richard Klees <[email protected]> |
6
|
|
|
* |
7
|
|
|
* This software is licensed under The MIT License. You should have received |
8
|
|
|
* a copy of the license along with the code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Lechimp\Dicto\Graph; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* A query on the IndexDB. |
15
|
|
|
*/ |
16
|
|
|
class IndexQueryImpl extends QueryImpl implements IndexQuery { |
17
|
12 |
|
public function filter_by_types($types) { |
18
|
12 |
|
assert('is_array($types)'); |
19
|
|
|
return $this->filter(function(Node $n) use ($types) { |
20
|
12 |
|
return in_array($n->type(), $types); |
21
|
12 |
|
}); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
*/ |
26
|
1 |
|
public function files() { |
27
|
1 |
|
return $this->filter_by_types(["file"]); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @inheritdocs |
32
|
|
|
*/ |
33
|
2 |
|
public function classes() { |
34
|
2 |
|
return $this->filter_by_types(["class"]); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @inheritdocs |
39
|
|
|
*/ |
40
|
1 |
|
public function methods() { |
41
|
1 |
|
return $this->filter_by_types(["method"]); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @inheritdocs |
46
|
|
|
*/ |
47
|
2 |
|
public function functions() { |
48
|
2 |
|
return $this->filter_by_types(["function"]); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @inheritdocs |
53
|
|
|
*/ |
54
|
20 |
|
public function expand_relation(array $types) { |
55
|
|
|
return $this->expand(function(Node $n) use (&$types) { |
56
|
|
|
return array_filter |
57
|
18 |
|
( $n->relations() |
58
|
|
|
, function(Relation $r) use (&$types) { |
59
|
17 |
|
return in_array($r->type(), $types); |
60
|
18 |
|
}); |
61
|
20 |
|
}); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @inheritdocs |
66
|
|
|
*/ |
67
|
|
|
public function expand_target() { |
68
|
13 |
|
return $this->expand(function(Relation $r) { |
69
|
9 |
|
return [$r->target()]; |
70
|
13 |
|
}); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|