woocommerce-pos
/
vendor_prefixed
/
sentry
/
sentry
/
src
/
Integration
/
EnvironmentIntegration.php
EnvironmentIntegration.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.17, at vendor_prefixed/sentry/sentry/src/Integration/EnvironmentIntegration.php
| 1 | <?php |
| 2 | |
| 3 | declare (strict_types=1); |
| 4 | namespace WCPOS\Vendor\Sentry\Integration; |
| 5 | |
| 6 | use WCPOS\Vendor\Sentry\Context\OsContext; |
| 7 | use WCPOS\Vendor\Sentry\Context\RuntimeContext; |
| 8 | use WCPOS\Vendor\Sentry\Event; |
| 9 | use WCPOS\Vendor\Sentry\SentrySdk; |
| 10 | use WCPOS\Vendor\Sentry\State\Scope; |
| 11 | use WCPOS\Vendor\Sentry\Util\PHPVersion; |
| 12 | /** |
| 13 | * This integration fills the event data with runtime and server OS information. |
| 14 | * |
| 15 | * @author Stefano Arlandini <[email protected]> |
| 16 | */ |
| 17 | final class EnvironmentIntegration implements IntegrationInterface |
| 18 | { |
| 19 | /** |
| 20 | * {@inheritdoc} |
| 21 | */ |
| 22 | public function setupOnce() : void |
| 23 | { |
| 24 | Scope::addGlobalEventProcessor(static function (Event $event) : Event { |
| 25 | $integration = SentrySdk::getCurrentHub()->getIntegration(self::class); |
| 26 | if ($integration !== null) { |
| 27 | $event->setRuntimeContext($integration->updateRuntimeContext($event->getRuntimeContext())); |
| 28 | $event->setOsContext($integration->updateServerOsContext($event->getOsContext())); |
| 29 | } |
| 30 | return $event; |
| 31 | }); |
| 32 | } |
| 33 | private function updateRuntimeContext(?RuntimeContext $runtimeContext) : RuntimeContext |
| 34 | { |
| 35 | if ($runtimeContext === null) { |
| 36 | $runtimeContext = new RuntimeContext('php'); |
| 37 | } |
| 38 | if ($runtimeContext->getVersion() === null) { |
| 39 | $runtimeContext->setVersion(PHPVersion::parseVersion()); |
| 40 | } |
| 41 | if ($runtimeContext->getSAPI() === null) { |
| 42 | $runtimeContext->setSAPI(\PHP_SAPI); |
| 43 | } |
| 44 | return $runtimeContext; |
| 45 | } |
| 46 | private function updateServerOsContext(?OsContext $osContext) : ?OsContext |
| 47 | { |
| 48 | if (!\function_exists('php_uname')) { |
| 49 | return $osContext; |
| 50 | } |
| 51 | if ($osContext === null) { |
| 52 | $osContext = new OsContext(\php_uname('s')); |
| 53 | } |
| 54 | if ($osContext->getVersion() === null) { |
| 55 | $osContext->setVersion(\php_uname('r')); |
| 56 | } |
| 57 | if ($osContext->getBuild() === null) { |
| 58 | $osContext->setBuild(\php_uname('v')); |
| 59 | } |
| 60 | if ($osContext->getKernelVersion() === null) { |
| 61 | $osContext->setKernelVersion(\php_uname('a')); |
| 62 | } |
| 63 | if ($osContext->getMachineType() === null) { |
| 64 | $osContext->setMachineType(\php_uname('m')); |
| 65 | } |
| 66 | return $osContext; |
| 67 | } |
| 68 | } |
| 69 |