Exemple #1
0
 protected function _alterMailtoEmailAddressMetadata($meta)
 {
     if ($this->subtype != 'mailto') {
         return $meta;
     }
     $validator = new Validator();
     $validator->set()->break()->emailAddress();
     $validator->steps($meta['validator']->steps());
     $meta['nullable'] = false;
     $meta['validator'] = $validator;
     return $meta;
 }
Exemple #2
0
 protected static function _parseMetadata($md)
 {
     $md = array_merge(array('fields' => array(), 'associations' => array(), 'properties' => array()), $md);
     foreach ($md['fields'] as $name => $field) {
         $field = \Coast\array_merge_smart(array('id' => false, 'type' => null, 'length' => null, 'nullable' => false, 'validator' => new Validator()), $field);
         $validator = new Validator();
         if (!$field['id'] && !$field['nullable']) {
             $validator->set()->break();
         }
         if ($field['type'] == 'integer' || $field['type'] == 'smallint' || $field['type'] == 'bigint') {
             $validator->integer();
         } else {
             if ($field['type'] == 'float' || $field['type'] == 'decimal') {
                 $validator->float();
             } else {
                 if ($field['type'] == 'boolean') {
                     $validator->boolean();
                 } else {
                     if ($field['type'] == 'array' || $field['type'] == 'simple_array' || $field['type'] == 'json_array') {
                         $validator->array();
                     } else {
                         if ($field['type'] == 'string' || $field['type'] == 'text' || $field['type'] == 'guid') {
                             $validator->string();
                         } else {
                             if ($field['type'] == 'date') {
                                 $validator->dateTime('Y-m-d');
                             } else {
                                 if ($field['type'] == 'time') {
                                     $validator->dateTime('H:i:s');
                                 } else {
                                     if ($field['type'] == 'datetime' || $field['type'] == 'datetimez') {
                                         $validator->dateTime('Y-m-d H:i:s');
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         if (isset($field['length'])) {
             $validator->length(null, $field['length']);
         }
         $validator->steps($field['validator']->steps());
         $field['validator'] = $validator;
         $md['fields'][$name] = $field;
         $md['properties'][$name] = $md['fields'][$name];
     }
     foreach ($md['associations'] as $name => $assoc) {
         $assoc = \Coast\array_merge_smart(array('type' => null, 'entity' => null, 'nullable' => false, 'validator' => new Validator()), $assoc);
         $validator = new Validator();
         if (!$assoc['nullable'] && $assoc['type'] == 'manyToOne') {
             $validator->set()->break();
         }
         $validator->steps($assoc['validator']->steps());
         $assoc['validator'] = $validator;
         $md['associations'][$name] = $assoc;
         $md['properties'][$name] = $md['associations'][$name];
     }
     return $md;
 }