예제 #1
0
파일: Model.php 프로젝트: ToddBudde/phrails
 /**
  * Validate the model
  *
  * @return boolean
  * @author Justin Palmer
  **/
 public function validate()
 {
     //print '<pre>';
     $boolean = true;
     $errors = array();
     $last_prop_name = '';
     //Run validation before calling save.
     $props = $this->props->export();
     $rules = $this->schema->rules();
     //var_dump($props);
     //Loop through the set properties.
     foreach ($props as $name => $value) {
         if (empty($errors)) {
             $last_prop_name = $name;
         }
         if (!empty($errors) && $last_prop_name != $name) {
             $this->errors->set($this->alias() . '[' . $last_prop_name . ']', $errors);
             $last_prop_name = $name;
             $errors = array();
         }
         //if the value is null and it is not a required property then lets just
         //continue onto the next property, nothing to do here.
         if ($value == NULL && !in_array($name, $this->schema()->required)) {
             continue;
         }
         //If there are rules for the property let's go through them.
         if ($rules->isKey($name)) {
             //print $name . ':' . $value . '<br/><br/>';
             //Get the rules.
             $prop_rules = $rules->get($name);
             //var_dump($prop_rules);
             foreach ($prop_rules as $key => $rule) {
                 $rule->value = $value;
                 if (!$rule->run()) {
                     if ($boolean) {
                         $boolean = false;
                     }
                     //Add the error message to some sort of array. So that we can add it to a flash.
                     $errors[] = $rule->message;
                 }
             }
         }
     }
     if (!empty($errors)) {
         $this->errors->set($this->alias() . '[' . $name . ']', $errors);
     }
     if (!$this->errors()->isEmpty()) {
         $boolean = false;
     }
     return $boolean;
 }
예제 #2
0
파일: SchemaTest.php 프로젝트: cebe/chive
 /**
  * Tests some config functions.
  */
 public function testConfigFunctions()
 {
     // Create new schema
     $schema = new Schema();
     // Check return types
     $this->assertEquals(true, is_array($schema->attributeLabels()));
     $this->assertEquals(true, is_array($schema->rules()));
     $this->assertEquals(true, is_array($schema->relations()));
 }