CliApplicationFactory::newApplication()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace Wikibase\QueryEngine\Console;
4
5
use Doctrine\DBAL\Platforms\MySqlPlatform;
6
use Symfony\Component\Console\Application;
7
use Wikibase\QueryEngine\SQLStore\DataValueHandlersBuilder;
8
use Wikibase\QueryEngine\SQLStore\StoreSchema;
9
10
/**
11
 * Builds the QueryEngine CLI application.
12
 * It adds the QueryEngine CLI commands with some demo configuration.
13
 *
14
 * This class is package private. Applications that use QueryEngine
15
 * and that want to include QueryEngine commands in their own CLI
16
 * should use their own Application object.
17
 *
18
 * @licence GNU GPL v2+
19
 * @author Jeroen De Dauw < [email protected] >
20
 */
21
class CliApplicationFactory {
22
23
	/**
24
	 * @var Application
25
	 */
26
	private $app;
27
28
	/**
29
	 * @return Application
30
	 */
31
	public function newApplication() {
32
		$this->app = new Application();
33
34
		$this->setApplicationInfo();
35
		$this->registerCommands();
36
37
		return $this->app;
38
	}
39
40
	private function setApplicationInfo() {
41
		$this->app->setName( 'Wikibase QueryEngine CLI' );
42
		$this->app->setVersion( WIKIBASE_QUERYENGINE_VERSION );
43
	}
44
45
	private function registerCommands() {
46
		$this->app->add( $this->newDumpCommand() );
47
	}
48
49
	private function newDumpCommand() {
50
		$command = new DumpSqlCommand();
51
		$command->setDependencies( $this->getSchema(), new MySqlPlatform() );
52
		return $command;
53
	}
54
55
	private function getSchema() {
56
		$handlerBuilder = new DataValueHandlersBuilder();
57
		$handlers = $handlerBuilder->withSimpleHandlers()->getHandlers();
58
59
		return new StoreSchema( 'qr_', $handlers );
60
	}
61
62
}
63