‪TYPO3CMS  10.4
Typo3DependencyViewHelper.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
22 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
23 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
24 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
25 
31 class ‪Typo3DependencyViewHelper extends AbstractViewHelper
32 {
33  use CompileWithRenderStatic;
34 
40  protected ‪$escapeOutput = false;
41 
47  public function ‪initializeArguments()
48  {
49  $this->registerArgument('extension', Extension::class, '', true);
50  }
51 
61  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
62  {
63  $extension = $arguments['extension'];
65  foreach ($extension->getDependencies() as $dependency) {
66  if ($dependency->getIdentifier() === 'typo3') {
67  $lowestVersion = $dependency->getLowestVersion();
68  $highestVersion = $dependency->getHighestVersion();
69  $cssClass = ‪self::isVersionSuitable($lowestVersion, $highestVersion) ? 'success' : 'default';
70  return
71  '<span class="label label-' . $cssClass . '">'
72  . htmlspecialchars($lowestVersion) . ' - ' . htmlspecialchars($highestVersion)
73  . '</span>';
74  }
75  }
76  return '';
77  }
78 
86  protected static function ‪isVersionSuitable($lowestVersion, $highestVersion)
87  {
89  $numericLowestVersion = ‪VersionNumberUtility::convertVersionNumberToInteger($lowestVersion);
90  $numericHighestVersion = ‪VersionNumberUtility::convertVersionNumberToInteger($highestVersion);
91  return ‪MathUtility::isIntegerInRange($numericTypo3Version, $numericLowestVersion, $numericHighestVersion);
92  }
93 }
‪TYPO3\CMS\Core\Utility\VersionNumberUtility
Definition: VersionNumberUtility.php:25
‪TYPO3\CMS\Extensionmanager\Domain\Model\Dependency
Definition: Dependency.php:26
‪TYPO3\CMS\Core\Utility\VersionNumberUtility\getNumericTypo3Version
‪static string getNumericTypo3Version()
Definition: VersionNumberUtility.php:107
‪TYPO3\CMS\Extensionmanager\Domain\Model\Extension
Definition: Extension.php:29
‪TYPO3\CMS\Extensionmanager\ViewHelpers\Typo3DependencyViewHelper\renderStatic
‪static string renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: Typo3DependencyViewHelper.php:59
‪TYPO3\CMS\Core\Utility\MathUtility\isIntegerInRange
‪static bool isIntegerInRange($value, $minimum, $maximum)
Definition: MathUtility.php:202
‪TYPO3\CMS\Extensionmanager\ViewHelpers\Typo3DependencyViewHelper\initializeArguments
‪initializeArguments()
Definition: Typo3DependencyViewHelper.php:45
‪TYPO3\CMS\Extensionmanager\ViewHelpers\Typo3DependencyViewHelper
Definition: Typo3DependencyViewHelper.php:32
‪TYPO3\CMS\Extensionmanager\ViewHelpers
‪TYPO3\CMS\Core\Utility\VersionNumberUtility\convertVersionNumberToInteger
‪static int convertVersionNumberToInteger($versionNumber)
Definition: VersionNumberUtility.php:32
‪TYPO3\CMS\Extensionmanager\ViewHelpers\Typo3DependencyViewHelper\$escapeOutput
‪bool $escapeOutput
Definition: Typo3DependencyViewHelper.php:38
‪TYPO3\CMS\Extensionmanager\ViewHelpers\Typo3DependencyViewHelper\isVersionSuitable
‪static bool isVersionSuitable($lowestVersion, $highestVersion)
Definition: Typo3DependencyViewHelper.php:84
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:22