Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezexpiryhandler.php
Go to the documentation of this file.
1 <?php
15 class eZExpiryHandler
16 {
17 public function __construct()
18 {
19 $this->Timestamps = array();
20 $this->IsModified = false;
21
22 $cacheDirectory = eZSys::cacheDirectory();
23 $this->CacheFile = eZClusterFileHandler::instance( $cacheDirectory . '/' . 'expiry.php' );
24 $this->restore();
25 }
26
32 function restore()
33 {
34 $Timestamps = $this->CacheFile->processFile( array( $this, 'fetchData' ) );
35 if ( $Timestamps === false )
36 {
37 $errMsg = 'Fatal error - could not restore expiry.php file.';
38 eZDebug::writeError( $errMsg, __METHOD__ );
39 trigger_error( $errMsg, E_USER_ERROR );
40 }
41
42 $this->Timestamps = $Timestamps;
43 $this->IsModified = false;
44 }
45
50 static function fetchData( $path )
51 {
52 include( $path );
53 return $Timestamps;
54 }
55
59 function store()
60 {
61 if ( !$this->IsModified )
62 {
63 return;
64 }
65
66 // EZP-23908: Restore timestamps before saving, to reduce chance of race condition issues
67 $modifiedTimestamps = $this->Timestamps;
68 $this->restore();
69
70 // Apply timestamps that have been added or modified in this process
71 foreach ( $modifiedTimestamps as $name => $value )
72 {
73 if ( $value > self::getTimestamp( $name, 0 ) )
74 {
75 $this->setTimestamp( $name, $value );
76 }
77 }
78
79 if ( $this->IsModified )
80 {
81 $this->CacheFile->storeContents( "<?php\n\$Timestamps = " . var_export( $this->Timestamps, true ) . ";\n?>", 'expirycache', false, true );
82 $this->IsModified = false;
83 }
84 }
85
92 function setTimestamp( $name, $value )
93 {
94 $this->Timestamps[$name] = $value;
95 $this->IsModified = true;
96 }
97
105 function hasTimestamp( $name )
106 {
107 return isset( $this->Timestamps[$name] );
108 }
109
117 function timestamp( $name )
118 {
119 if ( !isset( $this->Timestamps[$name] ) )
120 {
121 eZDebug::writeError( "Unknown expiry timestamp called '$name'", __METHOD__ );
122 return false;
123 }
124 return $this->Timestamps[$name];
125 }
126
135 static function getTimestamp( $name, $default = false )
136 {
137 $handler = eZExpiryHandler::instance();
138 if ( !isset( $handler->Timestamps[$name] ) )
139 {
140 return $default;
141 }
142 return $handler->Timestamps[$name];
143 }
144
150 static function instance()
151 {
152 if ( !isset( $GLOBALS['eZExpiryHandlerInstance'] ) ||
153 !( $GLOBALS['eZExpiryHandlerInstance'] instanceof eZExpiryHandler ) )
154 {
155 $GLOBALS['eZExpiryHandlerInstance'] = new eZExpiryHandler();
156 }
157
158 return $GLOBALS['eZExpiryHandlerInstance'];
159 }
160
166 static function hasInstance()
167 {
168 return isset( $GLOBALS['eZExpiryHandlerInstance'] ) && $GLOBALS['eZExpiryHandlerInstance'] instanceof eZExpiryHandler;
169 }
170
174 static function shutdown()
175 {
176 if ( eZExpiryHandler::hasInstance() )
177 {
178 eZExpiryHandler::instance()->store();
179 }
180 }
181
187 public static function registerShutdownFunction(){
188 eZDebug::writeStrict( __METHOD__ . " is deprecated. See EZP-22749.", __METHOD__ . " is deprecated" );
189 }
190
195 public $Timestamps;
196
201 public $IsModified;
202
203 public $CacheFile;
204
205 }
206
207 ?>
eZClusterFileHandler\instance
static instance( $filename=false)
Definition: ezclusterfilehandler.php:21
eZDebug\writeStrict
static writeStrict( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:414
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZExpiryHandler
eZSys\cacheDirectory
static cacheDirectory()
Definition: ezsys.php:527
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.