|
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 licence along with the code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Lechimp\Dicto\App; |
|
12
|
|
|
|
|
13
|
|
|
use Lechimp\Dicto\Indexer\Indexer; |
|
14
|
|
|
use Lechimp\Dicto\Analysis\Analyzer; |
|
15
|
|
|
use League\Flysystem\Adapter\Local; |
|
16
|
|
|
use League\Flysystem\Filesystem; |
|
17
|
|
|
use Lechimp\Flightcontrol\Flightcontrol; |
|
18
|
|
|
use Lechimp\Flightcontrol\File; |
|
19
|
|
|
use Lechimp\Flightcontrol\FSObject; |
|
20
|
|
|
use Doctrine\DBAL\DriverManager; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* The Engine of the App drives the analysis process. |
|
24
|
|
|
*/ |
|
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() { |
|
78
|
3 |
|
$adapter = new Local($this->config->project_root(), LOCK_EX, Local::SKIP_LINKS); |
|
79
|
3 |
|
$flysystem = new Filesystem($adapter); |
|
80
|
3 |
|
return new Flightcontrol($flysystem); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|