![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/magento/module-version/Controller/Index/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ declare(strict_types=1); namespace Magento\Version\Controller\Index; use Magento\Framework\App\Action\Action; use Magento\Framework\App\Action\Context; use Magento\Framework\App\Action\HttpGetActionInterface; use Magento\Framework\App\ProductMetadataInterface; use Magento\Framework\Controller\Result\RawFactory as RawResponseFactory; /** * Magento Version controller: Sets the response body to ProductName/Major.MinorVersion (Edition). */ class Index extends Action implements HttpGetActionInterface { public const DEV_PREFIX = 'dev-'; /** * @var ProductMetadataInterface */ private $productMetadata; /** * @var RawResponseFactory */ private $rawFactory; /** * @param Context $context * @param RawResponseFactory $rawFactory * @param ProductMetadataInterface $productMetadata */ public function __construct( Context $context, RawResponseFactory $rawFactory, ProductMetadataInterface $productMetadata ) { parent::__construct($context); $this->rawFactory = $rawFactory; $this->productMetadata = $productMetadata; } /** * @inheritDoc */ public function execute() { $rawResponse = $this->rawFactory->create(); $version = $this->productMetadata->getVersion() ?? ''; $versionParts = explode('.', $version); if (!$this->isGitBasedInstallation($version) && $this->isCorrectVersion($versionParts)) { $rawResponse->setContents( $this->productMetadata->getName() . '/' . $this->getMajorMinorVersion($versionParts) . ' (' . $this->productMetadata->getEdition() . ')' ); } return $rawResponse; } /** * Check if provided version is generated by Git-based Magento instance. * * @param string $fullVersion * @return bool */ private function isGitBasedInstallation($fullVersion): bool { return 0 === strpos($fullVersion, self::DEV_PREFIX); } /** * Verifies if the Magento version is correct * * @param array $versionParts * @return bool */ private function isCorrectVersion(array $versionParts): bool { return isset($versionParts[0]) && isset($versionParts[1]); } /** * Returns string only with Major and Minor version number * * @param array $versionParts * @return string */ private function getMajorMinorVersion(array $versionParts): string { return $versionParts[0] . '.' . $versionParts[1]; } }