MediaWiki
REL1_31
SitesCacheFileBuilder.php
Go to the documentation of this file.
1
<?php
2
25
class
SitesCacheFileBuilder
{
26
30
private
$siteLookup
;
31
35
private
$cacheFile
;
36
41
public
function
__construct
(
SiteLookup
$siteLookup
,
$cacheFile
) {
42
$this->siteLookup =
$siteLookup
;
43
$this->cacheFile =
$cacheFile
;
44
}
45
46
public
function
build
() {
47
$this->sites = $this->siteLookup->getSites();
48
$this->
cacheSites
( $this->sites->getArrayCopy() );
49
}
50
57
private
function
cacheSites
( array $sites ) {
58
$sitesArray = [];
59
60
foreach
( $sites as $site ) {
61
$globalId = $site->getGlobalId();
62
$sitesArray[$globalId] = $this->
getSiteAsArray
( $site );
63
}
64
65
$json = json_encode( [
66
'sites'
=> $sitesArray
67
] );
68
69
$result = file_put_contents( $this->cacheFile, $json );
70
71
return
$result !==
false
;
72
}
73
79
private
function
getSiteAsArray
(
Site
$site ) {
80
$siteEntry =
unserialize
( $site->serialize() );
81
$siteIdentifiers = $this->
buildLocalIdentifiers
( $site );
82
$identifiersArray = [];
83
84
foreach
( $siteIdentifiers as $identifier ) {
85
$identifiersArray[] = $identifier;
86
}
87
88
$siteEntry[
'identifiers'
] = $identifiersArray;
89
90
return
$siteEntry;
91
}
92
98
private
function
buildLocalIdentifiers
(
Site
$site ) {
99
$localIds = [];
100
101
foreach
( $site->getLocalIds() as $idType => $ids ) {
102
foreach
( $ids as $id ) {
103
$localIds[] = [
104
'type'
=> $idType,
105
'key'
=> $id
106
];
107
}
108
}
109
110
return
$localIds;
111
}
112
113
}
unserialize
unserialize( $serialized)
Definition
ApiMessage.php:192
Site
Definition
Site.php:29
SitesCacheFileBuilder
Definition
SitesCacheFileBuilder.php:25
SitesCacheFileBuilder\getSiteAsArray
getSiteAsArray(Site $site)
Definition
SitesCacheFileBuilder.php:79
SitesCacheFileBuilder\buildLocalIdentifiers
buildLocalIdentifiers(Site $site)
Definition
SitesCacheFileBuilder.php:98
SitesCacheFileBuilder\build
build()
Definition
SitesCacheFileBuilder.php:46
SitesCacheFileBuilder\__construct
__construct(SiteLookup $siteLookup, $cacheFile)
Definition
SitesCacheFileBuilder.php:41
SitesCacheFileBuilder\$cacheFile
string $cacheFile
Definition
SitesCacheFileBuilder.php:35
SitesCacheFileBuilder\$siteLookup
SiteLookup $siteLookup
Definition
SitesCacheFileBuilder.php:30
SitesCacheFileBuilder\cacheSites
cacheSites(array $sites)
Definition
SitesCacheFileBuilder.php:57
SiteLookup
Definition
SiteLookup.php:28
includes
site
SitesCacheFileBuilder.php
Generated on Mon Nov 25 2024 15:35:21 for MediaWiki by
1.10.0