Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
32 / 32
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
ManifestGenerator
100.00% covered (success)
100.00%
32 / 32
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
 generate
100.00% covered (success)
100.00%
24 / 24
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace MediaWiki\Extension\WikibaseManifest;
4
5use Config;
6
7class ManifestGenerator {
8
9    public const NAME = 'name';
10    public const ROOT_SCRIPT_URL = 'root_script_url';
11    public const MAIN_PAGE_URL = 'main_page_url';
12    public const API = 'api';
13    public const API_ACTION = 'action';
14    public const API_REST = 'rest';
15    public const EQUIV_ENTITIES = 'equiv_entities';
16    public const WIKIDATA_ORG = 'wikidata.org';
17    public const LOCAL_RDF_NAMESPACES = 'local_rdf_namespaces';
18    public const EXTERNAL_SERVICES = 'external_services';
19    public const LOCAL_ENTITIES = 'local_entities';
20    public const MAX_LAG = 'max_lag';
21    private const OAUTH = 'oauth';
22    private const OAUTH_REGISTRATION_PAGE = 'registration_page';
23
24    private $config;
25    private $mainPageUrl;
26    private $equivEntitiesFactory;
27    private $conceptNamespaces;
28    private $externalServicesFactory;
29    private $entityNamespacesFactory;
30    private $maxLagFactory;
31    private $oAuthUrlFactory;
32
33    public function __construct(
34        Config $config,
35        TitleFactoryMainPageUrl $mainPageUrl,
36        EquivEntitiesFactory $equivEntitiesFactory,
37        ConceptNamespaces $conceptNamespaces,
38        ExternalServicesFactory $externalServicesFactory,
39        EntityNamespacesFactory $entityNamespacesFactory,
40        MaxLagFactory $maxLagFactory,
41        OAuthUrlFactory $oAuthUrlFactory
42    ) {
43        $this->config = $config;
44        $this->mainPageUrl = $mainPageUrl;
45        $this->equivEntitiesFactory = $equivEntitiesFactory;
46        $this->conceptNamespaces = $conceptNamespaces;
47        $this->externalServicesFactory = $externalServicesFactory;
48        $this->entityNamespacesFactory = $entityNamespacesFactory;
49        $this->maxLagFactory = $maxLagFactory;
50        $this->oAuthUrlFactory = $oAuthUrlFactory;
51    }
52
53    public function generate(): array {
54        $config = $this->config;
55
56        $localRdfNamespaces = $this->conceptNamespaces->getLocal();
57        $externalServices = $this->externalServicesFactory->getExternalServices()->toArray();
58        $localEntities = $this->entityNamespacesFactory->getEntityNamespaces()->toArray();
59        $equivEntities = $this->equivEntitiesFactory->getEquivEntities()->toArray();
60
61        return [
62            self::NAME => $config->get( 'Sitename' ),
63            self::ROOT_SCRIPT_URL => $config->get( 'Server' ) . $config->get( 'ScriptPath' ),
64            self::MAIN_PAGE_URL => $this->mainPageUrl->getValue(),
65            self::MAX_LAG => $this->maxLagFactory->getMaxLag()->getValue(),
66            self::API => [
67                self::API_ACTION => $config->get( 'Server' ) . $config->get( 'ScriptPath' ) . '/api.php',
68                self::API_REST => $config->get( 'Server' ) . $config->get( 'ScriptPath' ) . '/rest.php'
69            ],
70            self::EQUIV_ENTITIES => [
71                self::WIKIDATA_ORG => $equivEntities
72            ],
73            self::LOCAL_RDF_NAMESPACES => $localRdfNamespaces,
74            self::EXTERNAL_SERVICES => $externalServices,
75            self::LOCAL_ENTITIES => $localEntities,
76            self::OAUTH => [
77                self::OAUTH_REGISTRATION_PAGE => $this->oAuthUrlFactory->getOAuthUrl()->getValue()
78            ]
79        ];
80    }
81}