Exemple #1
0
 public static function validatePath(RecordValidator $validator, Endpoint $Endpoint)
 {
     if (!$Endpoint->Path) {
         $validator->addError('Path', 'Path must not be empty');
         return;
     }
     if ($Endpoint->Path[0] == '/') {
         $validator->addError('Path', 'Path must not start with /');
         return;
     }
     if (substr($Endpoint->Path, -1) == '/') {
         $validator->addError('Path', 'Path must not end with /');
         return;
     }
     if (!preg_match(static::$validPathRegex, $Endpoint->Path)) {
         $validator->addError('Path', 'Path must start with a letter and only contain letters, numbers, periods, hyphens, and underscores');
         return;
     }
     $duplicateConditions = ['Path' => $Endpoint->Path];
     if ($Endpoint->ID) {
         $duplicateConditions[] = 'ID != ' . $Endpoint->ID;
     }
     if (Endpoint::getByWhere($duplicateConditions)) {
         $validator->addError('Path', 'Path matches an existing endpoint\'s');
         return;
     }
 }