1 | <?php |
||
25 | class Engine { |
||
26 | /** |
||
27 | * @var Config |
||
28 | */ |
||
29 | protected $config; |
||
30 | |||
31 | /** |
||
32 | * @var Indexer |
||
33 | */ |
||
34 | protected $indexer; |
||
35 | |||
36 | /** |
||
37 | * @var Analyzer |
||
38 | */ |
||
39 | protected $analyzer; |
||
40 | |||
41 | 3 | public function __construct(Config $config, Indexer $indexer, Analyzer $analyzer) { |
|
42 | 3 | $this->config = $config; |
|
43 | 3 | $this->indexer = $indexer; |
|
44 | 3 | $this->analyzer = $analyzer; |
|
45 | 3 | } |
|
46 | |||
47 | /** |
||
48 | * Run the analysis. |
||
49 | * |
||
50 | * @return null |
||
51 | */ |
||
52 | 3 | public function run() { |
|
53 | 3 | $fc = $this->init_flightcontrol(); |
|
54 | 3 | $fc->directory("/") |
|
55 | 3 | ->recurseOn() |
|
56 | ->filter(function(FSObject $obj) { |
||
57 | 3 | foreach ($this->config->analysis_ignore() as $pattern) { |
|
58 | 3 | if (preg_match("%$pattern%", $obj->path()) !== 0) { |
|
59 | 3 | return false; |
|
60 | } |
||
61 | 3 | } |
|
62 | 3 | return true; |
|
63 | 3 | }) |
|
64 | 3 | ->foldFiles(null, function($_, File $file) { |
|
65 | 3 | echo "indexing: ".$file->path()."\n"; |
|
66 | 3 | $this->indexer->index_file($file->path()); |
|
67 | 3 | }); |
|
68 | 3 | echo "\n\n\n"; |
|
69 | 3 | $this->analyzer->run(); |
|
70 | 3 | } |
|
71 | |||
72 | /** |
||
73 | * Initialize the filesystem abstraction. |
||
74 | * |
||
75 | * @return Flightcontrol |
||
76 | */ |
||
77 | 3 | public function init_flightcontrol() { |
|
82 | } |
||
83 |