[FEATURE] Add interface utility, includes function to get constants
This commit is contained in:
parent
fe832637ed
commit
7db9769872
40
Classes/Utility/InterfaceUtility.php
Normal file
40
Classes/Utility/InterfaceUtility.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user