PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.12.1
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.12.1
5.12.1 5.12.0 5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / vendor / prefixed / symfony / http-kernel / CacheWarmer / CacheWarmerAggregate.php
matomo / app / vendor / prefixed / symfony / http-kernel / CacheWarmer Last commit date
CacheWarmer.php 1 year ago CacheWarmerAggregate.php 1 year ago CacheWarmerInterface.php 2 years ago WarmableInterface.php 2 years ago
CacheWarmerAggregate.php
104 lines
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11 namespace Matomo\Dependencies\Symfony\Component\HttpKernel\CacheWarmer;
12
13 /**
14 * Aggregates several cache warmers into a single one.
15 *
16 * @author Fabien Potencier <fabien@symfony.com>
17 *
18 * @final
19 */
20 class CacheWarmerAggregate implements CacheWarmerInterface
21 {
22 private $warmers;
23 private $debug;
24 private $deprecationLogsFilepath;
25 private $optionalsEnabled = \false;
26 private $onlyOptionalsEnabled = \false;
27 /**
28 * @param iterable<mixed, CacheWarmerInterface> $warmers
29 */
30 public function __construct(iterable $warmers = [], bool $debug = \false, ?string $deprecationLogsFilepath = null)
31 {
32 $this->warmers = $warmers;
33 $this->debug = $debug;
34 $this->deprecationLogsFilepath = $deprecationLogsFilepath;
35 }
36 public function enableOptionalWarmers()
37 {
38 $this->optionalsEnabled = \true;
39 }
40 public function enableOnlyOptionalWarmers()
41 {
42 $this->onlyOptionalsEnabled = $this->optionalsEnabled = \true;
43 }
44 /**
45 * {@inheritdoc}
46 */
47 public function warmUp(string $cacheDir) : array
48 {
49 if ($collectDeprecations = $this->debug && !\defined('PHPUNIT_COMPOSER_INSTALL')) {
50 $collectedLogs = [];
51 $previousHandler = set_error_handler(function ($type, $message, $file, $line) use(&$collectedLogs, &$previousHandler) {
52 if (\E_USER_DEPRECATED !== $type && \E_DEPRECATED !== $type) {
53 return $previousHandler ? $previousHandler($type, $message, $file, $line) : \false;
54 }
55 if (isset($collectedLogs[$message])) {
56 ++$collectedLogs[$message]['count'];
57 return null;
58 }
59 $backtrace = debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 3);
60 // Clean the trace by removing first frames added by the error handler itself.
61 for ($i = 0; isset($backtrace[$i]); ++$i) {
62 if (isset($backtrace[$i]['file'], $backtrace[$i]['line']) && $backtrace[$i]['line'] === $line && $backtrace[$i]['file'] === $file) {
63 $backtrace = \array_slice($backtrace, 1 + $i);
64 break;
65 }
66 }
67 $collectedLogs[$message] = ['type' => $type, 'message' => $message, 'file' => $file, 'line' => $line, 'trace' => $backtrace, 'count' => 1];
68 return null;
69 });
70 }
71 $preload = [];
72 try {
73 foreach ($this->warmers as $warmer) {
74 if (!$this->optionalsEnabled && $warmer->isOptional()) {
75 continue;
76 }
77 if ($this->onlyOptionalsEnabled && !$warmer->isOptional()) {
78 continue;
79 }
80 $preload[] = array_values((array) $warmer->warmUp($cacheDir));
81 }
82 } finally {
83 if ($collectDeprecations) {
84 restore_error_handler();
85 if (is_file($this->deprecationLogsFilepath)) {
86 $previousLogs = unserialize(file_get_contents($this->deprecationLogsFilepath));
87 if (\is_array($previousLogs)) {
88 $collectedLogs = array_merge($previousLogs, $collectedLogs);
89 }
90 }
91 file_put_contents($this->deprecationLogsFilepath, serialize(array_values($collectedLogs)));
92 }
93 }
94 return array_values(array_unique(array_merge([], ...$preload)));
95 }
96 /**
97 * {@inheritdoc}
98 */
99 public function isOptional() : bool
100 {
101 return \false;
102 }
103 }
104