As ::cases() creates a Iteratable it is possible to use it in a foreach loop. In combination with value backed enum this can result in very compact and very readable code:
<?php
/** Content Security Policy directives */
enum CspDirective: String {
case Default = "default-src";
case Image = "img-src";
case Font = "font-src";
case Script = "script-src";
case Style = "style-src";
}
/** list all CSP directives */
foreach( CspSource::cases() as $directive ) {
echo $directive-> value . PHP_EOL;
}
?>
Which results in:
default-src
img-src
font-src
script-src
style-src