1 | <?php |
||
30 | class PageProps { |
||
31 | |||
32 | /** |
||
33 | * @var PageProps |
||
34 | */ |
||
35 | private static $instance; |
||
36 | |||
37 | /** |
||
38 | * Overrides the default instance of this class |
||
39 | * This is intended for use while testing and will fail if MW_PHPUNIT_TEST is not defined. |
||
40 | * |
||
41 | * If this method is used it MUST also be called with null after a test to ensure a new |
||
42 | * default instance is created next time getInstance is called. |
||
43 | * |
||
44 | * @since 1.27 |
||
45 | * |
||
46 | * @param PageProps|null $store |
||
47 | * |
||
48 | * @return ScopedCallback to reset the overridden value |
||
49 | * @throws MWException |
||
50 | */ |
||
51 | public static function overrideInstance( PageProps $store = null ) { |
||
63 | |||
64 | /** |
||
65 | * @return PageProps |
||
66 | */ |
||
67 | public static function getInstance() { |
||
73 | |||
74 | /** Cache parameters */ |
||
75 | const CACHE_TTL = 10; // integer; TTL in seconds |
||
76 | const CACHE_SIZE = 100; // integer; max cached pages |
||
77 | |||
78 | /** Property cache */ |
||
79 | private $cache = null; |
||
80 | |||
81 | /** |
||
82 | * Create a PageProps object |
||
83 | */ |
||
84 | private function __construct() { |
||
87 | |||
88 | /** |
||
89 | * Ensure that cache has at least this size |
||
90 | * @param int $size |
||
91 | */ |
||
92 | public function ensureCacheSize( $size ) { |
||
97 | |||
98 | /** |
||
99 | * Given one or more Titles and one or more names of properties, |
||
100 | * returns an associative array mapping page ID to property value. |
||
101 | * Pages in the provided set of Titles that do not have a value for |
||
102 | * the given properties will not appear in the returned array. If a |
||
103 | * single Title is provided, it does not need to be passed in an array, |
||
104 | * but an array will always be returned. If a single property name is |
||
105 | * provided, it does not need to be passed in an array. In that case, |
||
106 | * an associative array mapping page ID to property value will be |
||
107 | * returned; otherwise, an associative array mapping page ID to |
||
108 | * an associative array mapping property name to property value will be |
||
109 | * returned. An empty array will be returned if no matching properties |
||
110 | * were found. |
||
111 | * |
||
112 | * @param Title[]|Title $titles |
||
113 | * @param string[]|string $propertyNames |
||
114 | * @return array associative array mapping page ID to property value |
||
115 | */ |
||
116 | public function getProperties( $titles, $propertyNames ) { |
||
174 | |||
175 | /** |
||
176 | * Get all page property values. |
||
177 | * Given one or more Titles, returns an associative array mapping page |
||
178 | * ID to an associative array mapping property names to property |
||
179 | * values. Pages in the provided set of Titles that do not have any |
||
180 | * properties will not appear in the returned array. If a single Title |
||
181 | * is provided, it does not need to be passed in an array, but an array |
||
182 | * will always be returned. An empty array will be returned if no |
||
183 | * matching properties were found. |
||
184 | * |
||
185 | * @param Title[]|Title $titles |
||
186 | * @return array associative array mapping page ID to property value array |
||
187 | */ |
||
188 | public function getAllProperties( $titles ) { |
||
238 | |||
239 | /** |
||
240 | * @param Title[]|Title $titles |
||
241 | * @return array array of good page IDs |
||
242 | */ |
||
243 | private function getGoodIDs( $titles ) { |
||
260 | |||
261 | /** |
||
262 | * Get a property from the cache. |
||
263 | * |
||
264 | * @param int $pageID page ID of page being queried |
||
265 | * @param string $propertyName name of property being queried |
||
266 | * @return string|bool property value array or false if not found |
||
267 | */ |
||
268 | private function getCachedProperty( $pageID, $propertyName ) { |
||
280 | |||
281 | /** |
||
282 | * Get properties from the cache. |
||
283 | * |
||
284 | * @param int $pageID page ID of page being queried |
||
285 | * @return string|bool property value array or false if not found |
||
286 | */ |
||
287 | private function getCachedProperties( $pageID ) { |
||
293 | |||
294 | /** |
||
295 | * Save a property to the cache. |
||
296 | * |
||
297 | * @param int $pageID page ID of page being cached |
||
298 | * @param string $propertyName name of property being cached |
||
299 | * @param mixed $propertyValue value of property |
||
300 | */ |
||
301 | private function cacheProperty( $pageID, $propertyName, $propertyValue ) { |
||
304 | |||
305 | /** |
||
306 | * Save properties to the cache. |
||
307 | * |
||
308 | * @param int $pageID page ID of page being cached |
||
309 | * @param string[] $pageProperties associative array of page properties to be cached |
||
310 | */ |
||
311 | private function cacheProperties( $pageID, $pageProperties ) { |
||
315 | } |
||
316 |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: