From 7db9769872507f8a195bb08b54629aaaeb70dd4d Mon Sep 17 00:00:00 2001 From: Philipp Dieter Date: Mon, 2 Aug 2021 11:27:45 +0200 Subject: [PATCH] [FEATURE] Add interface utility, includes function to get constants --- Classes/Utility/InterfaceUtility.php | 40 ++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Classes/Utility/InterfaceUtility.php diff --git a/Classes/Utility/InterfaceUtility.php b/Classes/Utility/InterfaceUtility.php new file mode 100644 index 0000000..db5ae8f --- /dev/null +++ b/Classes/Utility/InterfaceUtility.php @@ -0,0 +1,40 @@ + + * + ***/ + +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); + } +}