| 1 | <?php |
||
| 10 | class Validator |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * Valid entity string formats. |
||
| 14 | * |
||
| 15 | * @var array |
||
| 16 | */ |
||
| 17 | private $stringFormats = ['dash', 'camelcase', 'studlycaps', 'underscore']; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Valid regex patterns per name format. |
||
| 21 | * |
||
| 22 | * @var array |
||
| 23 | */ |
||
| 24 | private $nameFormats = [ |
||
| 25 | 'studlycaps' => '/^[A-Z]{1}[a-zA-Z]{0,}$/', |
||
| 26 | 'camelcase' => '/^[a-z]{1}[a-zA-Z]{0,}$/', |
||
| 27 | 'dash' => '/^(?!.*--.*)[a-z]{1}[a-z-]{0,}(?<!-)$/', |
||
| 28 | 'underscore' => '/^(?!.*__.*)[a-z]{1}[a-z_]{0,}(?<!_)$/', |
||
| 29 | ]; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Validates a name (such as entity types or entity field keys) to a selected format. |
||
| 33 | * |
||
| 34 | * @param string $format |
||
| 35 | * @param string $name |
||
| 36 | * @return bool |
||
| 37 | */ |
||
| 38 | public function isNameValid($format, $name) |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Validates an entity string format. |
||
| 51 | * |
||
| 52 | * @param string $format |
||
| 53 | * @return bool |
||
| 54 | */ |
||
| 55 | public function isFormatValid($format) |
||
| 59 | } |
||
| 60 |