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