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