Path: blob/master/src/applications/almanac/util/AlmanacNames.php
12256 views
<?php12final class AlmanacNames extends Phobject {34public static function validateName($name) {5if (strlen($name) < 3) {6throw new Exception(7pht(8'Almanac service, device, property, network and namespace names '.9'must be at least 3 characters long.'));10}1112if (strlen($name) > 100) {13throw new Exception(14pht(15'Almanac service, device, property, network and namespace names '.16'may not be more than 100 characters long.'));17}1819if (!preg_match('/^[a-z0-9.-]+\z/', $name)) {20throw new Exception(21pht(22'Almanac service, device, property, network and namespace names '.23'may only contain lowercase letters, numbers, hyphens, and '.24'periods.'));25}2627if (preg_match('/(^|\\.)\d+(\z|\\.)/', $name)) {28throw new Exception(29pht(30'Almanac service, device, network, property and namespace names '.31'may not have any segments containing only digits.'));32}3334if (preg_match('/\.\./', $name)) {35throw new Exception(36pht(37'Almanac service, device, property, network and namespace names '.38'may not contain multiple consecutive periods.'));39}4041if (preg_match('/\\.-|-\\./', $name)) {42throw new Exception(43pht(44'Almanac service, device, property, network and namespace names '.45'may not contain hyphens adjacent to periods.'));46}4748if (preg_match('/--/', $name)) {49throw new Exception(50pht(51'Almanac service, device, property, network and namespace names '.52'may not contain multiple consecutive hyphens.'));53}5455if (!preg_match('/^[a-z0-9].*[a-z0-9]\z/', $name)) {56throw new Exception(57pht(58'Almanac service, device, property, network and namespace names '.59'must begin and end with a letter or number.'));60}61}6263}646566