1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Code-Insight library. |
4
|
|
|
* For the full copyright and license information, please view |
5
|
|
|
* the LICENSE file that was distributed with this source code. |
6
|
|
|
* |
7
|
|
|
* @copyright Alexander Obuhovich <[email protected]> |
8
|
|
|
* @link https://github.com/console-helpers/code-insight |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace ConsoleHelpers\CodeInsight\KnowledgeBase; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
use ConsoleHelpers\ConsoleKit\ConsoleIO; |
15
|
|
|
use ConsoleHelpers\DatabaseMigration\MigrationContext; |
16
|
|
|
|
17
|
|
|
class KnowledgeBaseFactory |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Database manager. |
22
|
|
|
* |
23
|
|
|
* @var DatabaseManager |
24
|
|
|
*/ |
25
|
|
|
private $_databaseManager; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Create knowledge base factory instance. |
29
|
|
|
* |
30
|
|
|
* @param DatabaseManager $database_manager Database manager. |
31
|
|
|
*/ |
32
|
|
|
public function __construct(DatabaseManager $database_manager) |
33
|
|
|
{ |
34
|
|
|
$this->_databaseManager = $database_manager; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Returns knowledge base for project path. |
39
|
|
|
* |
40
|
|
|
* @param string $project_path Project path. |
41
|
|
|
* @param string|null $fork Fork name. |
42
|
|
|
* @param ConsoleIO $io Console IO. |
43
|
|
|
* |
44
|
|
|
* @return KnowledgeBase |
45
|
|
|
*/ |
46
|
|
|
public function getKnowledgeBase($project_path, $fork = null, ConsoleIO $io = null) |
47
|
|
|
{ |
48
|
|
|
// Gets database for given project path. |
49
|
|
|
$database = $this->_databaseManager->getDatabase($project_path, $fork); |
50
|
|
|
|
51
|
|
|
// Create blank revision log. |
52
|
|
|
$knowledge_base = new KnowledgeBase($project_path, $database, $io); |
53
|
|
|
|
54
|
|
|
// Run migrations (includes initial schema creation). |
55
|
|
|
$context = new MigrationContext($database); |
56
|
|
|
$this->_databaseManager->runMigrations($context); |
57
|
|
|
|
58
|
|
|
return $knowledge_base; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Returns forks for given project. |
63
|
|
|
* |
64
|
|
|
* @param string $project_path Project path. |
65
|
|
|
* |
66
|
|
|
* @return string[] |
67
|
|
|
*/ |
68
|
|
|
public function getForks($project_path) |
69
|
|
|
{ |
70
|
|
|
return $this->_databaseManager->getForks($project_path); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
} |
74
|
|
|
|