Beispiel #1
0
 public function __construct($name, $data = false)
 {
     if ($data instanceof WaxModelField) {
         $this->bound_data = $data;
     } elseif (is_array($data)) {
         $this->defaults["name"] = $name;
         $this->defaults["id"] = $name . "_id";
         $this->defaults["label"] = Inflections::humanize($name);
         $settings = array_merge($this->defaults, $data);
         foreach ($settings as $datum => $value) {
             $this->{$datum} = $value;
         }
     } else {
         $this->name = $name;
         $this->id = $name . "_id";
         $this->editable = true;
         $this->label = Inflections::humanize($name);
     }
     /**
      * the validation details
      */
     $this->validator = new WaxValidate($this, $name);
     if (is_array($data) && isset($data['validate']) && is_array($data['validate'])) {
         foreach ($data['validate'] as $type) {
             $this->validator->validate($type, $data);
         }
     } elseif (is_array($data) && $data['validate']) {
         $this->validator->validate($data['validate'], $data);
     }
 }
Beispiel #2
0
 public function __construct($name, $data = false)
 {
     if ($data instanceof WaxModelField) {
         $this->bound_data = $data;
         if ($this->show_label && !$this->bound_data->label) {
             $this->bound_data->label = Inflections::humanize($this->bound_data->field);
         }
     } else {
         $this->defaults["name"] = $name;
         $this->defaults["id"] = $name;
         if ($this->show_label) {
             $this->defaults["label"] = Inflections::humanize($name);
         }
         $settings = array_merge($this->defaults, (array) $data);
         foreach ($settings as $set => $val) {
             $this->{$set} = $val;
         }
         $this->value = $this->value();
     }
     /**
      * the validation details
      */
     $this->setup_validations();
     $this->validation_classes();
 }
Beispiel #3
0
 public function error_messages_for($object)
 {
     if ($object instanceof WaxForm) {
         if ($object->bound_to_model) {
             if ($object->bound_to_model->errors) {
                 $html = "<ul class='user_errors'>";
             }
             foreach ($object->bound_to_model->errors as $err => $mess) {
                 $html .= "<li>" . $mess[0];
             }
         } else {
             foreach ($object->elements as $el) {
                 foreach ($el->errors as $er) {
                     $html .= sprintf($er->error_template, $er);
                 }
             }
         }
         $html .= "</ul>";
         return $html;
     }
     if (strpos($object, "_")) {
         $object = camelize($object, 1);
     }
     $class = new $object();
     $errors = $class->get_errors();
     foreach ($errors as $error) {
         $html .= $this->content_tag("li", Inflections::humanize($error['field']) . " " . $error['message'], array("class" => "user_error"));
     }
     if (count($errors) > 0) {
         return $this->content_tag("ul", $html, array("class" => "user_errors"));
     }
     return false;
 }
Beispiel #4
0
 public function __construct($message, $heading = "Application Error")
 {
     parent::__construct($message, $code);
     $this->error_heading = $heading;
     $this->error_message = $this->format_trace($this);
     $this->error_site = str_ireplace("www.", '', $_SERVER['HTTP_HOST']);
     $this->error_site = substr($this->error_site, 0, strpos($this->error_site, '.'));
     $this->error_site_name = ucwords(Inflections::humanize($this->error_site));
     if (defined('IN_CLI')) {
         $this->cli_giveup();
     } else {
         $this->handle_error();
     }
 }
Beispiel #5
0
 public function __construct($column, $model, $options = array())
 {
     $this->model = $model;
     foreach ($options as $option => $val) {
         $this->{$option} = $val;
     }
     if (!$this->field) {
         $this->field = $column;
     }
     if (!$this->table) {
         $this->table = $this->model->table;
     }
     if (!$this->col_name) {
         $this->col_name = $this->field;
     }
     if ($this->label === true) {
         $this->label = Inflections::humanize($this->field);
     }
     $this->errors = $this->model->errors[$this->field];
     $this->setup();
     $this->map_choices();
     $this->validator = new $this->validator($this->model, $this->field, $this->label);
 }
Beispiel #6
0
 function __construct($message, $code = "Page cannot be found", $status = "404")
 {
     if ($location = self::$redirect_on_error) {
         $this->error_heading = $code;
         $this->error_message = $this->format_trace($this);
         $this->error_site = str_ireplace("www.", '', $_SERVER['HTTP_HOST']);
         $this->error_site = substr($this->error_site, 0, strpos($this->error_site, '.'));
         $this->error_site_name = ucwords(Inflections::humanize($this->error_site));
         $this->simple_routing_error_log();
         if (!self::$double_redirect) {
             self::$double_redirect = true;
             header("HTTP/1.1 404 Not Found", 1, 404);
             if (is_readable(PUBLIC_DIR . ltrim($location, "/"))) {
                 $content = file_get_contents(PUBLIC_DIR . ltrim($location, "/"));
                 foreach (self::$replacements as $value => $replace) {
                     $content = str_ireplace($replace, $this->{$value}, $content);
                 }
                 ob_end_clean();
                 echo $content;
                 exit;
             }
             $_GET["route"] = $location;
             WaxUrl::$params = false;
             WaxUrl::perform_mappings();
             $delegate = Inflections::slashcamelize(WaxUrl::get("controller"), true) . "Controller";
             $delegate_controller = new $delegate();
             $delegate_controller->execute_request();
             exit;
         } else {
             WaxLog::log("error", "[Routing] Double redirect error");
             $code = "Application Error";
             $message = "A Page not found error was triggered and you have not set up a page to handle it";
         }
     }
     parent::__construct($message, $code);
 }