Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Zend_Cache_Backend Class Reference
Inheritance diagram for Zend_Cache_Backend:
Database AbstractDecorator Eaccelerator MongoDb RemoteSynchronizedCache CoreTestMock Zend_Cache_Backend_Apc Zend_Cache_Backend_BlackHole Zend_Cache_Backend_File Zend_Cache_Backend_Libmemcached Zend_Cache_Backend_Memcached Zend_Cache_Backend_Static Zend_Cache_Backend_Test Zend_Cache_Backend_TwoLevels Zend_Cache_Backend_WinCache Zend_Cache_Backend_Xcache Zend_Cache_Backend_ZendPlatform Zend_Cache_Backend_ZendServer

Public Member Functions

 __construct (array $options=array())
 
 setDirectives ($directives)
 
 setOption ($name, $value)
 
 getOption ($name)
 
 getLifetime ($specificLifetime)
 
 isAutomaticCleaningAvailable ()
 
 getTmpDir ()
 

Protected Member Functions

 _isGoodTmpDir ($dir)
 
 _loggerSanity ()
 
 _log ($message, $priority=4)
 

Protected Attributes

 $_directives
 
 $_options = array()
 

Detailed Description

Definition at line 30 of file Backend.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( array  $options = array())

Constructor

Parameters
array$optionsAssociative array of options

Definition at line 62 of file Backend.php.

63  {
64  foreach ($options as $name => $value) {
65  $this->setOption($name, $value);
66  }
67  }
setOption($name, $value)
Definition: Backend.php:101
$value
Definition: gender.phtml:16
if(!isset($_GET['name'])) $name
Definition: log.php:14

Member Function Documentation

◆ _isGoodTmpDir()

_isGoodTmpDir (   $dir)
protected

Verify if the given temporary directory is readable and writable

Parameters
string$dirtemporary directory
Returns
boolean true if the directory is ok

Definition at line 226 of file Backend.php.

227  {
228  if (is_readable($dir)) {
229  if (is_writable($dir)) {
230  return true;
231  }
232  }
233  return false;
234  }
is_writable($path)
Definition: io.php:25

◆ _log()

_log (   $message,
  $priority = 4 
)
protected

Log a message at the WARN (4) priority.

Parameters
string$message
int$priority
Returns
void

Definition at line 273 of file Backend.php.

274  {
275  if (!$this->_directives['logging']) {
276  return;
277  }
278 
279  if (!isset($this->_directives['logger'])) {
280  Zend_Cache::throwException('Logging is enabled but logger is not set.');
281  }
282  $logger = $this->_directives['logger'];
283  if (!$logger instanceof Zend_Log) {
284  Zend_Cache::throwException('Logger object is not an instance of Zend_Log class.');
285  }
286  $logger->log($message, $priority);
287  }
$message
$logger
static throwException($msg, Exception $e=null)
Definition: Cache.php:205

◆ _loggerSanity()

_loggerSanity ( )
protected

Make sure if we enable logging that the Zend_Log class is available. Create a default log object if none is set.

Exceptions
Zend_Cache_Exception
Returns
void

Definition at line 244 of file Backend.php.

245  {
246  if (!isset($this->_directives['logging']) || !$this->_directives['logging']) {
247  return;
248  }
249 
250  if (isset($this->_directives['logger'])) {
251  if ($this->_directives['logger'] instanceof Zend_Log) {
252  return;
253  }
254  Zend_Cache::throwException('Logger object is not an instance of Zend_Log class.');
255  }
256 
257  // Create a default logger to the standard output stream
258  #require_once 'Zend/Log.php';
259  #require_once 'Zend/Log/Writer/Stream.php';
260  #require_once 'Zend/Log/Filter/Priority.php';
261  $logger = new Zend_Log(new Zend_Log_Writer_Stream('php://output'));
262  $logger->addFilter(new Zend_Log_Filter_Priority(Zend_Log::WARN, '<='));
263  $this->_directives['logger'] = $logger;
264  }
const WARN
Definition: Log.php:46
$logger
static throwException($msg, Exception $e=null)
Definition: Cache.php:205

◆ getLifetime()

getLifetime (   $specificLifetime)

Get the life time

if $specificLifetime is not false, the given specific life time is used else, the global lifetime is used

Parameters
int$specificLifetime
Returns
int Cache life time

Definition at line 143 of file Backend.php.

144  {
145  if ($specificLifetime === false) {
146  return $this->_directives['lifetime'];
147  }
148  return $specificLifetime;
149  }

◆ getOption()

getOption (   $name)

Returns an option

Parameters
string$nameOptional, the options name to return
Exceptions
Zend_Cache_Exceptions
Returns
mixed

Definition at line 119 of file Backend.php.

120  {
121  $name = strtolower($name);
122 
123  if (array_key_exists($name, $this->_options)) {
124  return $this->_options[$name];
125  }
126 
127  if (array_key_exists($name, $this->_directives)) {
128  return $this->_directives[$name];
129  }
130 
131  Zend_Cache::throwException("Incorrect option name : {$name}");
132  }
static throwException($msg, Exception $e=null)
Definition: Cache.php:205
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ getTmpDir()

getTmpDir ( )

Determine system TMP directory and detect if we have read access

inspired from Zend_File_Transfer_Adapter_Abstract

Returns
string
Exceptions
Zend_Cache_Exceptionif unable to determine directory

Definition at line 172 of file Backend.php.

173  {
174  $tmpdir = array();
175  foreach (array($_ENV, $_SERVER) as $tab) {
176  foreach (array('TMPDIR', 'TEMP', 'TMP', 'windir', 'SystemRoot') as $key) {
177  if (isset($tab[$key]) && is_string($tab[$key])) {
178  if (($key == 'windir') or ($key == 'SystemRoot')) {
179  $dir = realpath($tab[$key] . '\\temp');
180  } else {
181  $dir = realpath($tab[$key]);
182  }
183  if ($this->_isGoodTmpDir($dir)) {
184  return $dir;
185  }
186  }
187  }
188  }
189  $upload = ini_get('upload_tmp_dir');
190  if ($upload) {
191  $dir = realpath($upload);
192  if ($this->_isGoodTmpDir($dir)) {
193  return $dir;
194  }
195  }
196  if (function_exists('sys_get_temp_dir')) {
197  $dir = sys_get_temp_dir();
198  if ($this->_isGoodTmpDir($dir)) {
199  return $dir;
200  }
201  }
202  // Attemp to detect by creating a temporary file
203  $tempFile = tempnam(md5(uniqid(rand(), TRUE)), '');
204  if ($tempFile) {
205  $dir = realpath(dirname($tempFile));
206  unlink($tempFile);
207  if ($this->_isGoodTmpDir($dir)) {
208  return $dir;
209  }
210  }
211  if ($this->_isGoodTmpDir('/tmp')) {
212  return '/tmp';
213  }
214  if ($this->_isGoodTmpDir('\\temp')) {
215  return '\\temp';
216  }
217  Zend_Cache::throwException('Could not determine temp directory, please specify a cache_dir manually');
218  }
static throwException($msg, Exception $e=null)
Definition: Cache.php:205

◆ isAutomaticCleaningAvailable()

isAutomaticCleaningAvailable ( )

Return true if the automatic cleaning is available for the backend

DEPRECATED : use getCapabilities() instead

Deprecated:
Returns
boolean

Definition at line 159 of file Backend.php.

160  {
161  return true;
162  }

◆ setDirectives()

setDirectives (   $directives)

Set the frontend directives

Parameters
array$directivesAssoc of directives
Exceptions
Zend_Cache_Exception
Returns
void

Definition at line 76 of file Backend.php.

77  {
78  if (!is_array($directives)) Zend_Cache::throwException('Directives parameter must be an array');
79  foreach ($directives as $name => $value) {
80  if (!is_string($name)) {
81  Zend_Cache::throwException("Incorrect option name : $name");
82  }
83  $name = strtolower($name);
84  if (array_key_exists($name, $this->_directives)) {
85  $this->_directives[$name] = $value;
86  }
87 
88  }
89 
90  $this->_loggerSanity();
91  }
$value
Definition: gender.phtml:16
static throwException($msg, Exception $e=null)
Definition: Cache.php:205
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ setOption()

setOption (   $name,
  $value 
)

Set an option

Parameters
string$name
mixed$value
Exceptions
Zend_Cache_Exception
Returns
void

Definition at line 101 of file Backend.php.

102  {
103  if (!is_string($name)) {
104  Zend_Cache::throwException("Incorrect option name : $name");
105  }
106  $name = strtolower($name);
107  if (array_key_exists($name, $this->_options)) {
108  $this->_options[$name] = $value;
109  }
110  }
$value
Definition: gender.phtml:16
static throwException($msg, Exception $e=null)
Definition: Cache.php:205
if(!isset($_GET['name'])) $name
Definition: log.php:14

Field Documentation

◆ $_directives

$_directives
protected
Initial value:
= array(
'lifetime' => 3600,
'logging' => false,
'logger' => null
)

Definition at line 44 of file Backend.php.

◆ $_options

$_options = array()
protected

Definition at line 55 of file Backend.php.


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