Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezexpiryhandler.php
Go to the documentation of this file.
1 <?php
16 class eZExpiryHandler
17 {
18 public function __construct()
19 {
20 $this->Timestamps = array();
21 $this->IsModified = false;
22
23 $cacheDirectory = eZSys::cacheDirectory();
24 $this->CacheFile = eZClusterFileHandler::instance( $cacheDirectory . '/' . 'expiry.php' );
25
26 if( $this->CacheFile !== false )
27 $this->restore();
28 }
29
35 function restore()
36 {
37 $Timestamps = $this->CacheFile->processFile( array( $this, 'fetchData' ) );
38 if ( $Timestamps === false )
39 {
40 $errMsg = 'Fatal error - could not restore expiry.php file.';
41 eZDebug::writeError( $errMsg, __METHOD__ );
42 trigger_error( $errMsg, E_USER_ERROR );
43 }
44
45 $this->Timestamps = $Timestamps;
46 $this->IsModified = false;
47 }
48
53 static function fetchData( $path )
54 {
55 include( $path );
56 return $Timestamps;
57 }
58
62 function store()
63 {
64 if ( !$this->IsModified )
65 {
66 return;
67 }
68
69 // EZP-23908: Restore timestamps before saving, to reduce chance of race condition issues
70 $modifiedTimestamps = $this->Timestamps;
71 $this->restore();
72
73 // Apply timestamps that have been added or modified in this process
74 foreach ( $modifiedTimestamps as $name => $value )
75 {
76 if ( $value > self::getTimestamp( $name, 0 ) )
77 {
78 $this->setTimestamp( $name, $value );
79 }
80 }
81
82 if ( $this->IsModified )
83 {
84 $this->CacheFile->storeContents( "<?php\n\$Timestamps = " . var_export( $this->Timestamps, true ) . ";\n?>", 'expirycache', false, true );
85 $this->IsModified = false;
86 }
87 }
88
95 function setTimestamp( $name, $value )
96 {
97 $this->Timestamps[$name] = $value;
98 $this->IsModified = true;
99 }
100
108 function hasTimestamp( $name )
109 {
110 return isset( $this->Timestamps[$name] );
111 }
112
120 function timestamp( $name )
121 {
122 if ( !isset( $this->Timestamps[$name] ) )
123 {
124 eZDebug::writeError( "Unknown expiry timestamp called '$name'", __METHOD__ );
125 return false;
126 }
127 return $this->Timestamps[$name];
128 }
129
138 static function getTimestamp( $name, $default = false )
139 {
140 $handler = eZExpiryHandler::instance();
141 if ( !isset( $handler->Timestamps[$name] ) )
142 {
143 return $default;
144 }
145 return $handler->Timestamps[$name];
146 }
147
153 static function instance()
154 {
155 if ( !isset( $GLOBALS['eZExpiryHandlerInstance'] ) ||
156 !( $GLOBALS['eZExpiryHandlerInstance'] instanceof eZExpiryHandler ) )
157 {
158 $GLOBALS['eZExpiryHandlerInstance'] = new eZExpiryHandler();
159 }
160
161 return $GLOBALS['eZExpiryHandlerInstance'];
162 }
163
169 static function hasInstance()
170 {
171 return isset( $GLOBALS['eZExpiryHandlerInstance'] ) && $GLOBALS['eZExpiryHandlerInstance'] instanceof eZExpiryHandler;
172 }
173
177 static function shutdown()
178 {
179 if ( eZExpiryHandler::hasInstance() )
180 {
181 eZExpiryHandler::instance()->store();
182 }
183 }
184
190 public static function registerShutdownFunction(){
191 eZDebug::writeStrict( __METHOD__ . " is deprecated. See EZP-22749.", __METHOD__ . " is deprecated" );
192 }
193
198 public $Timestamps;
199
204 public $IsModified;
205
206 public $CacheFile;
207
208 }
209
210 ?>
eZClusterFileHandler\instance
static instance( $filename=false)
Definition: ezclusterfilehandler.php:22
eZDebug\writeStrict
static writeStrict( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:415
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:546
eZExpiryHandler
eZSys\cacheDirectory
static cacheDirectory()
Definition: ezsys.php:528
$name
$name
Definition: companytypelist.php:194
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.