public function common($file) { $path = WEBAPP_ROOT . "/views/" . (empty($this->channel) ? "" : $this->channel . "/") . "common/{$file}.php"; if (!file_exists($path)) { SwissMVCErrors::generalError("Cannot find view include {$path}", false); } include $path; }
public function sanitize($fld, $value) { if (preg_match("#text\$#", $this->modelStructure[$fld]["type"]) || preg_match("#char\$#", $this->modelStructure[$fld]["type"]) || $this->modelStructure[$fld]["type"] == "enum" || $this->modelStructure[$fld]["type"] == "date" || $this->modelStructure[$fld]["type"] == "timestamp") { $value = "'" . Datasource::escape($value) . "'"; } else { if ($this->modelStructure[$fld]["type"] == "tinyint") { if (!(intval($value) == 0 || intval($value) == 1)) { SwissMVCErrors::generalError("Given value ({$value}) is not a valid boolean value"); } } else { // Assume to be numeric if (!is_numeric($value) && $value != 'NULL') { SwissMVCErrors::generalError("{$value} given as numeric database input (" . $this->modelSource . ".{$fld})"); } } } return $value; }
public static function errorHandler($errno, $errstr, $errfile, $errline, $errcontext) { if (strpos("DOMDocument::loadXML()", $errstr) == 0) { // Parse error list($prefix, $error) = explode("]: ", $errstr); SwissMVCErrors::generalError("Could not compile view " . realpath($errcontext["path"]) . ": " . $error, false); } return false; }
/** * Validate the data before storing it */ private function __validate($data = array()) { /* Empty any existing errors */ $this->errors = array(); if (empty($data)) { foreach ($this->fields as $field) { $data[$field] = $this->{$field}; } } if (is_array($this->validators)) { /** * Iterate through the fields */ foreach ($this->validators as $field => $validators) { if (is_array($validators)) { /** * And each of the validators for the field */ foreach ($validators as $validator => $parameters) { /** * Validators can be defined without parameters, so if $parameters is not an arrary, * then it actually contains the name of our validator */ if (!is_array($parameters)) { $validator = $parameters; $parameters = array(); } /** * Find the validator and execute it */ $validatorClass = Inflector::camelize(sprintf("%s_validator", $validator)); if (!class_exists($validatorClass)) { /** * Try to find the validator implementation file */ $path = sprintf("%s/validators/%s.php", dirname(__FILE__), strtolower($validator)); if (!file_exists($path)) { SwissMVCErrors::generalError("Error in " . get_class($this) . "->validators: Could not find validator class file ({$path}) for validator '{$validator}'", false); } require_once $path; // Now make sure that the class actually was in the file if (!class_exists($validatorClass)) { SwissMVCErrors::generalError("Error in " . get_class($this) . "->validators: Could not find validator implementation '{$validator}'. File was found, but doesn't contain correct implementation " . "(class {$validatorClass} not found).", false); } } $_impl = new $validatorClass(); /* Do the actual validation. If validator returns true, the field is valid */ if (($response = $_impl->validate($data[$field], $parameters)) !== true) { if (!is_array($this->errors[$field])) { $this->errors[$field] = array(); } $this->errors[$field][] = $response; } } } } } if (!empty($this->errors)) { // Pass validation stuff to the controller MVCContext::getContext()->getController()->errors = $this->errors; } return empty($this->errors); }