MediaWiki master
FileDependency.php
Go to the documentation of this file.
1<?php
15 private $filename;
17 private $timestamp;
18
33 public function __construct( $filename, $timestamp = null ) {
34 $this->filename = $filename;
35 $this->timestamp = $timestamp;
36 }
37
41 public function __sleep() {
42 $this->loadDependencyValues();
43
44 return [ 'filename', 'timestamp' ];
45 }
46
47 public function loadDependencyValues() {
48 if ( $this->timestamp === null ) {
49 # Dependency on a non-existent file stores "false"
50 # This is a valid concept!
51 // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
52 $this->timestamp = @filemtime( $this->filename );
53 }
54 }
55
57 public function isExpired() {
58 // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
59 $lastmod = @filemtime( $this->filename );
60 if ( $lastmod === false ) {
61 if ( $this->timestamp === false ) {
62 # Still nonexistent
63 return false;
64 }
65
66 # Deleted
67 wfDebug( "Dependency triggered: {$this->filename} deleted." );
68
69 return true;
70 }
71
72 if ( $lastmod > $this->timestamp ) {
73 # Modified or created
74 wfDebug( "Dependency triggered: {$this->filename} changed." );
75
76 return true;
77 }
78
79 # Not modified
80 return false;
81 }
82}
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.