Permalink
Browse files

Merge branch 'master' of ssh://leftnode.com/var/git/jolt

  • Loading branch information...
Vic Cherubini
Vic Cherubini committed Feb 24, 2011
2 parents 3f279e2 + 9f78e6e commit a198aac2b9d1cc4339491175f2be2750b35d0677
View
@@ -44,10 +44,10 @@ public function build_output() {
// Always remove the Content-Type header, let Jolt handle it
header_remove('Content-Type');
- header('Content-Type: ' . $content_type, true, $response_code);
+ header('Content-Type: '.$content_type, true, $response_code);
if (defined('JOLT_VERSION')) {
- header('X-Framework: Jolt ' . JOLT_VERSION);
+ header('X-Framework: Jolt '.JOLT_VERSION);
}
foreach ($headers as $complete_header) {
@@ -58,7 +58,7 @@ public function build_output() {
}
$controller_header = strtolower($controller_header);
- header($controller_header . ':' . $controller_header_value, true, $response_code);
+ header($controller_header.':'.$controller_header_value, true, $response_code);
// Special case for the Location header to prevent __toString() from not outputting anything.
if ('location' === $controller_header) {
View
@@ -129,6 +129,10 @@ public function render_view($view_name) {
return $rendered_view;
}
+ public function url($path, $secure=false) {
+ return $this->get_view()->url($path, $secure);
+ }
+
public function set_action($action) {
$this->action = trim($action);
return $this;
@@ -189,6 +193,17 @@ public function get_response_code() {
return $this->response_code;
}
+ public function get_post_params($key=NULL) {
+ if (!empty($key)) {
+ if (array_key_exists($key, $_POST)) {
+ return $_POST[$key];
+ } else {
+ return NULL;
+ }
+ }
+ return $_POST;
+ }
+
public function get_view() {
return $this->view;
}
View
@@ -36,7 +36,7 @@ public function attach_route(\jolt\route $route) {
return $this;
}
- public function attach_settings(\jolt\settings $settings) {
+ public function attach_settings(\jolt\vo $settings) {
$this->settings = clone $settings;
return $this;
}
@@ -116,4 +116,5 @@ private function check_view() {
}
return $this->view;
}
+
}
View
@@ -26,7 +26,7 @@ public function __construct($message=NULL) {
$msg .= $trace['function'] . '()';
}
- $msg .= " [{$message}] ({$filename} +{$line_number})";
+ $msg .= ' ['.$message.'] ('.$filename.' +'.$line_number.')';
parent::__construct($msg);
}
View
@@ -54,8 +54,8 @@ public function load() {
return false;
}
- $this->setData($this->loader->get_data())
- ->setErrors($this->loader->get_errors());
+ $this->set_data($this->loader->get_data())
+ ->set_errors($this->loader->get_errors());
return true;
}
@@ -65,10 +65,10 @@ public function write() {
return false;
}
- $this->writer->setId($this->get_id())
- ->setName($this->get_name())
- ->setData($this->get_data())
- ->setErrors($this->get_errors());
+ $this->writer->set_id($this->get_id())
+ ->set_name($this->get_name())
+ ->set_data($this->get_data())
+ ->set_errors($this->get_errors());
$written = $this->writer->write();
return $written;
@@ -106,9 +106,9 @@ public function validate() {
$exception = $this->exception;
if (!is_null($exception)) {
- throw new $exception($error);
+ throw new $exception($error, $this);
} else {
- throw new \jolt\exception($error);
+ throw new jolt_exception($error);
}
}
View
@@ -2,12 +2,11 @@
declare(encoding='UTF-8');
namespace jolt\form;
-use \jolt\form_controller;
require_once('jolt/form_controller.php');
-abstract class loader extends form_controller {
+abstract class loader extends \jolt\form_controller {
abstract public function load();
-}
+}
View
@@ -2,16 +2,15 @@
declare(encoding='UTF-8');
namespace jolt\form\loader;
-use \jolt\form\loader;
require_once('jolt/form/loader.php');
-class db extends loader {
+class db extends \jolt\form\loader {
private $pdo = NULL;
private $table = 'form';
- public function attach_pdo(\PDO $pdo) {
+ public function attach_pdo(\jolt\pdo $pdo) {
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_SILENT);
$pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
$this->pdo = $pdo;
@@ -35,50 +34,34 @@ public function load() {
}
$table = $this->get_table();
- $stmt = $pdo->prepare("SELECT form_id, data, errors FROM {$table} WHERE id = :id AND name = :name AND status = 1");
+ $form_data = $pdo->select_one('SELECT form_id, data, errors FROM '.$table.' WHERE id = :id AND name = :name AND status = :status',
+ array(':id' => $id, ':name' => $name, ':status' => 1));
- if (!$stmt) {
+ $form_data = $stmt->fetchObject();
+ if (!$form_data) {
return false;
}
- $parameters = array(
- 'id' => $id,
- 'name' => $name
- );
+ $form_id = $form_data->form_id;
- $executed = $stmt->execute($parameters);
+ $pdo->modify('UPDATE '.$table.' SET status = :status WHERE form_id = :form_id',
+ array(':status' => 0, ':form_id' => $form_id));
- if ($executed) {
- $form_data = $stmt->fetchObject();
- if (!$form_data) {
- return false;
- }
+ $data = json_decode($form_data->data, true);
+ $errors = json_decode($form_data->errors, true);
- $form_id = $form_data->form_id;
-
- $sql = "UPDATE {$table} SET status = 0 WHERE form_id = :form_id";
- $stmt = $pdo->prepare($sql);
-
- if (false !== $stmt) {
- $executed = $stmt->execute(array('form_id' => $form_id));
-
- $data = json_decode($form_data->data, true);
- $errors = json_decode($form_data->errors, true);
-
- if (is_null($data)) {
- $data = array($form_data->data);
- }
-
- if (is_null($errors)) {
- $errors = array($form_data->errors);
- }
+ if (is_null($data)) {
+ $data = array($form_data->data);
+ }
- $this->set_data($data)
- ->set_errors($errors);
- }
+ if (is_null($errors)) {
+ $errors = array($form_data->errors);
}
- return $executed;
+ $this->set_data($data)
+ ->set_errors($errors);
+
+ return true;
}
public function set_table($table) {
@@ -0,0 +1,77 @@
+<?php
+
+declare(encoding='UTF-8');
+namespace jolt\form\loader;
+
+require_once('jolt/form/loader.php');
+
+class session extends \jolt\form\loader {
+
+ private $session;
+ private $key = 'jolt_form';
+
+ public function attach_session(\jolt\session $session) {
+ $this->session = $session;
+ return $this;
+ }
+
+ public function load() {
+ $session = $this->get_session();
+ if (is_null($session)) {
+ return false;
+ }
+
+ $id = $this->get_id();
+ if (empty($id)) {
+ return false;
+ }
+
+ $name = $this->get_name();
+ if (empty($name)) {
+ return false;
+ }
+
+ $key = $this->get_key();
+ if (isset($session->$key)) {
+ $jolt_forms = $session->$key;
+ if (array_key_exists($name, $jolt_forms)) {
+ $form_data = $jolt_forms[$name];
+
+ $data = json_decode($form_data['data'], true);
+ $errors = json_decode($form_data['errors'], true);
+
+ if (is_null($data)) {
+ $data = array($form_data['data']);
+ }
+
+ if (is_null($errors)) {
+ $errors = array($form_data['errors']);
+ }
+
+ $this->set_data($data)
+ ->set_errors($errors);
+
+ unset($jolt_forms[$name]);
+ $session->$key = $jolt_forms;
+
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public function set_key($key) {
+ $this->key = trim($key);
+ return $this;
+ }
+
+ public function get_key() {
+ return $this->key;
+ }
+
+ public function get_session() {
+ return $this->session;
+ }
+
+}
View
@@ -54,7 +54,7 @@ public function error($error) {
public function rule($rule, $field) {
$this->rule = $rule;
if ($this->rule_set_exists()) {
- $validator_rule = new \jolt\form\validator\rule;
+ $validator_rule = new jolt\form\validator\rule;
$validator_rule->set_field($field);
$this->rule_sets[$this->rule_set][$rule] = $validator_rule;
@@ -68,8 +68,10 @@ public function not_empty($error) {
}
public function min_max($min, $max, $min_error, $max_error) {
- $this->add_rule('minlength', $min, $minError)
- ->add_rule('maxlength', $max, $max_error);
+ $this->add_rule('minlength', $min)
+ ->add_rule('maxlength', $max);
+ $this->add_error('minlength', $min_error)
+ ->add_error('maxlength', $max_error);
return $this;
}
@@ -89,7 +91,7 @@ public function get_error() {
public function is_empty() {
if ($this->rule_set_exists()) {
- return ( 0 === count($this->rule_sets[$this->rule_set]) );
+ return (0 === count($this->rule_sets[$this->rule_set]));
}
return true;
}
@@ -119,9 +121,9 @@ private function add_rule($key, $rule) {
private function add_error($key, $error) {
if ($this->rule_exists()) {
- $this->rule_sets[$this->rule_set][$this->rule]->add_rule($key, $error);
+ $this->rule_sets[$this->rule_set][$this->rule]->add_error($key, $error);
}
return $this;
}
-}
+}
@@ -40,13 +40,17 @@ public function is_empty() {
}
public function is_valid($value) {
- $isValid = true;
+ $is_valid = true;
foreach ($this->rules as $op => $rule) {
$op_method = 'op_' . strtolower($op);
if (method_exists($this, $op_method) && !$this->$op_method($rule, $value) ) {
$is_valid = false;
if (array_key_exists($op, $this->errors)) {
- $this->error = sprintf($this->errors[$op], $this->field);
+ if ('minlength' === $op || 'maxlength' === $op) {
+ $this->error = sprintf($this->errors[$op], $this->field, $rule);
+ } else {
+ $this->error = sprintf($this->errors[$op], $this->field);
+ }
}
break;
}
@@ -132,7 +136,7 @@ private function op_email($email, $value) {
}
// Length of each side must be greater than 0
- return (mb_strlen($bits[0], $this->charset) > 0 && mb_strlen($bits[1], $this->charset));
+ return (mb_strlen($bits[0], $this->charset) > 0 && mb_strlen($bits[1], $this->charset) > 0);
}
private function op_inarray($inarray, $value) {
@@ -149,6 +153,13 @@ private function op_regex($regex, $value) {
return true;
}
+ private function op_url($is_url, $url) {
+ if (false === filter_var($url, FILTER_VALIDATE_URL)) {
+ return false;
+ }
+ return true;
+ }
+
private function op_callback($callback, $value) {
if (!$callback($value)) {
return false;
View
@@ -2,11 +2,10 @@
declare(encoding='UTF-8');
namespace jolt\form;
-use \jolt\form_controller;
require_once('jolt/form_controller.php');
-abstract class writer extends form_controller {
+abstract class writer extends \jolt\form_controller {
abstract public function write();
Oops, something went wrong.

0 comments on commit a198aac

Please sign in to comment.