1 | <?php |
||
5 | class ValidateCodeFieldForObject extends Object |
||
6 | { |
||
7 | private static $length = 7; |
||
8 | |||
9 | /** |
||
10 | * @var Array |
||
11 | */ |
||
12 | private $replacements = array( |
||
13 | '/&/u' => '-and-', |
||
14 | '/&/u' => '-and-', |
||
15 | '/\s/u' => '-', // remove whitespace |
||
16 | '/[^A-Za-z0-9.\-_]+/u' => '', // remove non-ASCII chars, only allow alphanumeric, dashes and dots. |
||
17 | '/[\-]{2,}/u' => '-', // remove duplicate dashes |
||
18 | '/[\_]{2,}/u' => '_', // remove duplicate underscores |
||
19 | '/^[\.\-_]/u' => '', // Remove all leading dots, dashes or underscores |
||
20 | ); |
||
21 | |||
22 | /** |
||
23 | * makes sure that code is unique and gets rid of special characters |
||
24 | * should be run in onBeforeWrite |
||
25 | * |
||
26 | * @param DataObject | String $obj |
||
27 | * @param Boolean $createCode |
||
28 | * @param String $field |
||
29 | */ |
||
30 | |||
31 | public function checkCode($obj, $createCode = false, $field = "Code") |
||
72 | |||
73 | public function CreateCode() |
||
83 | } |
||
84 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.