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