Changeset View
Changeset View
Standalone View
Standalone View
src/applications/almanac/util/AlmanacNames.php
Context not available. | |||||
final class AlmanacNames extends Phobject { | final class AlmanacNames extends Phobject { | ||||
public static function validateName($name) { | public static function validateName($name) { | ||||
if (strlen($name) < 3) { | if (@strlen($name) < 3) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Almanac service, device, property, network and namespace names '. | 'Almanac service, device, property, network and namespace names '. | ||||
'must be at least 3 characters long.')); | 'must be at least 3 characters long.')); | ||||
} | } | ||||
if (strlen($name) > 100) { | if (@strlen($name) > 100) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Almanac service, device, property, network and namespace names '. | 'Almanac service, device, property, network and namespace names '. | ||||
'may not be more than 100 characters long.')); | 'may not be more than 100 characters long.')); | ||||
} | } | ||||
if (!preg_match('/^[a-z0-9.-]+\z/', $name)) { | if (!@preg_match('/^[a-z0-9.-]+\z/', $name)) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Almanac service, device, property, network and namespace names '. | 'Almanac service, device, property, network and namespace names '. | ||||
Context not available. | |||||
'periods.')); | 'periods.')); | ||||
} | } | ||||
if (preg_match('/(^|\\.)\d+(\z|\\.)/', $name)) { | if (@preg_match('/(^|\\.)\d+(\z|\\.)/', $name)) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Almanac service, device, network, property and namespace names '. | 'Almanac service, device, network, property and namespace names '. | ||||
'may not have any segments containing only digits.')); | 'may not have any segments containing only digits.')); | ||||
} | } | ||||
if (preg_match('/\.\./', $name)) { | if (@preg_match('/\.\./', $name)) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Almanac service, device, property, network and namespace names '. | 'Almanac service, device, property, network and namespace names '. | ||||
'may not contain multiple consecutive periods.')); | 'may not contain multiple consecutive periods.')); | ||||
} | } | ||||
if (preg_match('/\\.-|-\\./', $name)) { | if (@preg_match('/\\.-|-\\./', $name)) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Almanac service, device, property, network and namespace names '. | 'Almanac service, device, property, network and namespace names '. | ||||
'may not contain hyphens adjacent to periods.')); | 'may not contain hyphens adjacent to periods.')); | ||||
} | } | ||||
if (preg_match('/--/', $name)) { | if (@preg_match('/--/', $name)) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Almanac service, device, property, network and namespace names '. | 'Almanac service, device, property, network and namespace names '. | ||||
'may not contain multiple consecutive hyphens.')); | 'may not contain multiple consecutive hyphens.')); | ||||
} | } | ||||
if (!preg_match('/^[a-z0-9].*[a-z0-9]\z/', $name)) { | if (!@preg_match('/^[a-z0-9].*[a-z0-9]\z/', $name)) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Almanac service, device, property, network and namespace names '. | 'Almanac service, device, property, network and namespace names '. | ||||
Context not available. |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0