Completed
Push — master ( 61818c...b240d3 )
by Sam
03:00
created

Repository::setApi()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Xtools;
4
5
use Doctrine\DBAL\Connection;
6
use Mediawiki\Api\MediawikiApi;
7
use Psr\Cache\CacheItemPoolInterface;
8
9
/**
10
 * A repository is responsible for retrieving data from wherever it lives (databases, APIs,
11
 * filesystems, etc.)
12
 */
13
abstract class Repository
14
{
15
16
    /** @var Connection */
17
    protected $metaConnection;
18
19
    /** @var Connection */
20
    protected $projectsConnection;
21
22
    /** @var Connection */
23
    protected $toolsConnection;
24
25
    /** @var CacheItemPoolInterface */
26
    private $cache;
27
28
    /**
29
     * Set the database connection for the 'meta' database.
30
     * @param Connection $connection
31
     */
32
    public function setMetaConnection(Connection $connection)
33
    {
34
        $this->metaConnection = $connection;
35
    }
36
37
    /**
38
     * Set the database connection for the 'projects' database.
39
     * @param Connection $connection
40
     */
41
    public function setProjectsConnection(Connection $connection)
42
    {
43
        $this->projectsConnection = $connection;
44
    }
45
46
    /**
47
     * Set the database connection for the 'tools' database.
48
     * @param Connection $connection
49
     */
50
    public function setToolsConnection(Connection $connection)
51
    {
52
        $this->toolsConnection = $connection;
53
    }
54
55
    /**
56
     * Get the API object for the given project.
57
     * @param Project $project
58
     * @return MediawikiApi
59
     */
60
    protected function getMediawikiApi(Project $project)
61
    {
62
        // @TODO use newFromApiEndpoint instead.
63
        $api = MediawikiApi::newFromPage($project->getUrl());
64
        return $api;
65
    }
66
67
    /**
68
     * Normalize and quote a table name.
69
     *
70
     * @param string $databaseName
71
     * @param string $tableName
72
     * @return string Fully-qualified and quoted table name.
73
     */
74
    public function getTableName($databaseName, $tableName)
75
    {
76
        // @TODO Import from LabsHelper.
77
        return "`$databaseName`.`$tableName`";
78
    }
79
80
    /**
81
     * Set the cache for this repository.
82
     *
83
     * @param CacheItemPoolInterface $pool The cache pool.
84
     */
85
    public function setCache(CacheItemPoolInterface $pool)
86
    {
87
        $this->cache = $pool;
88
    }
89
}
90