Exemplo n.º 1
0
 /**
  * Set the error handler sets
  *
  * @return void
  */
 public function __construct()
 {
     $config = Load::factory('Config')->error;
     if (!in_array('Error', Tk::$helper)) {
         Tk::instance()->Load->helper('error');
     }
     if (array_key_exists('reporting', $config)) {
         set_error_handler('error_handler', $config['reporting']);
         error_reporting($config['reporting']);
     }
     set_exception_handler('exception_handler');
 }
Exemplo n.º 2
0
 /**
  * Run the validation based on the $this->rules list
  *
  * @param array $data
  * @param array $rules
  * @return boolean
  */
 public function validate($data, $rules = array())
 {
     if (!is_array($data) || empty($data)) {
         return false;
     }
     if (!empty($rules)) {
         $this->rules = $rules;
     }
     Tk::instance()->Load->helper('validation');
     //keeps the results of the validation
     $result = array();
     //determine if the ruel is a callback if there is an extra parameter
     $param = false;
     foreach ($data as $field => $value) {
         //keep the raw value of the field
         $this->values[$field] = $value;
         if (array_key_exists($field, $this->rules)) {
             $rules = explode('|', $this->rules[$field]);
             if (!in_array('required', $rules) && (empty($value) || is_null($value))) {
                 $this->sanitized_result[$field] = $value;
                 continue;
             }
             foreach ($rules as $rule) {
                 $param = false;
                 if (preg_match("/(.*?)\\[(.*?)\\]/", $rule, $match)) {
                     $rule = $match[1];
                     $param = $match[2];
                 }
                 if (function_exists($rule)) {
                     $r = $rule($value, $param);
                     if ($r == false) {
                         $this->result[$field] = false;
                     } else {
                         $this->sanitized_result[$field] = $r;
                     }
                 }
             }
             if (isset($this->result[$field])) {
                 $this->error_string .= isset($this->messages) && array_key_exists($field, $this->messages) ? "<li>{$this->messages[$field]}</li>" : "<li>{$field} invalid</li>";
                 $this->errors[$field] = array_key_exists($field, $this->messages) ? $this->messages[$field] : "{$field} invalid";
             }
         }
     }
     $this->error_string = !empty($this->error_string) ? "<ul>{$this->error_string}</ul>" : '';
     return !empty($this->result) ? false : true;
 }
Exemplo n.º 3
0
 /**
  * Sets an instance of Tk object
  *
  * @return void
  */
 public function __construct()
 {
     self::$Tk = Tk::instance();
 }
Exemplo n.º 4
0
 /**
  * Method to obtain an instance of the object
  *
  * @return object
  */
 public static function instance()
 {
     if (!isset(Tk::$instance)) {
         self::$instance = new Tk();
     }
     return self::$instance;
 }