|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +declare(strict_types=1); |
| 8 | + |
| 9 | +namespace Magento\CloudComponents\Model; |
| 10 | + |
| 11 | +/** |
| 12 | + * Class to get compressed debug back trace |
| 13 | + */ |
| 14 | +class DebugTrace |
| 15 | +{ |
| 16 | + /** |
| 17 | + * List of useless classes |
| 18 | + * |
| 19 | + * @var string[] |
| 20 | + */ |
| 21 | + private $notAllowedClasses = [ |
| 22 | + 'Symfony\Component\Console\Application', |
| 23 | + 'Magento\Framework\Console\Cli', |
| 24 | + 'Symfony\Component\Console\Command\Command', |
| 25 | + 'Magento\Staging\Model\Event\Manager\Proxy', |
| 26 | + 'Magento\Staging\Model\Event\Manager', |
| 27 | + 'Magento\Framework\Event\Invoker\InvokerDefault', |
| 28 | + 'Magento\CloudComponents\Model\Observer\CacheFlushAll', |
| 29 | + 'Magento\CloudComponents\Model\Cache\InvalidateLogger', |
| 30 | + 'Magento\CloudComponents\Model\Cache\InvalidateLogger', |
| 31 | + 'Magento\CloudComponents\Model\Indexation\Logger', |
| 32 | + 'Magento\Framework\Cache\Frontend\Decorator\Logger', |
| 33 | + 'Magento\Framework\Cache\Frontend\Decorator\Bare', |
| 34 | + 'Magento\Framework\App\Cache\Type\AccessProxy', |
| 35 | + 'Magento\Framework\Cache\Frontend\Decorator\TagScope', |
| 36 | + 'Magento\Framework\ObjectManager\ObjectManager', |
| 37 | + 'Magento\Framework\ObjectManager\Config\Compiled', |
| 38 | + 'Magento\Framework\ObjectManager\Config\Config', |
| 39 | + 'Magento\Framework\ObjectManager\Factory\Dynamic\Developer', |
| 40 | + 'Magento\Framework\ObjectManager\Factory\Dynamic\Production' |
| 41 | + ]; |
| 42 | + |
| 43 | + /** |
| 44 | + * List of useless functions |
| 45 | + * |
| 46 | + * @var string[] |
| 47 | + */ |
| 48 | + private $notAllowedFunctions = [ |
| 49 | + '___callPlugins', |
| 50 | + '___callParent', |
| 51 | + 'Magento\Framework\Interception\{closure}' |
| 52 | + ]; |
| 53 | + |
| 54 | + /** |
| 55 | + * Returns debug back trace |
| 56 | + * |
| 57 | + * @return array |
| 58 | + */ |
| 59 | + public function getTrace() |
| 60 | + { |
| 61 | + $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); |
| 62 | + foreach ($trace as $index => $line) { |
| 63 | + if (!isset($line['function'], $line['class'], $line['file'])) { |
| 64 | + continue; |
| 65 | + } |
| 66 | + if (in_array($line['function'], $this->notAllowedFunctions) |
| 67 | + || in_array($line['class'], $this->notAllowedClasses) |
| 68 | + || strpos($line['file'], 'Interceptor.php') !== false |
| 69 | + ) { |
| 70 | + unset($trace[$index]); |
| 71 | + } |
| 72 | + unset($trace[$index]['type']); |
| 73 | + } |
| 74 | + |
| 75 | + if (function_exists('gzcompress')) { |
| 76 | + return bin2hex( |
| 77 | + gzcompress( |
| 78 | + print_r( |
| 79 | + $trace, |
| 80 | + true |
| 81 | + ) |
| 82 | + ) |
| 83 | + ); |
| 84 | + } |
| 85 | + return $trace; |
| 86 | + } |
| 87 | +} |
0 commit comments