Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Factory Class Reference

Public Member Functions

 __construct (\Magento\Framework\ObjectManagerInterface $objectManager, Filesystem $filesystem, \Magento\Framework\App\ResourceConnection $resource, array $enforcedOptions=[], array $decorators=[])
 

Data Fields

const DEFAULT_LIFETIME = 7200
 
const PARAM_CACHE_FORCED_OPTIONS = 'cache_options'
 

Protected Member Functions

 _getBackendOptions (array $cacheOptions)
 
 _getDbAdapterOptions ()
 
 _getTwoLevelsBackendOptions ($fastOptions, $cacheOptions)
 
 _getFrontendOptions (array $cacheOptions)
 

Protected Attributes

 $_defaultBackend = 'Cm_Cache_Backend_File'
 
 $_backendOptions
 
 $_resource
 

Detailed Description

@SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 18 of file Factory.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\ObjectManagerInterface  $objectManager,
Filesystem  $filesystem,
\Magento\Framework\App\ResourceConnection  $resource,
array  $enforcedOptions = [],
array  $decorators = [] 
)
Parameters
\Magento\Framework\ObjectManagerInterface$objectManager
Filesystem$filesystem
\Magento\Framework\App\ResourceConnection$resource
array$enforcedOptions
array$decorators

Definition at line 89 of file Factory.php.

95  {
96  $this->_objectManager = $objectManager;
97  $this->_filesystem = $filesystem;
98  $this->_resource = $resource;
99  $this->_enforcedOptions = $enforcedOptions;
100  $this->_decorators = $decorators;
101  }
$objectManager
Definition: bootstrap.php:17
$resource
Definition: bulk.php:12
$filesystem

Member Function Documentation

◆ _getBackendOptions()

_getBackendOptions ( array  $cacheOptions)
protected

Get cache backend options. Result array contain backend type ('type' key) and backend options ('options')

Parameters
array$cacheOptions
Returns
array @SuppressWarnings(PHPMD.CyclomaticComplexity) @SuppressWarnings(PHPMD.NPathComplexity)

Definition at line 213 of file Factory.php.

214  {
215  $enableTwoLevels = false;
216  $type = isset($cacheOptions['backend']) ? $cacheOptions['backend'] : $this->_defaultBackend;
217  if (isset($cacheOptions['backend_options']) && is_array($cacheOptions['backend_options'])) {
218  $options = $cacheOptions['backend_options'];
219  } else {
220  $options = [];
221  }
222 
223  $backendType = false;
224  switch (strtolower($type)) {
225  case 'sqlite':
226  if (extension_loaded('sqlite') && isset($options['cache_db_complete_path'])) {
227  $backendType = 'Sqlite';
228  }
229  break;
230  case 'memcached':
231  if (extension_loaded('memcached')) {
232  if (isset($cacheOptions['memcached'])) {
233  $options = $cacheOptions['memcached'];
234  }
235  $enableTwoLevels = true;
236  $backendType = 'Libmemcached';
237  } elseif (extension_loaded('memcache')) {
238  if (isset($cacheOptions['memcached'])) {
239  $options = $cacheOptions['memcached'];
240  }
241  $enableTwoLevels = true;
242  $backendType = 'Memcached';
243  }
244  break;
245  case 'apc':
246  if (extension_loaded('apc') && ini_get('apc.enabled')) {
247  $enableTwoLevels = true;
248  $backendType = 'Apc';
249  }
250  break;
251  case 'xcache':
252  if (extension_loaded('xcache')) {
253  $enableTwoLevels = true;
254  $backendType = 'Xcache';
255  }
256  break;
257  case 'eaccelerator':
258  case 'varien_cache_backend_eaccelerator':
259  if (extension_loaded('eaccelerator') && ini_get('eaccelerator.enable')) {
260  $enableTwoLevels = true;
261  $backendType = \Magento\Framework\Cache\Backend\Eaccelerator::class;
262  }
263  break;
264  case 'database':
265  $backendType = \Magento\Framework\Cache\Backend\Database::class;
266  $options = $this->_getDbAdapterOptions();
267  break;
268  case 'remote_synchronized_cache':
269  $backendType = \Magento\Framework\Cache\Backend\RemoteSynchronizedCache::class;
270  $options['remote_backend'] = \Magento\Framework\Cache\Backend\Database::class;
271  $options['remote_backend_options'] = $this->_getDbAdapterOptions();
272  $options['local_backend'] = \Cm_Cache_Backend_File::class;
273  $cacheDir = $this->_filesystem->getDirectoryWrite(DirectoryList::CACHE);
274  $options['local_backend_options']['cache_dir'] = $cacheDir->getAbsolutePath();
275  $cacheDir->create();
276  break;
277  default:
278  if ($type != $this->_defaultBackend) {
279  try {
280  if (class_exists($type, true)) {
281  $implements = class_implements($type, true);
282  if (in_array('Zend_Cache_Backend_Interface', $implements)) {
283  $backendType = $type;
284  }
285  }
286  } catch (\Exception $e) {
287  }
288  }
289  }
290  if (!$backendType) {
291  $backendType = $this->_defaultBackend;
292  $cacheDir = $this->_filesystem->getDirectoryWrite(DirectoryList::CACHE);
293  $this->_backendOptions['cache_dir'] = $cacheDir->getAbsolutePath();
294  $cacheDir->create();
295  }
296  foreach ($this->_backendOptions as $option => $value) {
297  if (!array_key_exists($option, $options)) {
299  }
300  }
301 
302  $backendOptions = ['type' => $backendType, 'options' => $options];
303  if ($enableTwoLevels) {
304  $backendOptions = $this->_getTwoLevelsBackendOptions($backendOptions, $cacheOptions);
305  }
306  return $backendOptions;
307  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$type
Definition: item.phtml:13
$value
Definition: gender.phtml:16
_getTwoLevelsBackendOptions($fastOptions, $cacheOptions)
Definition: Factory.php:335

◆ _getDbAdapterOptions()

_getDbAdapterOptions ( )
protected

Get options for database backend type

Returns
array

Definition at line 314 of file Factory.php.

315  {
316  $options['adapter_callback'] = function () {
317  return $this->_resource->getConnection();
318  };
319  $options['data_table_callback'] = function () {
320  return $this->_resource->getTableName('cache');
321  };
322  $options['tags_table_callback'] = function () {
323  return $this->_resource->getTableName('cache_tag');
324  };
325  return $options;
326  }

◆ _getFrontendOptions()

_getFrontendOptions ( array  $cacheOptions)
protected

Get options of cache frontend (options of \Zend_Cache_Core)

Parameters
array$cacheOptions
Returns
array @SuppressWarnings(PHPMD.NPathComplexity)

Definition at line 381 of file Factory.php.

382  {
383  $options = isset($cacheOptions['frontend_options']) ? $cacheOptions['frontend_options'] : [];
384  if (!array_key_exists('caching', $options)) {
385  $options['caching'] = true;
386  }
387  if (!array_key_exists('lifetime', $options)) {
388  $options['lifetime'] = isset(
389  $cacheOptions['lifetime']
390  ) ? $cacheOptions['lifetime'] : self::DEFAULT_LIFETIME;
391  }
392  if (!array_key_exists('automatic_cleaning_factor', $options)) {
393  $options['automatic_cleaning_factor'] = 0;
394  }
395  $options['type'] =
396  isset($cacheOptions['frontend']) ? $cacheOptions['frontend'] : \Magento\Framework\Cache\Core::class;
397  return $options;
398  }

◆ _getTwoLevelsBackendOptions()

_getTwoLevelsBackendOptions (   $fastOptions,
  $cacheOptions 
)
protected

Initialize two levels backend model options

Parameters
array$fastOptionsfast level backend type and options
array$cacheOptionsall cache options
Returns
array

Definition at line 335 of file Factory.php.

336  {
337  $options = [];
338  $options['fast_backend'] = $fastOptions['type'];
339  $options['fast_backend_options'] = $fastOptions['options'];
340  $options['fast_backend_custom_naming'] = true;
341  $options['fast_backend_autoload'] = true;
342  $options['slow_backend_custom_naming'] = true;
343  $options['slow_backend_autoload'] = true;
344 
345  if (isset($cacheOptions['auto_refresh_fast_cache'])) {
346  $options['auto_refresh_fast_cache'] = (bool)$cacheOptions['auto_refresh_fast_cache'];
347  } else {
348  $options['auto_refresh_fast_cache'] = false;
349  }
350  if (isset($cacheOptions['slow_backend'])) {
351  $options['slow_backend'] = $cacheOptions['slow_backend'];
352  } else {
353  $options['slow_backend'] = $this->_defaultBackend;
354  }
355  if (isset($cacheOptions['slow_backend_options'])) {
356  $options['slow_backend_options'] = $cacheOptions['slow_backend_options'];
357  } else {
358  $options['slow_backend_options'] = $this->_backendOptions;
359  }
360  if ($options['slow_backend'] == 'database') {
361  $options['slow_backend'] = \Magento\Framework\Cache\Backend\Database::class;
362  $options['slow_backend_options'] = $this->_getDbAdapterOptions();
363  if (isset($cacheOptions['slow_backend_store_data'])) {
364  $options['slow_backend_options']['store_data'] = (bool)$cacheOptions['slow_backend_store_data'];
365  } else {
366  $options['slow_backend_options']['store_data'] = false;
367  }
368  }
369 
370  $backend = ['type' => 'TwoLevels', 'options' => $options];
371  return $backend;
372  }

Field Documentation

◆ $_backendOptions

$_backendOptions
protected
Initial value:
= [
'hashed_directory_level' => 1,
'file_name_prefix' => 'mage',
]

Definition at line 70 of file Factory.php.

◆ $_defaultBackend

$_defaultBackend = 'Cm_Cache_Backend_File'
protected

Definition at line 63 of file Factory.php.

◆ $_resource

$_resource
protected

Definition at line 80 of file Factory.php.

◆ DEFAULT_LIFETIME

const DEFAULT_LIFETIME = 7200

Default cache entry lifetime

Definition at line 23 of file Factory.php.

◆ PARAM_CACHE_FORCED_OPTIONS

const PARAM_CACHE_FORCED_OPTIONS = 'cache_options'

Caching params, that applied for all cache frontends regardless of type

Definition at line 28 of file Factory.php.


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