Example #1
0
 public function __call($name, $arguments)
 {
     if (empty($this->_inspector)) {
         throw new Exception("Call parent::__construct!");
     }
     $getMatches = StringMethods::match($name, "^get([a-zA-Z0-9]+)\$");
     if (sizeof($getMatches) > 0) {
         $normalized = lcfirst($getMatches[0]);
         $property = "_{$normalized}";
         if (property_exists($this, $property)) {
             $meta = $this->_inspector->getPropertyMeta($property);
             if (empty($meta["@readwrite"]) && empty($meta["@read"])) {
                 throw $this->_getExceptionForWriteonly($normalized);
             }
             if (isset($this->{$property})) {
                 return $this->{$property};
             }
             return null;
         }
     }
     $setMatches = StringMethods::match($name, "^set([a-zA-Z0-9]+)\$");
     if (sizeof($setMatches) > 0) {
         $normalized = lcfirst($setMatches[0]);
         $property = "_{$normalized}";
         if (property_exists($this, $property)) {
             $meta = $this->_inspector->getPropertyMeta($property);
             if (empty($meta["@readwrite"]) && empty($meta["@write"])) {
                 throw $this->_getExceptionForReadonly($normalized);
             }
             if (!empty($meta["@notnull"]) && $arguments[0] === NULL) {
                 throw $this->_getExceptionForNull($normalized);
             }
             $this->{$property} = $arguments[0];
             return $this;
         }
     }
     throw $this->_getExceptionForImplementation($name);
 }
Example #2
0
 public function validate()
 {
     $this->_errors = array();
     foreach ($this->columns as $column) {
         if ($column["validate"]) {
             $pattern = "#[a-z]+\\(([a-zA-Z0-9, ]+)\\)#";
             $raw = $column["raw"];
             $name = $column["name"];
             $validators = $column["validate"];
             $label = $column["label"];
             $defined = $this->getValidators();
             foreach ($validators as $validator) {
                 $function = $validator;
                 $arguments = array($this->{$raw});
                 $match = StringMethods::match($validator, $pattern);
                 if (count($match) > 0) {
                     $matches = StringMethods::split($match[0], ",\\s*");
                     $arguments = array_merge($arguments, $matches);
                     $offset = StringMethods::indexOf($validator, "(");
                     $function = substr($validator, 0, $offset);
                 }
                 if (!isset($defined[$function])) {
                     throw new Exception\Validation("The {$function} validator is not defined");
                 }
                 $template = $defined[$function];
                 if (!call_user_func_array(array($this, $template["handler"]), $arguments)) {
                     $replacements = array_merge(array($label ? $label : $raw), $arguments);
                     $message = $template["message"];
                     foreach ($replacements as $i => $replacement) {
                         $message = str_replace("{{$i}}", $replacement, $message);
                     }
                     if (!isset($this->_errors[$name])) {
                         $this->_errors[$name] = array();
                     }
                     $this->_errors[$name][] = $message;
                 }
             }
         }
     }
     return !sizeof($this->errors);
 }