Exemple #1
0
	function log($priority, $message, $file = null, $line = null, $e = null) {
		$schema = "DEFAULT";
		$table = "logs";
		$trace = "";
		if (!empty($e)) {
			$trace = $e->getTraceAsString();
		}
		if (is_object($message)) {
			$message = JSON::encode($message);
		}
		$now = new Date();
		$log = array();
		$log["priority"] = $priority;
		$log["message"] = $message;
		$log["trace"] = $trace;
		$log["file"] = $file;
		$log["line"] = $line;
		$log["createdBy"] = "SYS";
		$log["createdTime"] = $now;
		$log["updatedBy"] = "SYS";
		$log["updatedTime"] = $now;

		$driver = $GLOBALS["CFG_DB"]->CON[$schema]->DRIVER;
		$insert = new Insert($table, $log, $schema);
		$link = DB::connect();
		$success = mysql_query($insert->sql(), $link);
		if (!$success) {
			$result = Bean::invoke(String::camelize('_'.$driver.'_driver'), "error", array($schema));
			throw new Exception("Cannot persist object. ".$result);
		}
	}
Exemple #2
0
	function validate(&$action) {
		Apu::dispatch($action->validation);
		if (!empty($GLOBALS["VALIDATION"])) {
			reset($GLOBALS["VALIDATION"]);
			while (list($method, $methodValidations) = each($GLOBALS["VALIDATION"])) {
				if ($method == "-" || $method == $action->method) {
					reset($methodValidations);
					while (list($field, $fieldValidations) = each($methodValidations)) {
						$fieldValue = $action->get($field);
						while (list($i, $val) = each($fieldValidations)) {
							$function = $val["validate"];
							$not = false;
							if (substr($val["validate"], 0, 1) == "!") {
								$function = trim($function, "!");
								$not = true;
							}
							$validate = Bean::invoke("Validation", $function, array(&$action, $val, $field, $not));
							if ($not) {
								$validate = !$validate;
							}
							if (!$validate) {
								$defaultMessage = $GLOBALS["CFG_VALIDATION"]->MSG[$val["validate"]];
								$action->addMsgMessage($defaultMessage, $field);
							}
						}
					}
				}
			}
		}
	}
Exemple #3
0
	function doInvoke() {
		try {
		$result = Bean::invoke($this->md, $this->mt, $this->ps);
		$this->json = $result;
		} catch (Exception $e) {
			$error = new stdClass();
			$error->error = $e->getMessage();
			$this->json = $error;
		}
	}
Exemple #4
0
	function delete($table, $obj, $schema = "DEFAULT") {
		$driver = $GLOBALS["CFG_DB"]->CON[$schema]->DRIVER;
		$objId = Bean::get($obj, "__ID__");
		if (empty($objId)) {
			throw new Exception("Cannot delete unpersisted object");
		}
		$delete = new Delete($table, $obj, $schema);
		$success = DB::query($delete, $schema);
		if (!$success) {
			$result = Bean::invoke(String::camelize('_'.$driver.'_driver'), "error", array($schema));
			throw new Exception("Cannot delete object. ".$result);
		}
	}
Exemple #5
0
	function escape($value, $name) {
		$schema = $this->schema;
		$driver = $GLOBALS["CFG_DB"]->CON[$schema]->DRIVER;
		$value = Bean::invoke(String::camelize('_'.$driver.'_driver'), "escape", array($value, $name, $this->meta));
		return $value;
	}
Exemple #6
0
	function listen() {
		$this->pre();
		$methodName = String::camelize("do_".$this->method);
		Bean::invoke($this, $methodName);
		$this->post();
	}