MediaWiki REL1_35
FileDependency.php
Go to the documentation of this file.
1<?php
29 private $filename;
30 private $timestamp;
31
46 public function __construct( $filename, $timestamp = null ) {
47 $this->filename = $filename;
48 $this->timestamp = $timestamp;
49 }
50
54 public function __sleep() {
55 $this->loadDependencyValues();
56
57 return [ 'filename', 'timestamp' ];
58 }
59
60 public function loadDependencyValues() {
61 if ( $this->timestamp === null ) {
62 Wikimedia\suppressWarnings();
63 # Dependency on a non-existent file stores "false"
64 # This is a valid concept!
65 $this->timestamp = filemtime( $this->filename );
66 Wikimedia\restoreWarnings();
67 }
68 }
69
73 public function isExpired() {
74 Wikimedia\suppressWarnings();
75 $lastmod = filemtime( $this->filename );
76 Wikimedia\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.
Stable to extend.
__construct( $filename, $timestamp=null)
Create a file dependency.
loadDependencyValues()
Hook to perform any expensive pre-serialize loading of dependency values.