[FEATURE] Add interface utility, includes function to get constants

This commit is contained in:
Philipp Dieter 2021-08-02 11:27:45 +02:00
parent fe832637ed
commit 7db9769872

View File

@ -0,0 +1,40 @@
<?php
namespace Cjel\TemplatesAide\Utility;
/***
*
* This file is part of the "Templates Aide" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* (c) 2021 Philipp Dieter <philipp.dieter@attic-media.net>
*
***/
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
/**
*
*/
class InterfaceUtility
{
/**
* Get all interface constants per prefix
*/
public static function parseInterfaceConstants(
$interfaceClass, $prefix
) {
$constants = (new \ReflectionClass($interfaceClass))
->getConstants();
$constants = array_filter($constants, function($key) use ($prefix) {
if (substr($key, 0, strlen($prefix) + 1)
== strtoupper($prefix) . '_'
) {
return true;
}
}, ARRAY_FILTER_USE_KEY);
return array_values($constants);
}
}