Index.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Version\Controller\Index;
  8. use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
  9. use Magento\Framework\App\Action\Action;
  10. use Magento\Framework\App\Action\Context;
  11. use Magento\Framework\App\ProductMetadataInterface;
  12. /**
  13. * Magento Version controller
  14. */
  15. class Index extends Action implements HttpGetActionInterface
  16. {
  17. /**
  18. * @var ProductMetadataInterface
  19. */
  20. protected $productMetadata;
  21. /**
  22. * @param Context $context
  23. * @param ProductMetadataInterface $productMetadata
  24. */
  25. public function __construct(Context $context, ProductMetadataInterface $productMetadata)
  26. {
  27. $this->productMetadata = $productMetadata;
  28. parent::__construct($context);
  29. }
  30. /**
  31. * Sets the response body to ProductName/Major.MinorVersion (Edition). E.g.: Magento/0.42 (Community). Omits patch
  32. * version from response
  33. *
  34. * @return void
  35. */
  36. public function execute()
  37. {
  38. $version = $this->productMetadata->getVersion();
  39. $versionParts = explode('.', $version);
  40. if ((!isset($versionParts[0]) || !isset($versionParts[1]))
  41. || $this->isGitBasedInstallation($version)
  42. ) {
  43. return;
  44. }
  45. $majorMinorVersion = $versionParts[0] . '.' . $versionParts[1];
  46. $this->getResponse()->setBody(
  47. $this->productMetadata->getName() . '/' .
  48. $majorMinorVersion . ' (' .
  49. $this->productMetadata->getEdition() . ')'
  50. );
  51. }
  52. /**
  53. * Check if provided version is generated by Git-based Magento instance.
  54. *
  55. * @param string $fullVersion
  56. * @return bool
  57. */
  58. private function isGitBasedInstallation($fullVersion)
  59. {
  60. $versionParts = explode('-', $fullVersion);
  61. return (isset($versionParts[0]) && $versionParts[0] == 'dev');
  62. }
  63. }