MediaWiki master
FileDependency.php
Go to the documentation of this file.
1<?php
21use Wikimedia\AtEase\AtEase;
22
31 private $filename;
33 private $timestamp;
34
49 public function __construct( $filename, $timestamp = null ) {
50 $this->filename = $filename;
51 $this->timestamp = $timestamp;
52 }
53
57 public function __sleep() {
58 $this->loadDependencyValues();
59
60 return [ 'filename', 'timestamp' ];
61 }
62
63 public function loadDependencyValues() {
64 if ( $this->timestamp === null ) {
65 AtEase::suppressWarnings();
66 # Dependency on a non-existent file stores "false"
67 # This is a valid concept!
68 $this->timestamp = filemtime( $this->filename );
69 AtEase::restoreWarnings();
70 }
71 }
72
73 public function isExpired() {
74 AtEase::suppressWarnings();
75 $lastmod = filemtime( $this->filename );
76 AtEase::restoreWarnings();
77 if ( $lastmod === false ) {
78 if ( $this->timestamp === false ) {
79 # Still nonexistent
80 return false;
81 }
82
83 # Deleted
84 wfDebug( "Dependency triggered: {$this->filename} deleted." );
85
86 return true;
87 }
88
89 if ( $lastmod > $this->timestamp ) {
90 # Modified or created
91 wfDebug( "Dependency triggered: {$this->filename} changed." );
92
93 return true;
94 }
95
96 # Not modified
97 return false;
98 }
99}
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.
loadDependencyValues()
Hook to perform any expensive pre-serialize loading of dependency values.