Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Zend_Cache_Frontend_Page Class Reference
Inheritance diagram for Zend_Cache_Frontend_Page:
Zend_Cache_Core

Public Member Functions

 __construct (array $options=array())
 
 start ($id=false, $doNotDie=false)
 
 cancel ()
 
 _flush ($data)
 
- Public Member Functions inherited from Zend_Cache_Core
 __construct ($options=array())
 
 setConfig (Zend_Config $config)
 
 setBackend (Zend_Cache_Backend $backendObject)
 
 getBackend ()
 
 setOption ($name, $value)
 
 getOption ($name)
 
 setLifetime ($newLifetime)
 
 load ($id, $doNotTestCacheValidity=false, $doNotUnserialize=false)
 
 test ($id)
 
 save ($data, $id=null, $tags=array(), $specificLifetime=false, $priority=8)
 
 remove ($id)
 
 clean ($mode='all', $tags=array())
 
 getIdsMatchingTags ($tags=array())
 
 getIdsNotMatchingTags ($tags=array())
 
 getIdsMatchingAnyTags ($tags=array())
 
 getIds ()
 
 getTags ()
 
 getFillingPercentage ()
 
 getMetadatas ($id)
 
 touch ($id, $extraLifetime)
 

Protected Member Functions

 _setDefaultOptions ($options)
 
 _setContentTypeMemorization ($value)
 
 _setRegexps ($regexps)
 
 _makeId ()
 
 _makePartialId ($arrayName, $bool1, $bool2)
 
- Protected Member Functions inherited from Zend_Cache_Core
 _validateIdOrTag ($string)
 
 _validateTagsArray ($tags)
 
 _loggerSanity ()
 
 _log ($message, $priority=4)
 
 _id ($id)
 

Protected Attributes

 $_specificOptions
 
 $_activeOptions = array()
 
 $_cancel = false
 
- Protected Attributes inherited from Zend_Cache_Core
 $_backend = null
 
 $_options
 
 $_specificOptions = array()
 
 $_extendedBackend = false
 
 $_backendCapabilities = array()
 

Additional Inherited Members

- Data Fields inherited from Zend_Cache_Core
const BACKEND_NOT_SUPPORTS_TAG = 'tags are not supported by the current backend'
 
const BACKEND_NOT_IMPLEMENTS_EXTENDED_IF = 'Current backend doesn\'t implement the Zend_Cache_Backend_ExtendedInterface, so this method is not available'
 
- Static Protected Attributes inherited from Zend_Cache_Core
static $_directivesList = array('lifetime', 'logging', 'logger')
 

Detailed Description

Definition at line 36 of file Page.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( array  $options = array())

Constructor

Parameters
array$optionsAssociative array of options
boolean$doNotTestCacheValidityIf set to true, the cache validity won't be tested
Exceptions
Zend_Cache_Exception
Returns
void

Definition at line 130 of file Page.php.

131  {
132  foreach ($options as $name => $value) {
133  $name = strtolower($name);
134  switch ($name) {
135  case 'regexps':
136  $this->_setRegexps($value);
137  break;
138  case 'default_options':
139  $this->_setDefaultOptions($value);
140  break;
141  case 'content_type_memorization':
143  break;
144  default:
145  $this->setOption($name, $value);
146  }
147  }
148  if (isset($this->_specificOptions['http_conditional'])) {
149  if ($this->_specificOptions['http_conditional']) {
150  Zend_Cache::throwException('http_conditional is not implemented for the moment !');
151  }
152  }
153  $this->setOption('automatic_serialization', true);
154  }
_setContentTypeMemorization($value)
Definition: Page.php:186
setOption($name, $value)
Definition: Core.php:211
$value
Definition: gender.phtml:16
_setRegexps($regexps)
Definition: Page.php:212
static throwException($msg, Exception $e=null)
Definition: Cache.php:205
_setDefaultOptions($options)
Definition: Page.php:163
if(!isset($_GET['name'])) $name
Definition: log.php:14

Member Function Documentation

◆ _flush()

_flush (   $data)

callback for output buffering (shouldn't really be called manually)

Parameters
string$dataBuffered output
Returns
string Data to send to browser

Definition at line 309 of file Page.php.

310  {
311  if ($this->_cancel) {
312  return $data;
313  }
314  $contentType = null;
315  $storedHeaders = array();
316  $headersList = headers_list();
317  foreach($this->_specificOptions['memorize_headers'] as $key=>$headerName) {
318  foreach ($headersList as $headerSent) {
319  $tmp = explode(':', $headerSent);
320  $headerSentName = trim(array_shift($tmp));
321  if (strtolower($headerName) == strtolower($headerSentName)) {
322  $headerSentValue = trim(implode(':', $tmp));
323  $storedHeaders[] = array($headerSentName, $headerSentValue);
324  }
325  }
326  }
327  $array = array(
328  'data' => $data,
329  'headers' => $storedHeaders
330  );
331  $this->save($array, null, $this->_activeOptions['tags'], $this->_activeOptions['specific_lifetime'], $this->_activeOptions['priority']);
332  return $data;
333  }
save($data, $id=null, $tags=array(), $specificLifetime=false, $priority=8)
Definition: Core.php:348

◆ _makeId()

_makeId ( )
protected

Make an id depending on REQUEST_URI and superglobal arrays (depending on options)

Returns
mixed|false a cache id (string), false if the cache should have not to be used

Definition at line 340 of file Page.php.

341  {
342  $tmp = $_SERVER['REQUEST_URI'];
343  $array = explode('?', $tmp, 2);
344  $tmp = $array[0];
345  foreach (array('Get', 'Post', 'Session', 'Files', 'Cookie') as $arrayName) {
346  $tmp2 = $this->_makePartialId($arrayName, $this->_activeOptions['cache_with_' . strtolower($arrayName) . '_variables'], $this->_activeOptions['make_id_with_' . strtolower($arrayName) . '_variables']);
347  if ($tmp2===false) {
348  return false;
349  }
350  $tmp = $tmp . $tmp2;
351  }
352  return md5($tmp);
353  }
_makePartialId($arrayName, $bool1, $bool2)
Definition: Page.php:363

◆ _makePartialId()

_makePartialId (   $arrayName,
  $bool1,
  $bool2 
)
protected

Make a partial id depending on options

Parameters
string$arrayNameSuperglobal array name
bool$bool1If true, cache is still on even if there are some variables in the superglobal array
bool$bool2If true, we have to use the content of the superglobal array to make a partial id
Returns
mixed|false Partial id (string) or false if the cache should have not to be used

Definition at line 363 of file Page.php.

364  {
365  switch ($arrayName) {
366  case 'Get':
367  $var = $_GET;
368  break;
369  case 'Post':
370  $var = $_POST;
371  break;
372  case 'Session':
373  if (isset($_SESSION)) {
374  $var = $_SESSION;
375  } else {
376  $var = null;
377  }
378  break;
379  case 'Cookie':
380  if (isset($_COOKIE)) {
381  $var = $_COOKIE;
382  } else {
383  $var = null;
384  }
385  break;
386  case 'Files':
387  $var = $_FILES;
388  break;
389  default:
390  return false;
391  }
392  if ($bool1) {
393  if ($bool2) {
394  return serialize($var);
395  }
396  return '';
397  }
398  if (is_array($var) && count($var) > 0) {
399  return false;
400  }
401  return '';
402  }

◆ _setContentTypeMemorization()

_setContentTypeMemorization (   $value)
protected

Set the deprecated contentTypeMemorization option

Parameters
boolean$valuevalue
Returns
void
Deprecated:

Definition at line 186 of file Page.php.

187  {
188  $found = null;
189  foreach ($this->_specificOptions['memorize_headers'] as $key => $value) {
190  if (strtolower($value) == 'content-type') {
191  $found = $key;
192  }
193  }
194  if ($value) {
195  if (!$found) {
196  $this->_specificOptions['memorize_headers'][] = 'Content-Type';
197  }
198  } else {
199  if ($found) {
200  unset($this->_specificOptions['memorize_headers'][$found]);
201  }
202  }
203  }
$value
Definition: gender.phtml:16

◆ _setDefaultOptions()

_setDefaultOptions (   $options)
protected

Specific setter for the 'default_options' option (with some additional tests)

Parameters
array$optionsAssociative array
Exceptions
Zend_Cache_Exception
Returns
void

Definition at line 163 of file Page.php.

164  {
165  if (!is_array($options)) {
166  Zend_Cache::throwException('default_options must be an array !');
167  }
168  foreach ($options as $key=>$value) {
169  if (!is_string($key)) {
170  Zend_Cache::throwException("invalid option [$key] !");
171  }
172  $key = strtolower($key);
173  if (isset($this->_specificOptions['default_options'][$key])) {
174  $this->_specificOptions['default_options'][$key] = $value;
175  }
176  }
177  }
$value
Definition: gender.phtml:16
static throwException($msg, Exception $e=null)
Definition: Cache.php:205

◆ _setRegexps()

_setRegexps (   $regexps)
protected

Specific setter for the 'regexps' option (with some additional tests)

Parameters
array$optionsAssociative array
Exceptions
Zend_Cache_Exception
Returns
void

Definition at line 212 of file Page.php.

213  {
214  if (!is_array($regexps)) {
215  Zend_Cache::throwException('regexps option must be an array !');
216  }
217  foreach ($regexps as $regexp=>$conf) {
218  if (!is_array($conf)) {
219  Zend_Cache::throwException('regexps option must be an array of arrays !');
220  }
221  $validKeys = array_keys($this->_specificOptions['default_options']);
222  foreach ($conf as $key=>$value) {
223  if (!is_string($key)) {
224  Zend_Cache::throwException("unknown option [$key] !");
225  }
226  $key = strtolower($key);
227  if (!in_array($key, $validKeys)) {
228  unset($regexps[$regexp][$key]);
229  }
230  }
231  }
232  $this->setOption('regexps', $regexps);
233  }
setOption($name, $value)
Definition: Core.php:211
$value
Definition: gender.phtml:16
static throwException($msg, Exception $e=null)
Definition: Cache.php:205

◆ cancel()

cancel ( )

Cancel the current caching process

Definition at line 297 of file Page.php.

298  {
299  $this->_cancel = true;
300  }

◆ start()

start (   $id = false,
  $doNotDie = false 
)

Start the cache

Parameters
string$id(optional) A cache id (if you set a value here, maybe you have to use Output frontend instead)
boolean$doNotDieFor unit testing only !
Returns
boolean True if the cache is hit (false else)

Definition at line 242 of file Page.php.

243  {
244  $this->_cancel = false;
245  $lastMatchingRegexp = null;
246  if (isset($_SERVER['REQUEST_URI'])) {
247  foreach ($this->_specificOptions['regexps'] as $regexp => $conf) {
248  if (preg_match("`$regexp`", $_SERVER['REQUEST_URI'])) {
249  $lastMatchingRegexp = $regexp;
250  }
251  }
252  }
253  $this->_activeOptions = $this->_specificOptions['default_options'];
254  if ($lastMatchingRegexp !== null) {
255  $conf = $this->_specificOptions['regexps'][$lastMatchingRegexp];
256  foreach ($conf as $key=>$value) {
257  $this->_activeOptions[$key] = $value;
258  }
259  }
260  if (!($this->_activeOptions['cache'])) {
261  return false;
262  }
263  if (!$id) {
264  $id = $this->_makeId();
265  if (!$id) {
266  return false;
267  }
268  }
269  $array = $this->load($id);
270  if ($array !== false) {
271  $data = $array['data'];
272  $headers = $array['headers'];
273  if (!headers_sent()) {
274  foreach ($headers as $key=>$headerCouple) {
275  $name = $headerCouple[0];
276  $value = $headerCouple[1];
277  header("$name: $value");
278  }
279  }
280  if ($this->_specificOptions['debug_header']) {
281  echo 'DEBUG HEADER : This is a cached page !';
282  }
283  echo $data;
284  if ($doNotDie) {
285  return true;
286  }
287  die();
288  }
289  ob_start(array($this, '_flush'));
290  ob_implicit_flush(false);
291  return false;
292  }
$id
Definition: fieldset.phtml:14
$value
Definition: gender.phtml:16
load($id, $doNotTestCacheValidity=false, $doNotUnserialize=false)
Definition: Core.php:296
if(!isset($_GET['name'])) $name
Definition: log.php:14

Field Documentation

◆ $_activeOptions

$_activeOptions = array()
protected

Definition at line 113 of file Page.php.

◆ $_cancel

$_cancel = false
protected

Definition at line 120 of file Page.php.

◆ $_specificOptions

$_specificOptions
protected
Initial value:
= array(
'http_conditional' => false,
'debug_header' => false,
'content_type_memorization' => false,
'memorize_headers' => array(),
'default_options' => array(
'cache_with_get_variables' => false,
'cache_with_post_variables' => false,
'cache_with_session_variables' => false,
'cache_with_files_variables' => false,
'cache_with_cookie_variables' => false,
'make_id_with_get_variables' => true,
'make_id_with_post_variables' => true,
'make_id_with_session_variables' => true,
'make_id_with_files_variables' => true,
'make_id_with_cookie_variables' => true,
'cache' => true,
'specific_lifetime' => false,
'tags' => array(),
'priority' => null
),
'regexps' => array()
)

Definition at line 84 of file Page.php.


The documentation for this class was generated from the following file: