[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/almanac/util/ -> AlmanacNames.php (source)

   1  <?php
   2  
   3  final class AlmanacNames extends Phobject {
   4  
   5    public static function validateServiceOrDeviceName($name) {
   6      if (strlen($name) < 3) {
   7        throw new Exception(
   8          pht(
   9            'Almanac service and device names must be at least 3 '.
  10            'characters long.'));
  11      }
  12  
  13      if (!preg_match('/^[a-z0-9.-]+\z/', $name)) {
  14        throw new Exception(
  15          pht(
  16            'Almanac service and device names may only contain lowercase '.
  17            'letters, numbers, hyphens, and periods.'));
  18      }
  19  
  20      if (preg_match('/(^|\\.)\d+(\z|\\.)/', $name)) {
  21        throw new Exception(
  22          pht(
  23            'Almanac service and device names may not have any segments '.
  24            'containing only digits.'));
  25      }
  26  
  27      if (preg_match('/\.\./', $name)) {
  28        throw new Exception(
  29          pht(
  30            'Almanac service and device names may not contain multiple '.
  31            'consecutive periods.'));
  32      }
  33  
  34      if (preg_match('/\\.-|-\\./', $name)) {
  35        throw new Exception(
  36          pht(
  37            'Amanac service and device names may not contain hyphens adjacent '.
  38            'to periods.'));
  39      }
  40  
  41      if (preg_match('/--/', $name)) {
  42        throw new Exception(
  43          pht(
  44            'Almanac service and device names may not contain multiple '.
  45            'consecutive hyphens.'));
  46      }
  47  
  48      if (!preg_match('/^[a-z0-9].*[a-z0-9]\z/', $name)) {
  49        throw new Exception(
  50          pht(
  51            'Almanac service and device names must begin and end with a letter '.
  52            'or number.'));
  53      }
  54    }
  55  
  56  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1