Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / almanac / util / AlmanacNames.php
blobcee3c811513758bbef2ebe977c8c86e70d815710
1 <?php
3 final class AlmanacNames extends Phobject {
5 public static function validateName($name) {
6 if (strlen($name) < 3) {
7 throw new Exception(
8 pht(
9 'Almanac service, device, property, network and namespace names '.
10 'must be at least 3 characters long.'));
13 if (strlen($name) > 100) {
14 throw new Exception(
15 pht(
16 'Almanac service, device, property, network and namespace names '.
17 'may not be more than 100 characters long.'));
20 if (!preg_match('/^[a-z0-9.-]+\z/', $name)) {
21 throw new Exception(
22 pht(
23 'Almanac service, device, property, network and namespace names '.
24 'may only contain lowercase letters, numbers, hyphens, and '.
25 'periods.'));
28 if (preg_match('/(^|\\.)\d+(\z|\\.)/', $name)) {
29 throw new Exception(
30 pht(
31 'Almanac service, device, network, property and namespace names '.
32 'may not have any segments containing only digits.'));
35 if (preg_match('/\.\./', $name)) {
36 throw new Exception(
37 pht(
38 'Almanac service, device, property, network and namespace names '.
39 'may not contain multiple consecutive periods.'));
42 if (preg_match('/\\.-|-\\./', $name)) {
43 throw new Exception(
44 pht(
45 'Almanac service, device, property, network and namespace names '.
46 'may not contain hyphens adjacent to periods.'));
49 if (preg_match('/--/', $name)) {
50 throw new Exception(
51 pht(
52 'Almanac service, device, property, network and namespace names '.
53 'may not contain multiple consecutive hyphens.'));
56 if (!preg_match('/^[a-z0-9].*[a-z0-9]\z/', $name)) {
57 throw new Exception(
58 pht(
59 'Almanac service, device, property, network and namespace names '.
60 'must begin and end with a letter or number.'));