*/ class AbstractStimulusViewHelper extends AbstractViewHelper { /** * This method is taken from symfony/webpack-encore-bundle * * Normalize a Stimulus controller name into its HTML equivalent (no special character and / becomes --). * * @see https://stimulus.hotwire.dev/reference/controllers */ protected static function normalizeControllerName(string $str): string { return preg_replace('/^@/', '', str_replace('_', '-', str_replace('/', '--', $str))); } /** * This method is taken from symfony/webpack-encore-bundle * * Normalize a Stimulus Value API key into its HTML equivalent ("kebab case"). * Backport features from symfony/string. * * @see https://stimulus.hotwire.dev/reference/values */ protected static function normalizeKeyName(string $str): string { // Adapted from ByteString::camel $str = ucfirst(str_replace(' ', '', ucwords(preg_replace('/[^a-zA-Z0-9\x7f-\xff]++/', ' ', $str)))); // Adapted from ByteString::snake return strtolower(preg_replace(['/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'], '\1-\2', $str)); } }