‪TYPO3CMS  10.4
OpcodeCacheService.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
25 {
31  public function ‪getAllActive()
32  {
33  $supportedCaches = [
34  'OPcache' => [
35  'active' => extension_loaded('Zend OPcache') && ini_get('opcache.enable') === '1',
36  'version' => phpversion('Zend OPcache'),
37  'warning' => ‪self::isClearable() ? false : 'Either opcache_invalidate or opcache_reset are disabled in this installation. Clearing will not work.',
38  'clearCallback' => static function ($fileAbsPath) {
39  if (self::isClearable()) {
40  if ($fileAbsPath !== null) {
41  opcache_invalidate($fileAbsPath);
42  } else {
43  opcache_reset();
44  }
45  }
46  },
47  ],
48  ];
49 
50  $activeCaches = [];
51  foreach ($supportedCaches as $opcodeCache => $properties) {
52  if ($properties['active']) {
53  $activeCaches[$opcodeCache] = $properties;
54  }
55  }
56  return $activeCaches;
57  }
58 
64  public function ‪clearAllActive($fileAbsPath = null)
65  {
66  foreach ($this->‪getAllActive() as $properties) {
67  $callback = $properties['clearCallback'];
68  $callback($fileAbsPath);
69  }
70  }
71 
75  protected static function ‪isClearable(): bool
76  {
77  $disabled = explode(',', (string)ini_get('disable_functions'));
78  return !(in_array('opcache_invalidate', $disabled, true) || in_array('opcache_reset', $disabled, true));
79  }
80 }
‪TYPO3\CMS\Core\Service\OpcodeCacheService\clearAllActive
‪clearAllActive($fileAbsPath=null)
Definition: OpcodeCacheService.php:64
‪TYPO3\CMS\Core\Service\OpcodeCacheService\getAllActive
‪array getAllActive()
Definition: OpcodeCacheService.php:31
‪TYPO3\CMS\Core\Service\OpcodeCacheService
Definition: OpcodeCacheService.php:25
‪TYPO3\CMS\Core\Service\OpcodeCacheService\isClearable
‪static bool isClearable()
Definition: OpcodeCacheService.php:75
‪TYPO3\CMS\Core\Service
Definition: AbstractService.php:16