Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
DependencyStore
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 3
12
0.00% covered (danger)
0.00%
0 / 1
 newEntityDependencies
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 retrieve
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 retrieveMulti
n/a
0 / 0
n/a
0 / 0
0
 store
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 storeMulti
n/a
0 / 0
n/a
0 / 0
0
 remove
n/a
0 / 0
n/a
0 / 0
0
1<?php
2/**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21namespace Wikimedia\DependencyStore;
22
23/**
24 * Track per-module dependency file paths that are expensive to mass compute
25 *
26 * @internal For use by ResourceLoader\Module only
27 */
28abstract class DependencyStore {
29    /** @var string */
30    protected const KEY_PATHS = 'paths';
31    /** @var string */
32    protected const KEY_AS_OF = 'asOf';
33
34    /**
35     * @param string[] $paths List of dependency paths
36     * @param int|null $asOf UNIX timestamp or null
37     * @return array
38     */
39    public function newEntityDependencies( array $paths = [], $asOf = null ) {
40        return [ self::KEY_PATHS => $paths, self::KEY_AS_OF => $asOf ];
41    }
42
43    /**
44     * Get the currently tracked dependencies for an entity
45     *
46     * The "paths" field contains a sorted list of unique paths
47     *
48     * The "asOf" field reflects the last-modified timestamp of the dependency data itself.
49     * It will be null if there is no tracking data available. Note that if empty path lists
50     * are never stored (as an optimisation) then it will not be possible to discern whether
51     * the result is up-to-date.
52     *
53     * @param string $type Entity type
54     * @param string $entity Entity name
55     * @return array Map of (paths: paths, asOf: UNIX timestamp or null)
56     */
57    final public function retrieve( $type, $entity ) {
58        return $this->retrieveMulti( $type, [ $entity ] )[$entity];
59    }
60
61    /**
62     * Get the currently tracked dependencies for a set of entities
63     *
64     * @see KeyValueDependencyStore::retrieve()
65     * @param string $type Entity type
66     * @param string[] $entities Entity names
67     * @return array[] Map of (entity => (paths: paths, asOf: UNIX timestamp or null))
68     */
69    abstract public function retrieveMulti( $type, array $entities );
70
71    /**
72     * Set the currently tracked dependencies for an entity
73     *
74     * @param string $type Entity type
75     * @param string $entity Entity name
76     * @param array $data Map of (paths: paths, asOf: UNIX timestamp or null)
77     * @param int $ttl New time-to-live in seconds
78     */
79    final public function store( $type, $entity, array $data, $ttl ) {
80        $this->storeMulti( $type, [ $entity => $data ], $ttl );
81    }
82
83    /**
84     * Set the currently tracked dependencies for a set of entities
85     *
86     * @see KeyValueDependencyStore::store()
87     * @param string $type Entity type
88     * @param array[] $dataByEntity Map of (entity => (paths: paths, asOf: UNIX timestamp or null))
89     * @param int $ttl New time-to-live in seconds
90     *
91     */
92    abstract public function storeMulti( $type, array $dataByEntity, $ttl );
93
94    /**
95     * Delete the currently tracked dependencies for an entity or set of entities
96     *
97     * @param string $type Entity type
98     * @param string|string[] $entities Entity name(s)
99     */
100    abstract public function remove( $type, $entities );
101}