|
11 | 11 |
|
12 | 12 | namespace Symfony\Bundle\MakerBundle;
|
13 | 13 |
|
14 |
| -use Symfony\Component\DependencyInjection\Container; |
15 | 14 | use Doctrine\Common\Inflector\Inflector;
|
| 15 | +use Symfony\Component\DependencyInjection\Container; |
16 | 16 |
|
17 | 17 | /**
|
18 | 18 | * @author Javier Eguiluz <[email protected]>
|
@@ -197,6 +197,29 @@ public static function isValidPhpVariableName($name)
|
197 | 197 | return (bool) preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $name, $matches);
|
198 | 198 | }
|
199 | 199 |
|
| 200 | + public static function isValidPhpClassName(string $className): bool |
| 201 | + { |
| 202 | + $reservedKeywords = ['__halt_compiler', 'abstract', 'and', 'array', |
| 203 | + 'as', 'break', 'callable', 'case', 'catch', 'class', |
| 204 | + 'clone', 'const', 'continue', 'declare', 'default', 'die', 'do', |
| 205 | + 'echo', 'else', 'elseif', 'empty', 'enddeclare', 'endfor', |
| 206 | + 'endforeach', 'endif', 'endswitch', 'endwhile', 'eval', |
| 207 | + 'exit', 'extends', 'final', 'for', 'foreach', 'function', |
| 208 | + 'global', 'goto', 'if', 'implements', 'include', |
| 209 | + 'include_once', 'instanceof', 'insteadof', 'interface', 'isset', |
| 210 | + 'list', 'namespace', 'new', 'or', 'print', 'private', |
| 211 | + 'protected', 'public', 'require', 'require_once', 'return', |
| 212 | + 'static', 'switch', 'throw', 'trait', 'try', 'unset', |
| 213 | + 'use', 'var', 'while', 'xor', '__CLASS__', '__DIR__', '__FILE__', |
| 214 | + '__FUNCTION__', '__LINE__', '__METHOD__', '__NAMESPACE__', '__TRAIT__', |
| 215 | + 'int', 'float', 'bool', 'string', 'true', 'false', 'null', 'void', |
| 216 | + 'iterable', 'object', |
| 217 | + ]; |
| 218 | + |
| 219 | + return !\in_array(strtolower($className), $reservedKeywords, true) && |
| 220 | + preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $className); |
| 221 | + } |
| 222 | + |
200 | 223 | public static function areClassesAlphabetical(string $class1, string $class2)
|
201 | 224 | {
|
202 | 225 | $arr1 = [$class1, $class2];
|
|
0 commit comments