MediaWiki master
FileDependency.php
Go to the documentation of this file.
1<?php
7use Wikimedia\AtEase\AtEase;
8
17 private $filename;
19 private $timestamp;
20
35 public function __construct( $filename, $timestamp = null ) {
36 $this->filename = $filename;
37 $this->timestamp = $timestamp;
38 }
39
43 public function __sleep() {
44 $this->loadDependencyValues();
45
46 return [ 'filename', 'timestamp' ];
47 }
48
49 public function loadDependencyValues() {
50 if ( $this->timestamp === null ) {
51 AtEase::suppressWarnings();
52 # Dependency on a non-existent file stores "false"
53 # This is a valid concept!
54 $this->timestamp = filemtime( $this->filename );
55 AtEase::restoreWarnings();
56 }
57 }
58
60 public function isExpired() {
61 AtEase::suppressWarnings();
62 $lastmod = filemtime( $this->filename );
63 AtEase::restoreWarnings();
64 if ( $lastmod === false ) {
65 if ( $this->timestamp === false ) {
66 # Still nonexistent
67 return false;
68 }
69
70 # Deleted
71 wfDebug( "Dependency triggered: {$this->filename} deleted." );
72
73 return true;
74 }
75
76 if ( $lastmod > $this->timestamp ) {
77 # Modified or created
78 wfDebug( "Dependency triggered: {$this->filename} changed." );
79
80 return true;
81 }
82
83 # Not modified
84 return false;
85 }
86}
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Base class to represent dependencies for LocalisationCache entries.
Depend on a file.
__construct( $filename, $timestamp=null)
Create a file dependency.
isExpired()
Returns true if the dependency is expired, false otherwise.bool
loadDependencyValues()
Hook to perform any expensive pre-serialize loading of dependency values.